Echo JS 0.11.0

<~>
pluma 3432 days ago. link 1 point
> If you choose to use class, I hope I never have to try to maintain your code. In my opinion, developers should avoid the use of constructors, class, and new, and use methods of inheritance which more closely follow the language architecture.

How quaint.

Unlike `with` and its ilk, using `class` in and of itself is not a problem. It's a smell at best. And relying on smells alone can lead to false positives.

I'm a JS programmer. My use of (modern) JS was not preceded by a class-based language like Java or C# but Python, which itself frequently prompts discussions about the merits of classes over functions and plain objects (although Python has no other form of inheritance than classes).

I don't see new/class-style inheritance as a problem. It's another gun in the weapons rack and like all guns it provides plenty of ways to shoot yourself and/or others. But unlike `with` and other things that should be avoided no-questions-asked, it's not a pure footgun.

Crying foul at the introduction of a more sugary syntax for the constructors-and-prototypes idiom and deriding "this" as evil is reactionary at best, xenophobic at worst. JS "classes" are not the devil and they are here to stay. You can limit yourself to a "class-free" subset of JS if you find them so appalling but a stubborn wilful ignorance of idioms you personally object to does not make you a better programmer -- it only lets you stagnate in isolation.

You can pretend JavaScript is Haskell and use broken implementations of monads, you can pretend constructors and methods don't exist and drown in a low-level sea of factories and prototypes, you can cast rocks at anyone who dares consider jQuery, but at the same time the rest of us will be out there, using the right tools for the job and getting shit done.

EDIT: I think it's important to realize that it's not classes but inheritance that causes the most problems and is most abused. It doesn't matter whether your inheritance is prototypal or classical (emulated through prototypes -- a feat that can not be achieved the other way around). Most cases of inheritance would be better served by composition. JS classes are just a nice way to create thin object factories -- inheriting between them should be considered meta-programming and thus be used sparingly and carefully.

Replies