Classes Suck

I am not an OOP convert. I’ve spent most of my professional life working with classes and objects, but the more time I spend, the less I understand why you’d want to combine code and data so rigidly. I want to handle data as data and write the code that best fits a particular situation.

Games in C by Jonathan Whiting

Totally feel the same way.

Pity the people in charge of ES6 felt the need to officially add classes to JavaScript.


Get New Posts via Email

I don't always post, but when I do, you can get it sent directly to your inbox.

Join 15 other subscribers

  • Encapsulation is why classes don’t suck and the fact that there is a class syntax now doesn’t mean the concept of classes were just added to JavaScript

    • You could simulate classes before with the new keyword, but it was this thing you did with a function and an object that resulted in something like a class.

      Inheritance and extension was still messy but we could keep up the illusion if we didn’t force the paradigm.

      Now, it’s officially called a class.

      Classes are little more than helper functions tangled in with state. In most cases you can cleanly separate the two, which begs the question of why they’re coupled together in the first place.

      • The new keyword isn’t for simulating classes even in languages like PHP that have had class keyword since OOP was introduced. The new is for creating an instance of class thereby creating an object. I see you’re referring to JS here perhaps your title should have been Classes suck in JavaScript because you should see how useful encapsulation is in building GUI programs. The tone of the title suggests you’re trolling. Functions are objects and can play the role of classes allowing nested functions assigned to prototypes in ES5. The necessity of code being structured like this is unarguable but the ES5 syntax is so unpleasant for anyone coming from regular conventions of other languages. We’ve used it enough to get used to it but if ES6 is introducing what we’ve anticipated then we’re left with a choice to either stick with the old ES5 syntax or move to the awesome ES6 class syntax

        • I’m not trolling. No time for that.

          1. I feel classes suck. That much interdependence between your data and the helper functions you user to operate on it is excessive to me.

          2. Previously I could pretend class don’t exist in JavaScript. I hear there’s differences between classical inheritance and inheritance in JavaScript. I wouldn’t know personally.

          All I can tell you is you could do something fancy with happens with new, function and an object and you get the JS representation of a class.

          Now, there’s an actual class system. JavaScript is slightly less functional for this one and I’m not happy about it.