I generally agree but if you want a constructive discussion, in what sense it's stupid?

several years ago, when I was first exposed functional style programming, I started to move away from class heavy Java style. I'm not crazy into Haskell level FP but I started to devlope this emotion of disliking class or code with internal private state.

But since 2 weeks ago, I started to use class heavily again. At least in JavaScript, I feel it's still the best tool to capture stateful code in a stateful/mutable way.

But I don't use inheritance. I only use basic polymorphism such as interfaces (TS).

Coming from Go, I feel simple interfaces and message passing between stateful component are enough to capture most business logics and actually makes stateful programming fun.

But yes, there are many problems of JavaScript class. I never liked prototype chain. It's a cute idea but a bad idea. It's lack of async constructor is always bad.

Reply to this note

Please Login to reply.

Discussion

I'm with you on most of that. The problem I'm running into right now is trying to access a child class from a parent. Specifically, `static create() { return new this() }` doesn't seem to work.

I use zero inheritance except for the class component in Preact. Therefore, I can't feel your problem.

Do you use typescript? I feel like typescript nudges you toward classes. I have a very clojure-like programming style (functions and structs) which typescript hates.

"typescript nudges you toward classes" I believe this is only a reflextion on many existing projects migrated to TS from 2017ish JS when class was a new thing.

TypeScript has lots of compile time utilities to actually write code more like a statically typed functional language.

I really like clojure's design philosophy and Blowater is mostly functions, object literals and channels.

But I actually end up loving class component for them maintain their state locally and I don't use hooks at all.

I still use functional component for pure statelss UI. But stateful UI is all written with a mix of class components and global states.

I use class mostly just for runtime namespaces. Yeah, probably only used 10% of what a JS class can do but I feel the 10% is the good parts.

Becuase I also write unit tests and integration tests. Having a strong compiler can reduce the amount of tests that I need to write.

Prototypes based is a little messy feeling imo.

Class-based better