OOP (Java/C#) v.s. Functional (Scala, Clojure)

I’ve been trying to come up with a fairly well formed argument to support the idea that “the software development  community should start favouring modern functional languages.”

While I’m still collecting my thoughts on this … A couple of days ago Zite pointed me to this blog post. I believe it provides a sound argument and it conveys a similar point of view to what I would have liked to put forward.

 

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

4 thoughts on “OOP (Java/C#) v.s. Functional (Scala, Clojure)

  1. Ken Stevens

    Alexei,

    Excellent post, and bang-on on so many fronts.

    Ben,

    My reading of the post is not so much a knock on object-oriented programming as it is asking the question: If we’re not doing object-oriented programming anyway, then why are we still using an object-oriented programming language?

    Here’s some typical code from a java SWT application:

    combo.addListener (SWT.DefaultSelection, new Listener () {
    public void handleEvent (Event e) {
    System.out.println (e.widget + ” – Default Selection”);
    }
    });

    If you use guava, you have to write code like this all the time. This is a consequence of jamming object-oriented principles into a domain where they’re not a good fit. And I think what we’re discovering as software development matures, is that there are fewer and fewer real-world software problems nowadays for which object-oriented principles are a good fit.

    I’d much rather write code like this:

    combo.addListener (SWT.DefaultSelection, function(Event e) {
    System.out.println (e.widget + ” – Default Selection”);
    });

    • Caleb Powell
      Caleb Powell

      I agree with your points Ken.

      The functional languages that Alexei has chosen (Scala and Clojure) are targeted at the JVM and can be run on nearly any stack that we deliver to. Assuming fluency in all of them, wouldn’t it make sense to pick the best language for the job?

  2. Ben Hall
    Ben Hall

    Hey Alexei,

    I’d be interested in hearing more about why we should use Functional Programming (FP), but make sure that you’re comparing FP to the appropriate baseline. That is, for the most part, I don’t think we do much Object Oriented Programming (OOP)–at least not in the service layer. Therefore to compare FP to OOP is to use OOP as an easily knocked down straw man (as the post that you linked to does).

    I’m not sure that means you should just compare Functional Programming against Procedural Programming though.

    BH

    • Alexei Guevara
      Alexei Guevara Post author

      Hey Ben,

      My read of the post is similar to Ken’s.

      It could be argued the OOP promise never materialized because people don’t
      know how to do OOP, or that OOP is hard … But what is OOP ? According to
      Alan Kay, OOP is only about message passing.

      Still, I would like to make Ken’s point a bit stronger, and
      instead of saying that:

      “If we’re not doing object-oriented programming anyway, then why are
      we still using an object-oriented programming language?”

      I would like to say that:

      “we are not doing object-oriented programming because we’ve found, through practice!,
      that it is not an adequate approach to build what we know as enterprise software.
      why are we still using an object-oriented programming language?”

      About why a functional approach (à la clojure) might be more beneficial than an object-orinted one.

      I can not say it better that Rich Hickey – http://www.infoq.com/presentations/Simple-Made-Easy

Leave a Reply