Atomic Scala
Bruce Eckel
Dianne Marsh
Mindview LLC
Crested Butte, CO
How to Use This Book
This book teaches the Scala language to both programming beginners and to those who have already programmed in another language.
Beginners: Start with the Introduction and move forward through each chapter (we call chapters atoms) just as you would any other book including the Summary atoms, which will solidify your knowledge.
Experienced Programmers: Because you already understand the fundamentals of programming, we have prepared a fast track for you:
- Read the Introduction .
- Perform the installation for your platform following the appropriate atom. We assume you already have a programming editor and you can use a shell; if not read Editors and The Shell .
- Read Running Scala and Scripting .
- Jump forward to Summary 1 ; read it and solve the exercises.
- Jump forward to Summary 2 ; read it and solve the exercises.
- At this point, continue normally through the book, starting with Pattern Matching .
Introduction
This should be your first Scala book, not your last. We show you enough to become familiar and comfortable with the language competent, but not expert. Youll write useful Scala code, but you wont necessarily be able to read all the Scala code you encounter.
When youre done, youll be ready for more complex Scala books, several of which we recommend at the end of this one.
This is a book for a dedicated novice. Novice because you dont need prior programming knowledge, but dedicated because were giving you just enough to figure it out on your own. We give you a foundation in programming and in Scala but we dont overwhelm you with the full extent of the language.
Beginning programmers should think of it as a game: You can get through, but youll need to solve a few puzzles along the way. Experienced programmers can move rapidly through the book and find the place where they need to slow down and start paying attention.
Atomic Concepts
All programming languages consist of features that you apply to produce results. Scala is powerful: not only does it have more features, but you can usually express those features in numerous different ways. The combination of more features and more ways to express them can, if everything is dumped on you too quickly, make you flee, declaring that Scala is too complicated.
It doesnt have to be.
If you know the features, you can look at any Scala code and tease out its meaning. Indeed, its often easier to understand one page of Scala that produces the same effect as many pages of code in some other language, simply because you can see all the Scala code in one place.
Because its easy to get overwhelmed, we teach you the language carefully and deliberately, using the following principles:
- Baby steps and small wins. We cast off the tyranny of the chapter. Instead, we present each small step as an atomic concept or simply atom, which looks like a tiny chapter. A typical atom contains one or more small, runnable pieces of code and the output it produces. We describe whats new and different. We try to present only one new concept per atom.
- No forward references. It often helps authors to say, These features are explained in a later chapter. This confuses the reader, so we dont do it.
- No references to other languages. We almost never refer to other languages (only when absolutely necessary). We dont know what languages youve learned (if any), and if we make an analogy to a feature in a language you dont understand, it just frustrates you.
- Show dont tell. Instead of verbally describing a feature, we prefer examples and output that demonstrate what the feature does. Its better to see it in code.
- Practice before theory. We try to show the mechanics of the language first, then tell why those features exist. This is backwards from traditional teaching, but it often seems to work better.
Weve worked hard to make your learning experience the best it can be, but theres a caveat: For the sake of making things easier to understand, we will occasionally oversimplify or abstract a concept that you might later discover isnt precisely correct. We dont do this often, and only after careful consideration. We believe it helps you learn more easily now, and that youll successfully adapt once you know the full story.
Cross-References
Whenever we refer to another atom in the book, the reference will have a grey box around it. A reference to the current atom looks like this: Introduction .
Sample the Book
In order to introduce you to the book and get you going in Scala, weve released a sample of the electronic book as a free distribution, which you can find at AtomicScala.com. We tried to make the sample large enough that it is useful by itself.
The complete book is for sale, both in print form and in eBook format. If you like what weve done in the free sample, please support us and help us continue our work by paying for what you use. We hope that the book helps and we greatly appreciate your sponsorship.
In the age of the Internet, it doesnt seem possible to control any piece of information. Youll probably be able to find the complete electronic version of this book in a number of places. If you are unable to pay for the book right now and you do download it from one of these sites, please pay it forward. For example, help someone else learn the language once youve learned it. Or just help someone in any way that they need it. Perhaps sometime in the future youll be better off, and you can come and buy something, or just donate to our tip jar at AtomicScala.com/tip-jar.
Example Code & Exercise Solutions
Available as a download from www.AtomicScala.com.
Seminars
An important goal of this book was to make the material usable in other forms in particular, live seminars. Indeed, our experience giving seminars and workshops informed the way we created the book, with the intent of producing short lectures (to fit your attention span) and a stepwise learning process with many checkpoints along the way.
Scala is an amazing and elegant language. Its also powerful, and overwhelming if you try to absorb it all at once. Our goal is to present the language in small bites that you can quickly grasp, to give you a foundation on which to build more knowledge.
We want you to finish the course feeling strong and ready to learn more about Scala. To achieve this we select a subset of topics that, once learned, allow you to create useful and interesting programs a base from which you can increase your understanding. We have carefully trimmed away topics that you dont need to know right away (but that youll be able to acquire more easily from other books or more advanced courses).
Were careful to introduce topics before we use them, and we dont assume any programming language background. Books typically go deep on a topic in a single chapter. Instead, we divide topics into multiple atoms, building your knowledge piece by piece so you can understand and absorb each idea before moving to the next. We think youll find this is a more natural way to learn.
Were not covering everything in the language thats too much for a week. Were giving you what we consider the essentials in a way that you can understand them, so you have a strong basis for moving forward with Scala, either through self-study or more advanced courses.
One of the great things about the Atomic format is that it produces small lectures we try to keep them less than 15 minutes each, within the limits of everyones attention span. Shorter, more energetic lectures keep you engaged.
Next page