Introduction

Ouch! That hurts my brain! Stop making me think differently. Oh, wait . . . it hurts less now. I get it. This different way of solving the problem has some benefits. I felt that way after my first year of law school. I felt that way for a while when I began coding Scala. What’s this Option thingy? Give me back my null! How do you get the fifth element from a Seq? On and on it went. Day after day of head-splitting paradigm changing and breaking 30 years of coding habits, I am somewhat at peace with the Scala way of coding. Yes, my coding habits were borne out of 6800 machine code coding. Talk about imperative coding. That’s all you’ve got when you’ve got an accumulator, a program counter, and an index register. I grew up through BASIC, Pascal, C, C++, Objective-C, and Java. And along comes this Scala stuff, this functional-objective way of thinking, these compositional design patterns. Who thought up this wacky stuff?

After more than two years of coding Scala, I’ve come to understand that the Scala idioms are really better. My brain has finally stopped hurting. I’ve finally stopped fighting for flow of control statements. I see that it’s more important for me to take small elements and compose them together into complex systems. I understand that if a method always returns the same output given the same input, I can safely glue that function together with other functions into a very complex structure. I understand that explicit looping in my code is a distraction from the business logic that is buried in the code. My path was hard, and I hope yours will be easier.

The first step in writing Scala is not being afraid of the fact that Scala’s going to warp your brain. The next step in writing Scala is accepting that your code is going to look like Java, Ruby, Python, whatever code for a while. It will take you time and effort and more time to code Scala using the idioms in this book. It will take you time to design code that fits into Scala paradigms and to discover and devise paradigms of your own. It will take time but hopefully less time than it took me.

This book is for you. It’s my attempt to show you a different way of thinking about and writing code. I hope that you’ll enjoy our journey through Scala together. I hope that by the end of this book you’ll have a new perspective on coding. I hope that you’ll be writing better code and fewer lines of code yet are happier about the code that you’re writing. So, come along. Stick that little toe in the Scala waters and see if they feel as good for you as they have for me.

Who This Book Is For

This book is for folks with some programming background who want to dip their little toe into Scala, check the temperature, and perhaps wade in some more.

How This Book Is Structured

Chapters 1 through 3 are meant to give you a basic grounding in Scala syntax and Scala idioms. Chapters 4 through 7 tour key Scala features, including functions, pattern matching, Scala Collections and traits. Chapter 8 is a deep dive into Scala’s type system. Chapter 9 discusses Scala and Java interoperability. Chapter 10 rolls the pieces together with an exploration of DSLs and Scala’s parser combinator library. Chapter 11 discusses the standard build tool SBT. Chapter 12 shows how to develop web applications using Scala web framework. Chapter 13 discusses some best practices for Scala.

Prerequisites

You should have the Java JDK 1.6 or higher installed on your machine as well as Scala 2.10 or higher.

Downloading the Code

The source code for this book is available to readers under the Source Code/Downloads tab of this book’s home page, which is located at www.apress.com/9781484202333.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.48.27