Object-oriented – What Functional features are worth a little OOP confusion for the benefits they bring

functional programmingobject-orientedparadigmsprogramming practices

After learning functional programming in Haskell and F#, the OOP paradigm seems ass-backwards with classes, interfaces, objects. Which aspects of FP can I bring to work that my co-workers can understand? Are any FP styles worth talking to my boss about retraining my team so that we can use them?

Possible aspects of FP:

  • Immutability
  • Partial Application and Currying
  • First Class Functions (function pointers / Functional Objects / Strategy Pattern)
  • Lazy Evaluation (and Monads)
  • Pure Functions (no side effects)
  • Expressions (vs. Statements – each line of code produces a value instead of, or in addition to causing side effects)
  • Recursion
  • Pattern Matching

Is it a free-for-all where we can do whatever the programming language supports to the limit that language supports it? Or is there a better guideline?

Best Answer

Functional programming is a different paradigm from Object-Oriented programming (a different mindset, and a different way of thinking about programs). You have begun to realize that here is more than one way (object-oriented) to think about problems and their solutions. There are others (procedural and generic programming come to mind). How you react to this new knowledge, whether you accept and integrate these new tools and approaches into your skill set, will determine whether you grow and become a more complete, skilled developer.

We are all trained to handle and are comfortable with a certain level of complexity. I like to call this a person's hrair limit (from Watership Down, how high can you count). It is a great thing to expand your mind, your ability to consider more options, and have more tools to approach and solve problems. But it is a change, and it pulls you out of your comfort zone.

One problem you may encounter is that you will become less content to follow the "everything is an object" crowd. You may have to develop patience as you work with people who may not understand (or want to understand) why a functional approach to software development works well for certain problems. Just as a generic programming approach works well for certain problems.

Good Luck!