Home Page Icon
Home Page
Table of Contents for
Cover
Close
Cover
by Alex Payne, Dean Wampler
Programming Scala
Dedication
A Note Regarding Supplemental Files
Foreword
Preface
Welcome to Programming Scala
Conventions Used in This Book
Using Code Examples
Getting the Code Examples
Safari® Books Online
How to Contact Us
Acknowledgments
1. Zero to Sixty: Introducing Scala
Why Scala?
If You Are a Java Programmer…
If You Are a Ruby, Python, etc. Programmer…
Introducing Scala
The Seductions of Scala
Installing Scala
For More Information
A Taste of Scala
A Taste of Concurrency
Recap and What’s Next
2. Type Less, Do More
In This Chapter
Semicolons
Variable Declarations
Method Declarations
Method Default and Named Arguments (Scala Version 2.8)
Nesting Method Definitions
Inferring Type Information
Literals
Integer Literals
Floating-Point Literals
Boolean Literals
Character Literals
String Literals
Symbol Literals
Tuples
Option, Some, and None: Avoiding nulls
Organizing Code in Files and Namespaces
Importing Types and Their Members
Imports are Relative
Abstract Types And Parameterized Types
Reserved Words
Recap and What’s Next
3. Rounding Out the Essentials
Operator? Operator?
Syntactic Sugar
Methods Without Parentheses and Dots
Precedence Rules
Domain-Specific Languages
Scala if Statements
Scala for Comprehensions
A Dog-Simple Example
Filtering
Yielding
Expanded Scope
Other Looping Constructs
Scala while Loops
Scala do-while Loops
Generator Expressions
Conditional Operators
Pattern Matching
A Simple Match
Variables in Matches
Matching on Type
Matching on Sequences
Matching on Tuples (and Guards)
Matching on Case Classes
Matching on Regular Expressions
Binding Nested Variables in Case Clauses
Using try, catch, and finally Clauses
Concluding Remarks on Pattern Matching
Enumerations
Recap and What’s Next
4. Traits
Introducing Traits
Traits As Mixins
Stackable Traits
Constructing Traits
Class or Trait?
Recap and What’s Next
5. Basic Object-Oriented Programming in Scala
Class and Object Basics
Parent Classes
Constructors in Scala
Calling Parent Class Constructors
Nested Classes
Visibility Rules
Public Visibility
Protected Visibility
Private Visibility
Scoped Private and Protected Visibility
Final Thoughts on Visibility
Recap and What’s Next
6. Advanced Object-Oriented Programming In Scala
Overriding Members of Classes and Traits
Attempting to Override final Declarations
Overriding Abstract and Concrete Methods
Overriding Abstract and Concrete Fields
Overriding Abstract and Concrete Fields in Traits
Overriding Abstract and Concrete Fields in Classes
Overriding Abstract Types
When Accessor Methods and Fields Are Indistinguishable: The Uniform Access Principle
Companion Objects
Apply
Unapply
Apply and UnapplySeq for Collections
Companion Objects and Java Static Methods
Case Classes
Syntactic Sugar for Binary Operations
The copy Method in Scala Version 2.8
Case Class Inheritance
Equality of Objects
The equals Method
The == and != Methods
The ne and eq Methods
Array Equality and the sameElements Method
Recap and What’s Next
7. The Scala Object System
The Predef Object
Classes and Objects: Where Are the Statics?
Package Objects
Sealed Class Hierarchies
The Scala Type Hierarchy
Linearization of an Object’s Hierarchy
Recap and What’s Next
8. Functional Programming in Scala
What Is Functional Programming?
Functions in Mathematics
Variables that Aren’t
Functional Programming in Scala
Function Literals and Closures
Purity Inside Versus Outside
Recursion
Tail Calls and Tail-Call Optimization
Trampoline for Tail Calls
Functional Data Structures
Lists in Functional Programming
Maps in Functional Programming
Sets in Functional Programming
Other Data Structures in Functional Programming
Traversing, Mapping, Filtering, Folding, and Reducing
Traversal
Mapping
Filtering
Folding and Reducing
Functional Options
Pattern Matching
Partial Functions
Currying
Implicits
Implicit Conversions
Implicit Function Parameters
Final Thoughts on Implicits
Call by Name, Call by Value
Lazy Vals
Recap: Functional Component Abstractions
9. Robust, Scalable Concurrency with Actors
The Problems of Shared, Synchronized State
Actors
Actors in Abstract
Actors in Scala
Sending Messages to Actors
The Mailbox
Actors in Depth
Effective Actors
Traditional Concurrency in Scala: Threading and Events
One-Off Threads
Using java.util.concurrent
Events
Recap and What’s Next
10. Herding XML in Scala
Reading XML
Exploring XML
Looping and Matching XML
Writing XML
A Real-World Example
Recap and What’s Next
11. Domain-Specific Languages in Scala
Internal DSLs
A Payroll Internal DSL
Infix Operator Notation
Implicit Conversions and User-Defined Types
Apply Methods
Payroll Rules DSL Implementation
Internal DSLs: Final Thoughts
External DSLs with Parser Combinators
About Parser Combinators
A Payroll External DSL
A Scala Implementation of the External DSL Grammar
Generating Paychecks with the External DSL
Internal Versus External DSLs: Final Thoughts
Recap and What’s Next
12. The Scala Type System
Reflecting on Types
Understanding Parameterized Types
Manifests
Parameterized Methods
Variance Under Inheritance
Variance of Mutable Types
Variance In Scala Versus Java
Implementation Notes
Type Bounds
Upper Type Bounds
Lower Type Bounds
A Closer Look at Lists
Views and View Bounds
Nothing and Null
Understanding Abstract Types
Parameterized Types Versus Abstract Types
Path-Dependent Types
C.this
C.super
path.x
Value Types
Type Designators
Tuples
Parameterized Types
Annotated Types
Compound Types
Infix Types
Function Types
Type Projections
Singleton Types
Self-Type Annotations
Structural Types
Existential Types
Infinite Data Structures and Laziness
Recap and What’s Next
13. Application Design
Annotations
Enumerations Versus Pattern Matching
Thoughts On Annotations and Enumerations
Enumerations Versus Case Classes and Pattern Matching
Using Nulls Versus Options
Options and for Comprehensions
Exceptions and the Alternatives
Scalable Abstractions
Fine-Grained Visibility Rules
Mixin Composition
Self-Type Annotations and Abstract Type Members
Effective Design of Traits
Design Patterns
The Visitor Pattern: A Better Alternative
Dependency Injection in Scala: The Cake Pattern
Better Design with Design By Contract
Recap and What’s Next
14. Scala Tools, Libraries, and IDE Support
Command-Line Tools
scalac Command-Line Tool
The scala Command-Line Tool
Limitations of scala versus scalac
The scalap, javap, and jad Command-Line Tools
The scaladoc Command-Line Tool
The sbaz Command-Line Tool
The fsc Command-Line Tool
Build Tools
Integration with IDEs
Eclipse
Installing the Scala plugin
Developing Scala applications
IntelliJ
Installing the Scala plugins
Developing Scala applications
NetBeans
Installing the Scala plugins
Developing Scala applications
Text Editors
Test-Driven Development in Scala
ScalaTest
Specs
ScalaCheck
Other Notable Scala Libraries and Tools
Lift
Scalaz
Scalax
MetaScala
JavaRebel
Miscellaneous Smaller Libraries
Java Interoperability
Java and Scala Generics
Using Scala Functions in Java
JavaBean Properties
AnyVal Types and Java Primitives
Scala Names in Java Code
Java Library Interoperability
AspectJ
The Spring Framework
Terracotta
Hadoop
Recap and What’s Next
A. References
Glossary
Index
About the Authors
Colophon
Copyright
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Next
Next Chapter
Programming Scala
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset