What’s Different About This Code
When you write in a language such as Java, C#, or Ruby, you’re working at a number of levels simultaneously. Part of your brain is thinking about the specification—what has to get done. The other part is thinking about the implementation—the nuts and bolts of how to do it. And that’s where things often get bogged down.
But look at that last example. We’re iterating over a set of digits. We’re selecting those with odd or even positions. We’re performing conditional calculations. We’re summing the result. And there isn’t a single control structure in the program. No ifs, no loops. The code pretty much reflects the specification of what we want to happen.
And that’s one of the reasons I’m a fan of functional ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access