DEV Community

Discussion on: Class Contradictions in TypeScript vs JavaScript

Collapse
raresportan profile image
Rares Portan

The problem (at least in my case) is not with the class itself. Is with this.
If you are using classes, of course you use methods which change the state using this. And that can lead to a lot of frustration, and people need to use bind(this).

When instead of using classes with methods you start using pure functions the code is much much more clear and testable.

Also we create types using class (or better with type in TS), so classes cannot be ignored completely. But this doesn't mean that all code should be classes.

I recommend you to try to read this book, to see the things from the eyes of a FP fanboy:
mostly-adequate.gitbooks.io/mostly...

Collapse
bytebodger profile image
Adam Nathaniel Davis Author

The binding issue has always felt like a red herring to me. There's no scenario where you must .bind(this). I haven't used .bind() in years. But I understand that, for those who don't know how to get around it, it's annoying. When I first started React, it annoyed the heck outta me.

I appreciate the link! I'm definitely checking that out.

Collapse
greenroommate profile image
Haris Secic

The problem with FP is that it's the same as OO. Devs like to get stuck on some philosophy and hate all others. Some of us like to mix and match. Just look at Scala, a lot of FP people hate it for using some OO. A lot of OO people hate it for being FP, and some of us love it for being just that, a free choice of 2 worlds.
Now as soon as you try to be reasonable and just get the work done it fires up crowd in development as theres popular belif that this is a job where you need to be smart, know math, and such, thus the need for philosophy and hate the people who think they're only humans.
"If it was up to engineers in automobile industry we would have no cars today".

Collapse
bytebodger profile image
Adam Nathaniel Davis Author

I wish I could give this more hearts. This basically sums up about half of my blog posts. I understand that everyone will have preferences and, on occasion, we all find subjects on which we feel passionate. But for too many devs, they see nearly every architectural choice as an opportunity to enlist in another Holy War.