After a bumpy start with Scala on Day 1, I’ve moved onto the second day of Scala in Seven Languages in Seven Weeks.
Scala, Day 2: Thoughts
The second Scala chapter shifts gears to functional programming. Unfortunately, I was impatient on Day 1 and had already looked up all of these concepts (and some more) to build a Tic Tac Toe game. As a result, I breezed through the chapter.
On a side note, I was using Scala on a personal project and rewrote some Java code using Scala. As much as I complained yesterday about Scala’s complexity, the slow compiler, and poor IDE support, I must admit one thing: the resulting code was noticeably cleaner, shorter, and easier to read.
The language is certainly not perfect, but I need to make sure I’m not missing the forrest for the trees: it’s still likely a vastly superior alternative to Java.
Scala, Day 2: Problems
The functional programming problems in this chapter were extremely simple. I burned through them in a few minutes and present the code without further comment:
String foldLeft
Use foldLeft
to compute the total size of a List of Strings.
Censorship
Write a Censor
trait with a method that will replace “curse” words with
“clean” alternatives. Read the curse words and alternatives from a file and
store them in a Map.
Output:
On to day 3
Learn about pattern matching and actors in Scala, Day 3.
Bryan Covell
If you enjoyed this post, you may also like my books, Hello, Startup and Terraform: Up & Running. If you need help with DevOps or infrastructure, reach out to me at Gruntwork.