3 ms·
> In my mind, the really mind altering thing was seeing > not just that Object Oriented and Functional > programming styles could be compatible, but th
by danneu 14y ago
> In my mind, the really mind altering thing was seeing
> not just that Object Oriented and Functional
> programming styles could be compatible, but that they
> were in many ways complementary.
I recently had this same a-ha moment listening to Gary Bernhardt (destroyallsoftware.com) talk about the functional core with an imperative shell.
In screencast #81 (Nov '12), he starts with code that looks like what most people would write if we wanted to write a script that compiles every .markdown file in the current directory to .html. It's an imperative loop that File.reads each path, compiles the file, determines the new filename, and File.writes the result.
Then he refactors away everything except the file I/O into a Page class with immutable methods. In other words, the only mutation that goes on in the end is in that loop (where it can't be avoided). And the result is a Page class that is effortless to test.
Something immediately snapped when I saw that even though it seems so obvious in retrospect. The boundaries of responsibilities in a system became incredibly apparent.
I don't know quite where it happened, but between Martin Odersky's course and idly watching Bernhardt's screencasts, I gained like 10 levels.