Robert Shecter

My answer to, “Is it practical to write functional code inside a highly OOP code base?”

I vote yes. :-) The biggest caveat will be your team and their buy-in.

You don’t mention a language, so I’ll use Python as an example. I personally found it very easy to begin doing functional programming inside a big messy OOP Python codebase. It was so messy that the full app could only run on my manager’s home computer. (!) FYI, this was no tiny startup. Starbucks was our client. They should have known better. Anyhow…

I didn’t give it much thought; I just worked like normal. Mostly TDD, writing tests for the functions I wanted, then coding them using Python’s standard modules and functions. I didn’t need to create a class, so I never did. (That says a lot in favor of fp IMO.)

My boss was a little confused, then low-key impressed. The assignment had been something like,

“Write code to check a credit card number and do XYZ with the data”.

So when he asked how to use my code, I showed the top-level function and replied, “Just call this, some_module.process_cc_number()“. It was a lot less work than my team-mates were used to. Normally they’d have to find a “factory”, instantiate a class, remember to set the correct attributes in the right order, read the comments to see how to tell it to “run”, blah blah blah…

Leave a comment