logoalt Hacker News

halflifetoday at 4:18 PM1 replyview on HN

Of course, the only question is in what way the programming language pushes you. You can TS code where every variable is assigned “any” type, that would void all type safety. Is it possible? Yes. But someone needs to bend the languages will to do that.

Classes have inherent state, and methods which encapsulate logic. That pushed you to create separate logic bundles.

Functions are callable scripts. There are no rules. I’ve seen too many components that invoke tens of hooks, and hundreds of lines of state management. Most classes I’ve seen never reached that. Were there classes that were too big? Of course, but at least there was logic separation with methods.


Replies

bobthepandatoday at 5:04 PM

The great sin of the migration to hooks was that the docs were so poorly written that everyone got into bad habits.

You can have self documenting state like class components in the form of reducers which are just state machines. But it is much later in the documentation.