If you’ve read any of my books (like the Scala Cookbook or Functional Programming, Simplified), and thought, “Hey, I can write a book,” I encourage you to do so. One book that has been helpful in my writing career is William Zinsser’s On Writing Well: The Classic Guide to Writing Nonfiction. If you’re seriously thinking about writing a book about programming or any other technical topic, it’s a good read.
In an effort to “Get rid of the crap,” I asked my editor if we could delete an entire chapter from the Scala Cookbook, and she said yes. I didn’t know if they’d allow that since the advance they paid me is based on a proposal of X chapters, but they’re all-in on just trying to create a good book, which is nice.
As I finish editing this book in January, 2014, it’s a busy time. In addition to releasing this book, I just finished writing a 700+ page computer programming book for O’Reilly named Scala Cookbook.
A funny thing about the Scala Cookbook: I wrote it on a whim, as a dare, wondering, “Am I good enough to write this book, on my own?” I doubted myself for a little while, but then overcame my fears and sent an email to the people at O’Reilly. As I’ve said throughout this book, all you are is attitude.
Photos of mom and cub polar bears. I hoped O’Reilly would use these for the cover of the Scala Cookbook — because of the whole “scalable” thing, and to help raise awareness about climate change — but whoever puts images on their book covers had something else in mind.
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 1.3, “How to Split Strings in Scala.”
You want to split a string into parts based on a field separator, such as a string you get from a CSV or pipe-delimited file.
Use one of the split methods that are available on String objects:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 1.2, “How to Create Multiline Strings in Scala.”
You want to create multiline strings within your Scala source code, like you can with the “heredoc” syntax of other languages.
In Scala you create multiline strings by surrounding your text with three double quotes:
This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 1.1, “Testing String Equality in Scala.”
When using Scala, you want to compare two strings to see if they’re equal, i.e., whether they contain the exact same sequence of characters.
In Scala you compare two String instances with the
== operator. Given these strings:
The funny thing about writing the Scala Cookbook is that it started as a whim. I was just about to leave for a vacation at the beach, and right before I turned off the computer, a thought flashed in my mind, “I should contact the people at O’Reilly about writing a cookbook for Scala.” I then had a doubt that they would actually do it, but I applied the “What the heck” rule — i.e., “What the heck, what do I have to lose?” — and sent the email.
I dug around the internet for a few minutes, found the correct O’Reilly email address, sent them a message, turned off the computer, and drove to the beach. While I was at the beach the publisher wrote and said, “Love it, send me a full proposal!”
So if you’re thinking about doing something, but are afraid or uncertain about doing it ... apply the “What the heck” rule, and give it a shot. :)
On May 24, 2013, I finished with the last hardcopy chapters of the Scala Cookbook. I put all of the chapters next to the paper shredder as a way to show what I had just done. The final edits would be finished with a copywriter over the next several weeks, and I signed off on the final edition while I was at Virginia Beach.