As a consequence of this functional-programming obsession, classes - and JS's pseudo-class keyword - are bad. Really, really bad. Don't ask why they're bad. If you even ask such a question, you risk being ostracized. So rather than risking the fanboys' wrath, just quiet down and accept that classes are bad.
A lot of the more-senior, more "hardcore" JS acolytes have (by my estimation) increasingly migrated toward TypeScript in the last 3-4 years. Sure - you're not required to write TS to be a "real" frontend/JS dev. But it feels (to me) like TS is becoming a much larger influence amongst the hardcore JS devs - the same devs who seem so deeply offended by the sight of the
The previous point is amplified if you're an Angular dev. Modern Angular has become, basically, a TypeScript library.
When you start writing a lot of TS, and you start talking to a lot of those grizzled JS veterans who now prefer to code only in TS, they don't seem to have too many problem with
I won't repeat here all of my frustrations with the "typical" JS dev who wrinkles his nose at the
class keyword, but believes anything inside a
function is sublime. You can see those articles linked at the top of this blog series.
My only point (in this section) is to highlight the fact that, nowadays, if you're developing in React, or in vanilla JS, or in many other JS libraries, there's a good chance that some of your team members disdain classes - and love functions. And if you don't wanna be seen as the out-of-date dinosaur on the team, you'd better shape up and start cranking out more of those functions.
And maybe I could get down with the whole idea that any use of a
class keyword is somehow "wrong" - if it weren't for some of the glaring contradictions that I feel exist in the JS/TS code-sphere. Specifically, I can't figure out, for the life of me, why it is that a class - in JS - is somehow antithetical to the core idea of JS. But if you switch to TS (and all JS is TS), it's perfectly fine to start cranking out classes??
You don't have to take my word for it. Spend a few minutes googling React tutorials - especially, any tutorials published in the last two-or-so years. You'll see that many of them are heavily focused on functions. (Or... on the new "hotness" - Hooks!) Then spend some time googling the latest tutorials on TS. And repeatedly, you'll find yourself running smack-dab into... classes.
Before you get up-in-arms, please understand: I'm perfectly aware that classes aren't in any way required in TS. I've found numerous cases in TS where classes seem to be the "default" answer - or where, by my estimation, they just seem to be the "solution of least resistance".
But this isn't meant to imply that classes are required for TS devs. If you're a FP fanboy, and a TS fanboy, you can pretty much write all of your glorious TS code without ever having to reach for that mean, ugly, nasty
class keyword. But I can't help but notice that, over and over again, I start researching "how to solve Problem X in TypeScript", and over and over again, the suggestions I find from the community are written with classes.
I'm pretty sure that I understand how this (perceived) dichotomy arose. JS is TS. So, on some level, you'd think that we'd have the same trends influencing both communities. But TS has a very strong lineage... from C#.
Now, don't start hoopin' and hollerin'. I fully understand that there are few similarities (under the covers) between C# and TS. But, syntactically, TS looks incredibly familiar to anyone who's coming over from the C# world. And that makes perfect sense, because TS is the logical spawn of Microsoft's previous involvement in the ECMAScript open-source community.
With all that in-mind, it makes perfect sense that TS and C# share (syntactic) constructs such as:
- etc., etc.
But I'm still sometimes baffled to see how classes are increasingly shunned in the "plain JS React" community - but they seem (to me) to be much more tolerated in the TS-React community.
I was inspired to write this because I have a friend. He's a dev, like me. But he's far younger than me. And he's, frankly, a far better dev than me - a real "whiz kid" type. He lives-and-breaths this stuff. While my experience usually allows me to hold my own in a conversation with him, I'll freely admit that he's already internalized much more deep knowledge about programming than I ever have.
This friend of mine is a pretty hardcore "class hater". He thinks that the keyword never shoulda been introduced to JS. If the JS code works perfectly - but it uses classes - he sees it as a central flaw.
In the last year-or-so, he started making the TS conversion. He was slow to adopt it - but once he did, he really "found religion" so-to-speak. I don't honestly think he wants to code in anything but TypeScript at this point.
So, at this point, I don't really know what to say. I realize that some TS devs hate classes. And I know that some JS devs are perfectly fine with them. And maybe the only "problem" is in my own perception. Maybe the trends are not what I see from my old, cranky perch on the programming shelf. But if there is anything to my analysis, it just doesn't seem to make any sense why "hardcore" JS devs are so disdainful of classes - and yet many "hardcore" TS devs don't seem to have any problem with them.