DEV Community 👩‍💻👨‍💻

Discussion on: You don't need classes

josef37 profile image
Josef Wittmann

There was a talk by Robert C. Martin (Uncle Bob) once about SOLID, where he started to explain, what advantages OOP has over the "old way".

And his main point was that classes make polymorphism so much simpler that it enables you to use dependency injection - which in turn does not make your top-level code depend on all details (aka inversion of control).

But most JS code I write and read does not use that at all, so classes are not that useful in these cases.

latobibor profile image
András Tóth • Edited on

I am late to the discussion but the thing we don't talk about is language design. At the end of the day that will constrain what constructs can or cannot work effectively. Since JS is neither functional nor object oriented languages, none of the "pure" approaches work "elegantly" (i.e. a functional approach creates a lot of clutter and stringly typed solutions, while this is a shit-show on its own right in JS). I know some managers will want to set aside "elegant things" over "working things", but truly when you have anything stringly typed you are setting up a bug yourself - somebody at a refactor, at a simple renaming will miss to update the string.

Therefore what made Java bearable might make JS unbearable or the other way around. I also saw people use maps instead of classes in Java, because "it compiles and serves its purpose, so it's OK".

Some comments have been hidden by the post's author - find out more