Programming in Scala: A Comprehensive Step-by-step Guide

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Programming in Scala is the definitive book on Scala, the new language for the Java Platform that blends object-oriented and functional programming concepts into a unique and powerful tool for developers. Coauthored by the designer of the Scala language, this authoritative book will teach you, one step at a time, the Scala language and the ideas behind it. The book is carefully crafted to help you learn. The first few chapters will give you enough of the basics that you can already start using Scala for simple tasks. The entire book is organized so that each new concept builds on concepts that came before - a series of steps that promises to help you master the Scala language and the important ideas about programming that Scala embodies. A comprehensive tutorial and reference for Scala, this book covers the entire language and important libraries.

Author(s): Martin Odersky, Lex Spoon, Bill Venners
Edition: 1St Edition
Publisher: Artima Inc
Year: 2008

Language: English
Commentary: 69971
Pages: 754
Tags: Библиотека;Компьютерная литература;Scala;

Contents......Page 7
List of Figures......Page 17
List of Tables......Page 19
List of Listings......Page 20
Foreword......Page 27
Acknowledgments......Page 29
Introduction......Page 31
A Scalable Language......Page 39
A language that grows on you......Page 40
What makes Scala scalable?......Page 45
Why Scala?......Page 48
Scala's roots......Page 55
Conclusion......Page 57
Learn to use the Scala interpreter......Page 58
Define some variables......Page 60
Define some functions......Page 62
Write some Scala scripts......Page 64
Loop with while; decide with if......Page 65
Iterate with foreach and for......Page 67
Conclusion......Page 70
Parameterize arrays with types......Page 71
Use lists......Page 75
Use tuples......Page 80
Use sets and maps......Page 81
Learn to recognize the functional style......Page 86
Read lines from a file......Page 89
Conclusion......Page 92
Classes, fields, and methods......Page 93
Semicolon inference......Page 98
Singleton objects......Page 99
A Scala application......Page 102
The Application trait......Page 105
Conclusion......Page 106
Some basic types......Page 107
Literals......Page 108
Operators are methods......Page 115
Arithmetic operations......Page 118
Relational and logical operations......Page 119
Bitwise operations......Page 121
Object equality......Page 123
Operator precedence and associativity......Page 124
Conclusion......Page 127
A specification for class Rational......Page 129
Constructing a Rational......Page 130
Reimplementing the toString method......Page 132
Adding fields......Page 133
Self references......Page 135
Auxiliary constructors......Page 136
Private fields and methods......Page 138
Defining operators......Page 139
Identifiers in Scala......Page 141
Method overloading......Page 144
Implicit conversions......Page 146
Conclusion......Page 147
Built-in Control Structures......Page 149
If expressions......Page 150
While loops......Page 151
For expressions......Page 154
Exception handling with try expressions......Page 159
Match expressions......Page 163
Living without break and continue......Page 165
Variable scope......Page 167
Refactoring imperative-style code......Page 170
Conclusion......Page 172
Methods......Page 173
Local functions......Page 175
First-class functions......Page 177
Short forms of function literals......Page 179
Placeholder syntax......Page 180
Partially applied functions......Page 181
Closures......Page 184
Repeated parameters......Page 188
Tail recursion......Page 189
Conclusion......Page 193
Reducing code duplication......Page 194
Simplifying client code......Page 198
Currying......Page 200
Writing new control structures......Page 202
By-name parameters......Page 205
Conclusion......Page 208
A two-dimensional layout library......Page 209
Abstract classes......Page 210
Defining parameterless methods......Page 211
Extending classes......Page 214
Overriding methods and fields......Page 216
Defining parametric fields......Page 217
Invoking superclass constructors......Page 219
Using override modifiers......Page 220
Polymorphism and dynamic binding......Page 222
Declaring final members......Page 224
Using composition and inheritance......Page 226
Implementing above, beside, and toString......Page 227
Defining a factory object......Page 229
Heighten and widen......Page 231
Putting it all together......Page 235
Conclusion......Page 236
Scala's class hierarchy......Page 237
How primitives are implemented......Page 241
Bottom types......Page 243
Conclusion......Page 244
How traits work......Page 245
Thin versus rich interfaces......Page 248
Example: Rectangular objects......Page 249
The Ordered trait......Page 252
Traits as stackable modifications......Page 254
Why not multiple inheritance?......Page 258
To trait, or not to trait?......Page 262
Conclusion......Page 263
Packages......Page 264
Imports......Page 268
Implicit imports......Page 272
Access modifiers......Page 273
Conclusion......Page 278
Assertions......Page 279
Unit testing in Scala......Page 281
Informative failure reports......Page 282
Using JUnit and TestNG......Page 284
Tests as specifications......Page 286
Property-based testing......Page 288
Organizing and running tests......Page 290
Conclusion......Page 292
A simple example......Page 293
Kinds of patterns......Page 298
Pattern guards......Page 307
Pattern overlaps......Page 309
Sealed classes......Page 310
The Option type......Page 312
Patterns everywhere......Page 314
A larger example......Page 318
Conclusion......Page 326
List literals......Page 327
Constructing lists......Page 328
Basic operations on lists......Page 329
List patterns......Page 330
First-order methods on class List......Page 332
Higher-order methods on class List......Page 343
Methods of the List object......Page 351
Understanding Scala's type inference algorithm......Page 355
Conclusion......Page 358
Overview of the library......Page 359
Sequences......Page 361
Sets and maps......Page 367
Selecting mutable versus immutable collections......Page 377
Initializing collections......Page 380
Tuples......Page 383
Conclusion......Page 386
What makes an object stateful?......Page 387
Reassignable variables and properties......Page 390
Case study: Discrete event simulation......Page 393
A language for digital circuits......Page 394
The Simulation API......Page 397
Circuit Simulation......Page 401
Conclusion......Page 409
Functional queues......Page 410
Information hiding......Page 414
Variance annotations......Page 417
Checking variance annotations......Page 421
Lower bounds......Page 424
Contravariance......Page 426
Object private data......Page 429
Upper bounds......Page 431
Conclusion......Page 434
A quick tour of abstract members......Page 435
Type members......Page 436
Abstract vals......Page 437
Abstract vars......Page 438
Initializing abstract vals......Page 439
Abstract types......Page 447
Path-dependent types......Page 449
Enumerations......Page 452
Case study: Currencies......Page 454
Conclusion......Page 463
Implicit conversions......Page 465
Rules for implicits......Page 468
Implicit conversion to an expected type......Page 471
Converting the receiver......Page 473
Implicit parameters......Page 475
View bounds......Page 481
Debugging implicits......Page 485
Conclusion......Page 486
The List class in principle......Page 487
The ListBuffer class......Page 493
The List class in practice......Page 495
Functional on the outside......Page 497
Conclusion......Page 498
For Expressions Revisited......Page 500
For expressions......Page 501
The n-queens problem......Page 503
Querying with for expressions......Page 506
Translation of for expressions......Page 508
Going the other way......Page 512
Generalizing for......Page 513
Conclusion......Page 515
An example: Extracting email addresses......Page 516
Extractors......Page 517
Patterns with zero or one variables......Page 520
Variable argument extractors......Page 522
Extractors and sequence patterns......Page 525
Extractors versus case classes......Page 526
Regular expressions......Page 527
Conclusion......Page 531
Why have annotations?......Page 532
Syntax of annotations......Page 533
Standard annotations......Page 535
Conclusion......Page 537
Semi-structured data......Page 539
XML overview......Page 540
XML literals......Page 541
Serialization......Page 543
Taking XML apart......Page 545
Deserialization......Page 546
Loading and saving......Page 547
Pattern matching on XML......Page 549
Conclusion......Page 552
Modular Programming Using Objects......Page 553
The problem......Page 554
A recipe application......Page 555
Abstraction......Page 558
Splitting modules into traits......Page 561
Runtime linking......Page 564
Tracking module instances......Page 565
Conclusion......Page 567
Equality in Scala......Page 568
Writing an equality method......Page 569
Defining equality for parameterized types......Page 582
Recipes for equals and hashCode......Page 587
Conclusion......Page 593
Using Scala from Java......Page 594
Annotations......Page 597
Existential types......Page 602
Conclusion......Page 606
Trouble in paradise......Page 607
Actors and message passing......Page 608
Treating native threads as actors......Page 612
Better performance through thread reuse......Page 613
Good actors style......Page 616
A longer example: Parallel discrete event simulation......Page 623
Conclusion......Page 640
Combinator Parsing......Page 642
Example: Arithmetic expressions......Page 643
Running your parser......Page 645
Basic regular expression parsers......Page 646
Another example: JSON......Page 647
Parser output......Page 649
Implementing combinator parsers......Page 655
String literals and regular expressions......Page 664
Error reporting......Page 665
Backtracking versus LL(1)......Page 667
Conclusion......Page 669
A first Swing application......Page 671
Panels and layouts......Page 674
Handling events......Page 676
Example: Celsius/Fahrenheit converter......Page 679
Conclusion......Page 681
The visual framework......Page 683
Disconnecting data entry and display......Page 686
Formulas......Page 689
Parsing formulas......Page 691
Evaluation......Page 696
Operation libraries......Page 699
Change propagation......Page 702
Conclusion......Page 706
Scala scripts on Unix and Windows......Page 708
Glossary......Page 709
Bibliography......Page 725
About the Authors......Page 728
Index......Page 729