Saturday, July 25, 2015

Best Scala Books

It is hard enough to remember my opinions, without also remembering my reasons for them! ๐Ÿ˜†
Nietzsche, as quoted in Moore's and Mertens' The Nature of Computation (Oxford).
I have no doubt in my mind that Scala is extremely well-positioned to serve as a bridge between the object-orientation of Java and the functional programming languages. My journey began several years ago with a highly readable book called Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages (O'Reilly) by Austin-based Bruce Tate. And in case anyone wondered where the name "Scala" came from: "Scala" is the Italian word for stairway ๐Ÿ‘ž ๐Ÿ‘ก ๐Ÿ‘ฃ ๐Ÿ‘ข

Casting a glance back at my (ongoing) journey, here are the books that have proved most helpful to me in grokking Scala—I'll take an opinionated look at the following books, in turn
  1. Programming Scala: Scalability = Functional Programming + Objects (O'Reilly), by Dean Wampler and Alex Payne ⛳
  2. Scala in Action (Manning) by Nilanjan Raychaudhuri ๐Ÿš
  3. Scala Cookbook: Recipes for Object-Oriented and Functional Programming (O'Reilly) by Alvin Alexander ๐Ÿ”
  4. Scala in Depth (Manning) by Joshua Suereth ๐ŸŠ
  5. Functional Programming in Scala (Manning), by Paul Chiusano and Rรบnar Bjarnason ๐Ÿ“
  6. Scala for the Impatient (Addison-Wesley), by Cay S. Horstmann ⏳

1. Programming Scala: Scalability = Functional Programming + Objects (O'Reilly), by Dean Wampler and Alex Payne ⛳


If you're going to read only one book on Scala, make it this one: Programming Scala: Scalability = Functional Programming + Objects (O'Reilly), by Dean Wampler and Alex Payne. It has been said about Scala—and very correctly so—that it has a very large surface area. In their book The Well-Grounded Java Developer, Evans and Verburg define it like so:
The surface area of a language is the number of keywords and independent language constructs that the working developer must master to be productive in the language. 
Given that, Dean's book is immensely helpful in that beginning readers don’t need to read the entire book to become productive with Scala. Instead, you can read just the first three chapters—which essentially give you a quick summary of the core language features—and immediately start experimenting with Scala using the REPL. And when you're ready to explore the depths of Scala, it's all in there, too. I've found this a truly comprehensive guide to the Scala language as well as its ecosystem.

Both beginners and advanced users will find much of value in this book. As my experience with programming Scala over the years has grown, it has become my go-to book. Dean's unique combination of deeply methodical thinking and pragmatism are writ large in the pages of this one-of-a-kind book.

The second edition of Programming Scala: Scalability = Functional Programming + Objects is absolutely worth getting, even if you've read the first edition. I'm sure glad to have found this book—beginning with the first edition. I'm confident that you won't be disappointed.


2. Scala in Action (Manning) by Nilanjan Raychaudhuri ๐Ÿš


The book Scala in Action (Manning) by Nilanjan Raychaudhuri is another excellent book which has aged nicely over the years that I've programmed in Scala, and as my experience with it has grown. It's target audience is clearly the enterprise software developer who is typically working with a massive code-base. While this book isn't nearly as comprehensive a guide to Scala the language, it definitely has its strong points. One thing I really appreciated was how the author introduces each chapter with an engaging prelude; with the captivating motivational material to grab you up-front, the ensuing narratives in the chapters each flow smoothly, and the chapter-to-chapter transition is pleasing and smooth as well.

Another quality of this book that I appreciated a lot are the copious footnotes, containing pointers to useful references for the reader to explore (The quality of these references is especially high, much more so than I typically find in other books—Kudos to the author for painstakingly researching and then culling the research to share only the very best references).

This book is particularly good for those transitioning from Java to Scala. James Gosling (the renowned designer of the Java programming language) has said
If I were to pick a language to use today other than Java, it would be Scala.
If that description fits you, then this Scala in Action the book for you. I found it especially strong in its coverage of the inevitable topic that's highly relevant for seasoned Java programmers—interoperability between Scala and Java. I liked the author's take on working with Java generics and collections, on solving integration challenges, plus a nice bonus on building web applications in Scala while using Java frameworks.


3. Scala Cookbook: Recipes for Object-Oriented and Functional Programming (O'Reilly) by Alvin Alexander ๐Ÿ”


The programming cookbooks are perennial favorites with many of us software developers. This one, entitled Scala Cookbook: Recipes for Object-Oriented and Functional Programming (O'Reilly) by Alvin Alexander follows in the fine tradition of the legendary programming cookbooks published by O'Reilly. Probably the first thing you will note is this book's size! Coming in at 722 pages, it's quite the boat anchor, and not for the faint of heart ;)

Joking aside, I think highly of this book from a fellow Aggie. Think of this tome as high octane fuel to propel your programming adventures in Scala. It is replete with all things common sense and pragmatic about doing things the Scala way.

What I appreciate the most about this book is its relentless focus on serving the reader with recipe after recipe of high-quality code—undoubtedly coming straight from the trenches of software development in Scala—accompanied by insights into the why and wherefore of the rationale taken by any given recipe. If pragmatic, no-nonsense advice (on nuts-and-bolts Scala programming) is what you're after, this is the book for you. My first taste for the pragmatism that the author brings to the pages of this book came with this delightful self-introduction. Thus, while introducing his circuitous route to software development (after getting a degree in Aerospace Engineering from Texas A& M University), the author says
...Once he became a practicing engineer, he realized he liked software and programming more than engineering. So in approximate order he taught himself Fortran, C, Unix and network administration, sed, awk, Perl, Java, Python, Ruby, JRuby, Groovy, PHP, and Scala. During this process he started a software consulting firm, grew it to fifteen people, sold it, and moved to Alaska for a few years...
In a nutshell—much as the author himself notes in the Preface—this book is
...a cookbook of problem-solving recipes about Scala, the most interesting programming language I’ve ever used. The book contains solutions to more than 250 common problems, shown with possibly more than 700 examples. (I haven’t counted, but I suspect that’s true.)
The central theme, which I found informing the book Scala Cookbook: Recipes for Object-Oriented and Functional Programming is the value that the author sees in how Scala empowers programmers to write concise, readable code. Code maintenance, anyone? I won't be a bit surprised if you, too, spend the vast majority of your time reading code, compared to the time spent writing code. And that's where Scala truly shines with its brevity and expressiveness, packing a lot of punch in little chunks of code. Good bye to the grief we've grown accustomed to experiencing with the lack of readable code as well as boilerplate code!


4. Scala in Depth (Manning) by Joshua Suereth ๐ŸŠ


I've got a confession to make: This next book that I am about to recommend, I do so with a tad bit of trepidation, because it has challenged and stretched to its limits—and continues to do so—my conceptualization of the expansive solution space spanned by the true Scala way of doing things...

This book, Scala in Depth (Manning) by Joshua Suereth, is the work of a programming virtuoso! Having made the confession above, I'm glad to have doggedly stuck to grokking the sublimely intricate themes to be found in its pages. While this is definitely not your first, or even second, book on Scala, please don't let that deter you. Repeatedly trekking over and dipping into its pages—that's what I've been doing the past several years—will be time supremely well invested. Once you've read a couple of books on Scala, experimented at the REPL to your heart's content, and are writing some significant Scala code, this book will be your guide to some amazing things that this amazing language equips you with.

To use the notion of SNR—Signal-to-Noise Ratio, of which all engineers get disabused at one time or another during their training—this masterpiece has practically zero fluff. In my mind, this book will easily still be around for another decade, serving as a rich source of insights into Scala, for developers like us to mine and benefit from. It's rather difficult to convey the richness of topics covered quite thoroughly in this fantastic compendium of relatively advanced themes in the Scala solution space. What will help convey that richness as a prelude are these words of the stunningly brilliant and creative computer scientist, Martin Odersky—designer of the Scala language—which he offers in the book's Preface:
Joshua Suereth is one of the most complete programmers I know. Familiar with a whole gamut of programming languages and techniques, he is an expert in high-performance systems, build tools, type theory, and many other areas. He is also a gifted teacher, and all that combined is what makes Scala in Depth special.
This book provides in-depth coverage of several of the more intricate areas of Scala, including advanced aspects of its type system, implicits, composition techniques with traits, collections, actors, functional categories. But this is not a dry recollection of language and library concepts. The book is full of practical advice on how to apply these lesser known parts of Scala in useful ways, and what the best practices are...
If what you're looking for is expert guidance on how to write idiomatic Scala code and understand trade-offs when making use of advanced language features, you will like this book immensely. The type system in Scala is covered exceptionally well, as are patterns in functional programming (ala Scala), and you can't help but appreciate the author's unique take of promoting "...the blended style of Scala, where paradigms are mixed to achieve something greater". As the author himself notes
Scala provides the tools needed to blend the object-oriented and functional programming worlds. Scala is at its best when these two evenly share a codebase. The biggest danger to misusing Scala is to ignore its object orientation or its functional programming. But combining the two is the sweet spot that the language was designed to fulfill.
Be prepared for some deep dives into equally deep topics, albeit made relatively accessible by this book. If I could wish for one thing to be different about this book, it would be more elaborate coverage of the various topics. And what I said earlier about the incredibly high SNR of Scala in Depth in that there is, literally, zero fluff, the brevity could have been softened somewhat by more detailed explanations. Perhaps that will change, should the idea of a second edition of this book be conceived and get under way. Whatever path you take to fathom the depths of this book, I do believe that your deep dives will prove worthwhile. Mine have been so far, even as they continue in earnest :)

5. Functional Programming in Scala (Manning), by Paul Chiusano and Rรบnar Bjarnason ๐Ÿ“


I found a gem of a book in this next title: Functional Programming in Scala (Manning), by Paul Chiusano and Rรบnar Bjarnason. This book provided the perfect answer to a vexing question that had been dogging me for a while—In the words of Scala's creator, Martin Odersky, who has articulated that exact question so articulately as follows, in his Foreword to this book
So to properly learn functional programming in Scala, should one make a detour via a pure functional language such as Haskell?
So I got started a bit with Haskell—Got the GHC (Glasgow Haskell Compiler) and read parts of the book The Haskell Road to Logic, Maths and Programming (College Publications), by Kees Doets and Jan van Eijck. But I wasn't sure—actually, still am not—whether I wanted to invest time in learning the rather alien-looking syntax of Haskell, let alone grok its idioms. Luckily for me, this book (Functional Programming in Scala) came along, and which I read via Manning's MEAP (Manning Early Access Program). As Martin Odersky continues in his Preface, answering the vexing question that I alluded to earlier, he elaborates
Any argument in favor of this approach has been severely weakened by the appearance of Functional Programming in Scala... What Paul and Rรบnar do, put simply, is treat Scala as a pure functional programming language. Mutable variables, exceptions, classical input/output, and all other traces of impurity are eliminated. If you wonder how one can write useful programs without any of these conveniences, you need to read the book. Building up from first principles and extending all the way to incremental input and output, they demonstrate that, indeed, one can express every concept using only pure functions. And they show that it is not only possible, but that it also leads to beautiful code and deep insights into the nature of computation.
Without a shadow of a doubt, this book is challenging—and I continue to work through it—but that challenge originates in the fundamentally different (functional) way in which it invites us to think about programming (i.e. contrasted with the pervasive object-oriented paradigm in which the vast majority of us swim nowadays). This is a book you likely won't regret reading; to give you a sense of the topics covered, here is the Table of Contents:
1. Introduction to functional programmingChapter 1. What is functional programming? Chapter 2. Getting started with functional programming in Scala Chapter 3. Functional data structures Chapter 4. Handling errors without exceptions Chapter 5. Strictness and laziness Chapter 6. Purely functional state  
2. Functional design and combinator libraries Chapter 7. Purely functional parallelism Chapter 8. Property-based testing Chapter 9. Parser combinators  
3. Common structures in functional design Chapter 10. Monoids Chapter 11. Monads Chapter 12. Applicative and traversable functors  
4. Effects and I/OChapter 13. External effects and I/O Chapter 14. Local effects and mutable state Chapter 15. Stream processing and incremental I/O
The bottom-line with this gem—Functional Programming in Scala—is that it will challenge you, and jolt you out of your comfort zone. But if you're up to it, you'll be richly rewarded.

6. Scala for the Impatient (Addison-Wesley), by Cay S. Horstmann ⏳


Although not in the same league as the preceding books, this book is especially good in covering the syntax of Scala both succinctly and comprehensively. I reckon the title says it all: Scala for the Impatient (Addison-Wesley), by Cay S. Horstmann. This book will be especially helpful for anyone coming brand new to Scala. When I read it, I was quite impressed by how the author had diligently crafted the material to help the reader—typically, someone coming from Java to Scala—bridge the chasm between the two languages.

It also contains lots of tips and tricks—common gotchas that trip up beginning Scala programmers. In fact, this quality, combined with its succinctness and comprehensiveness, makes it a good reference to have around. In the words of Martin Odersky
I am very happy that his book has finally arrived because it really delivers on what the title says. It gives an eminently practical introduction to Scala, explains what’s particular about it, how it differs from Java, how to overcome some common hurdles to learning it, and how to write good Scala code.
This books nicely addresses for beginners the essential challenge of Scala being a language with a very large surface area (and to which I had alluded earlier). In fact, much as the author himself notes in the book's Preface
Scala is a big language, but you can use it effectively without knowing all of its details intimately.
With these caveats, Scala for the Impatient is definitely a book worth exploring.

In the end, and as I mentioned at the outset, I invite your comments—Having now read my brief take each on the books above...
  • Do you find that your experience of reading any of these books was different? 
  • Perhaps some qualities that I did not cover are the ones that you found the most helpful as you learned Scala and its ecosystem. 
  • Did I leave out any of your favorite Scala book(s)? 
  • I've covered only a partial list of the Scala books that I've read, necessarily limited by the time available...
My hope is that these brief vignettes will help you in your journey to grokking Scala. Bon voyage, and I leave you with a photo of a pseudo-random section—which is clearly biased toward Scala material—of one of my bookshelves ๐Ÿ˜…


Sunday, July 5, 2015

Two Amazing Books


First up is How to Invest Your Time Like Money by Elizabeth Grace Saunders. So just when you thought that Elizabeth had shared all imaginable wisdom on the subject of time investment, she comes back with yet another tour de force of a book. What had amazed me about her first book—The 3 Secrets to Effective Time Investment—was that I could randomly open the book to any page, and be guaranteed a nugget of wisdom. Just to make sure the magic was still working :) I opened the book randomly to the page which leads off a discussion (entitled Routines Require Intentional Practice), and found this insight that I'm partially excerpting here:
At first it will take a great deal of mental and emotional fortitude to even want to start putting these routines into practice.... It's like hacking a new pathway through the jungle of the day when you were used to strolling down a well-established trail or like breaking up scar tissue and retraining your muscles when your body developed bad compensation techniques after an injury.... Ultimately, though, strengthening simple routines leads to a life where you consistently achieve more success with less stress.
~ The 3 Secrets to Effective Time Investment.
This stellar follow-up book—How to Invest Your Time Like Money—is every bit as good. If anything, even more so! Each chapter begins with a delightful quote, of which I'd like to share a couple:
The difference between who you are and who you want to be is what you do.
~Anonymous
Time is an equal opportunity employer. Each human being has exactly the same number of hours and minutes every day.
~Denis Waitley, writer
Much like its predecessor, this book is eminently down-to-earth, and packed with eminently sensible advice. In echoing what another reader has lucidly observed in their online review, I'm compelled to say that this will be a go-to resource for when I need help to re-calibrate what's important.

This book is highly recommended—Much like its predecessor, it is far from stuffy; it entertains even as it instructs. For example, here's the delightful quote that leads of the second chapter (Identify Your Time Debt), in the words of Wilkins Micawber, a fictional character from Charles Dickens's 1850 novel, David Copperfield:
Annual income twenty pounds, annual expenditure nineteen pounds nineteen and six, result happiness. Annual income twenty pounds, annual expenditure twenty pounds nought and six, result misery.
~Wilkins Micawber, David Copperfield


Of the two amazing books that I want to bring to your attention, the second one is a wide-ranging discussion of all things probability. Hang on, please, lest the mere mention of the word probability (erroneously) lead you down the path of contemplating boredom...

While ostensibly academic, this book is amazingly well-written and engaging. Even though my background is in engineering—both my BS and MS degrees are in engineering, with emphasis on computation and software—I can still appreciate the engaging style and sheer logical beauty with which the themes are explored in this book, and how ideas are tackled and presented with peerless reasoning and solid arguments. Here is a prelude—by way of the following excerpt—to the cool stuff that awaits you within its pages:
Models have practical uses of a quite different type. Many people are fond of saying, They will never make a machine to replace the human mind—it does many things which no machine could ever do. A beautiful answer to this was given by J. von Neumann in a talk on computers given in Princeton in 1948, which the writer was privileged to attend. In reply to the canonical question from the audience [But of course, a mere machine can't really think, can it?], he said: You insist that there is something a machine cannot do. If you will tell me precisely what it is that a machine cannot do, then I can always make a machine which will do just that!
I learned about this book—Probability Theory: The Logic of Science—from Eric Jonas in an interview that he gave to Sebastian Gutierrez (a data entrepreneur with a background in math at MIT). Thank you again, Eric! So Eric notes in his advice...
...understand probability theory forwards and backwards. I’m at the point now where everything else I learn, I then map back into probability theory. It’s great because it provides this amazing, deep, rich basis set along which I can project everything else out there. There’s a book by E. T. Jaynes called Probability Theory: The Logic of Science, and it’s our bible. We really buy it in some sense. The reason I like the probabilistic generative approach is you have these two orthogonal axes— the modeling axis and the inference axis. Which basically translates into how do I express my problem and how do I compute the probability of my hypothesis given the data? The nice thing I like from this Bayesian perspective is that you can engineer along each of these axes independently. Of course, they’re not perfectly independent, but they can be close enough to independent that you can treat them that way.
There is one other book which embodies some of the same amazing qualities—engaging style, fantastic material, and sheer loveliness of presentation—that I see in the Jaynes book. And that book is entitled The Nature of Computation by Cristopher Moore and Stephan Mertens (Oxford University Press). It, too, may well be worthy of your time invested in exploring it...


Enjoy :)