0

I read this blog post recently: The Two Pillars of JavaScript Part 1: How to Escape the 7th Circle of Hell, which is essentially a criticism of object oriented programming, and advocacy for funtional programming instead.

Some key points made:

  • Constructors violate the open/closed principle because they couple all callers to the details of how your object gets instantiated. ... JavaScript doesn’t need constructor functions because any function can return a new object. With dynamic object extension, object literals and Object.create(), we have everything we need — with none of the mess. And this behaves just like it does in any other function. Hurray!

  • Classical Inheritance generally lets you inherit only from a single ancestor, forcing you into awkward taxonomies. I say awkward because without fail, every OO design taxonomy I have ever seen in a large application was eventually wrong.

  • The coupling between a child class and its parent is the tightest form of coupling in OO design. That’s the opposite of reusable, modular code.

    Making small changes to a class creates rippling side-effects that break things that should be completely unrelated.

Ok, sure. Without discussing the merits of these arguments (I think the article could do with some code examples) - how is this functional/prototype hacking paradigm used in practise?

ie. Particularly in regards to a framework like Angular or React - where the foundation of components are ES6 classes that extend a framework parent class.

  • 1
    You might be interested in React's 'stateless functional components'. I can't comment on Angular. – jasonk Sep 6 '18 at 4:06
  • @jasonk Sure - React has stateless functional components, but it's hard to know how you would create a button that knows how many times it has been clicked with it. – dwjohnston Sep 6 '18 at 4:20
  • see Discuss this ${blog} – gnat Sep 6 '18 at 9:52
  • you'll have to find some functional programming advocates..... – Ewan Sep 6 '18 at 12:36
  • @dwjohnston, you cite Classical Inheritance, but JavaScript inheritance works on prototypal inheritance which works a bit differently than classic inheritance. – Daniel Nov 24 '18 at 19:17

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.