DEV Community

I'm Javascript. And I'm done taking your shit.

Akaash Patnaik on May 04, 2020

Alright, douchebag! You think you can go on the Internet — the house that I built — and talk smack about me? You thought I wouldn't know every ti...
Collapse
 
190245 profile image
Dave

This! (sorry, couldn't resist).

Seriously though, as an OO developer, I don't hate on JS... I hate on the guys telling me it has to be used as a panacea. JS has it's uses, as does COBOL etc.

Collapse
 
fjones profile image
FJones

Aye. Much as the comedy is appreciated, I think a lot of it does touch on the crux of the issue: There's really nothing JavaScript is good at. Just (increasingly fewer) things it is less frustrating than existing available languages at. It's not really a language of choice, but a language of necessity or for lack of alternatives (though it definitely could be - the paradigms lend themselves really well to some really niche applications).

As a scripting language, even for the web, we've been working around it since it became common - very little web JavaScript is actually written in ECMAScript - and when it is, we still need to preprocess it. And on the other hand, we're shoehorning JavaScript into environments it is decidedly not designed for - it is indeed seen as a panacea.

Rebuilding web frontends on a new language obviously isn't going to happen, but sometimes the vast sea of superset languages and frameworks with their own syntactic quirks does make me wonder what the web would look like if Netscape had run on Python or Lua instead... Well, that's a dark thought, nevermind.

Collapse
 
jpantunes profile image
JP Antunes • Edited

If you keep misusing a language or ignoring how it has advanced since you first worked with it 20 years ago then yeah, that would be right.

Personally it took me about 2 decades to come around and actually try to learn (modern) JS and I only did it because node.js + streams + generators + async/await + bigInt + es6 give me an easy-to-use and hard-to-get-wrong environment to work with, from cryptography to web services, and the ecosystem is filled with good modules and examples.

Thread Thread
 
190245 profile image
Dave

Many other languages have mostly the same capability, and, in my opinion are easier to use while being harder to get wrong, than JS is.

Take the situation with boolean's in JS as an example, and the fact that they can be undefined. Dead easy to get that wrong if you don't know what you're looking at. Plus, as an OO developer (mostly Java, but lots of others too), a boolean value that can have 3 states is simply bonkers - again, in my opinion.

Thread Thread
 
fjones profile image
FJones

And yet, none of the examples you list are ones I find particularly compelling. Yes, JavaScript is easy-to-use - as easy as most any scripting language. It certainly isn't hard-to-get-wrong, though.

node.js is exactly one of those environments JS wasn't designed for. It has, in many ways, combined the worst parts of Python, Java, and PHP into one, with few noticable upsides. Talk about misusing a language.
Async/await is a construct that embraces easy-to-get-wrong if anything - conventional Promises were actually better than this.
BigInt in a language where everything is a low-precision float is another matter of working around language design. Yes, almost every language faces this, but JavaScript's solution isn't unique either - much as it isn't for streams and generators.
And ES6 is indeed the point about a language evolving over 20 years: Most of ES6 is syntactical shorthands for existing functionality. JavaScript has advanced, yes, but so have other web languages. PHP 8 is still struggling from old flaws, but it, too, is a huge change from 20 years ago. Does that make PHP a good language now? Many of the flaws in language design are still there.

Mind you, I wasn't trying to hate on JS all that much. It's a flawed language like many others. I'm trying to see anything it excels at in productive use, used as an example of JS being good. Every language has its use - what is JavaScript's? Versatility, perhaps. But is that due to the language or due to the ubiquity stemming from its use in Netscape? I would argue the latter, and I would argue that a jack-of-all-trades language just opens itself up to even more misuse.
Cryptography in JS is something I'll freely admit to continue hating on, though - and that's even ignoring the constant security flaws in that ecosystem of modules.

Where Perl and PHP are the duct tape of the web, JS is the splint. It's useful, but it isn't good.

Thread Thread
 
190245 profile image
Dave

Seriously now... can you please come to work with us?

Why don't others in the industry understand? Appropriate tool for the job, that's all that matters.

Have some love, you deserve it!

Thread Thread
 
jpantunes profile image
JP Antunes • Edited

JS wasn't made for node, it was the other way around and I think that's obvious to anyone who can look at two release dates and tell which one came first. If you want to argue whether nodejs is a good platform for backend development I'm happy to engage in that discussion separately, but we'd need to talk about architecture(s) too because that's what influences my choice in tools and I suspect it's the same with you and most experienced professionals.

ES6 introduced more than just shortcuts, although those are very welcomed (imho) because I like terse code. Async/Await for example is definitely a bit more than syntactic sugar, it's a new language construct that allows devs to reason about their async code as if it was sync. Promises are great too and constructs such as Promise.all and Promise.race are really great. BigInt is a new primitive and it's not stored as a floating point (double-precision, 64 bit number) but as an object. From memory, numbers work the same way in JS, Python and Elixir, and probably every other language that implements IEEE 754.

You do touch on a pain point of the JS ecosystem, which is the reliance on modules to do very basic stuff. I don't blame the language itself as much as a combination of other factors, ie, most devs start coding in JS, therefore most code you'd see is from people with limited experience, therefore most bad code you'll see will be JS. Likewise, if most cars in Bavaria are BMWs, and there are only a few Lotus around, it's normal to see more wrecked BMWs than Lotuses, but that doesn't make it a worse car.

Now the question remains, how exactly is JS not a good language when its practical, expressive and feature rich and runs almost everywhere?

Thread Thread
 
fjones profile image
FJones

I won't rehash the arguments about the specific features (mostly because, as I said, I wasn't meaning to hate on JS too much and I'm not objecting to the features, but their uniqueness as a stand-out for particular use cases), so I'll just touch on the closing:

Practicality of JavaScript is betrayed by its legacy flaws in language design. If I'm not mistaken, the OP actually references quite a few of those. Heck, many of the points from "PHP Is A Fractal Of Bad Design" have their JS equivalent, and so the conclusion holds true as well: If I'm spending more effort on remembering the quirks, am I really using a good language?

JS is also hardly any more expressive or feature-rich than other languages. Arguably, the standard library is less feature-rich than that of most other languages, and with most of the syntax borrowed from existing languages (and shorthands becoming increasingly less verbose), that, too, betrays the strengths of JS.

That it runs everywhere is kind of my main point: Why does it run everywhere? And are those the right places for it to run? Is there any use case where it is a stand-out first choice as a language? Notably a use case where you have a choice. With language supersets like TypeScript steadily supplanting it, it isn't even the stand-out choice for web frontends anymore - and when it is used by itself, rarely without additional syntactic sugar like JSX. I can't name a use case where I'm given multiple options and would choose JS from them - even though the underlying paradigms of a prototype-based functional language should lend themselves well to that. Each use case JS is reasonably decent at has either no alternatives, or better ones. Better tools for the same job.

Thread Thread
 
jpantunes profile image
JP Antunes

JS is 25 years old iirc, it has plenty of history but why would anyone worry about the quirks instead of trying to learn it as a new language (post ES6)? Mind you that Typescript does not replace JS, it just helps some developers write type safe (at design time...) code, but it's still plain JS at runtime.

On another note, take a moment to read this sentence as if someone else wrote it: "Why does it run everywhere?.... Each use case JS is reasonably decent at has either no alternatives, or better ones. Better tools for the same job." To me this is an example of "old man yells at cloud", or are you going to argue that Netflix handling 15% of all web traffic with Node.js is a bad decision?

Collapse
 
190245 profile image
Dave

Oh how I wish I could get you sat around the table with someone at my office.

I tried to tell them why JS was no good at IPC... tried & died.

Thread Thread
 
jpantunes profile image
JP Antunes

"Take the situation with boolean's in JS as an example, and the fact that they can be undefined. "

Care to explain how a value is a Boolean if it's undefined? Do you mean to say that you can declare a variable without defining it and that's a bad thing?

Thread Thread
 
190245 profile image
Dave

Resisting the urge to poke a little fun, notice the capitalisation? JavaScript has a Boolean function just to work around the lack of type definition.

Now, I fully admit, I'm biased - I'm a self-taught developer (having started out in CSS/JS/HTML before WYSIWYG editors), and I've spent most of my career in OO languages with strict type enforcement, so I intrinsically dislike that aspect of the language.

That said, if I get a ticket at work to do something in JS, I can do. Again, appropriate tool for the job.

Now, given I was replying to a comment claiming that JS was "hard to get wrong" - from an OO developer perspective, can you see that undefined being a feature of a language just doesn't sit well? Sure, I can get over it, but unless you understand the nuances of the language, it is very is to "get it wrong" - in any language.

Thread Thread
 
jpantunes profile image
JP Antunes

Please... can you be a bit more clear?

> let a = new Boolean
undefined
> a
[Boolean: false]

First, a Boolean value is one of { true, false }. If it's undefined then it's not a boolean, but it might work as one thanks to the falsy / truthy inference. So, if you pass an undefined value into a boolean check it will evaluate as falsy which is the sane thing to do, but if you are in fact working with Booleans (the type) then you will initialise your variable appropriately. Here is a bit more info in case you want / need it: github.com/lydiahallie/javascript-...

Again, if someone writes poor code in any language, the code will be poor. If you try to write Java in JS you'll have a bad experience but that's really about knowing the tools you work with, right?

Thread Thread
 
190245 profile image
Dave

You get that the OP posted with humour, and as numerous other commentors have said, the same can be said of any language, right?

Why the need to defend JS? There's aspects of the language I don't like (and can't really avoid). There's aspects of Java I don't like (and can actively avoid. See: Optional). There's times when JS is the appropriate tool to use, so I use it. There's other times when other languages are more appropriate, and they get used.

As I originally said in reply to the OP (I think, it was a while ago), my main issue with JS is that some people see JS as a panacea. No language is a panacea, they all have down sides.

Thread Thread
 
jpantunes profile image
JP Antunes

Yeah it does seem like I'm defending JS but my intention is only to understand the actual reasons behind the complaints. IMHO it's often due to lack of knowledge, and I say that from my own experience since I used to dislike JS at a fundamental level.. until I actually decided to learn it as a new language instead of trying to "hack" Java into it.

Thread Thread
 
190245 profile image
Dave

My only complaint with JS, isn't even to do with JS.

As I originally posted in the comment on this, my complaint is the people that see JS as a panacea.

Appropriate tool, at the appropriate time, and I'm happy. Hell, my boss this morning was kicking around an idea to use scala + MLlib, my reply was "can't say I've used either enough to have any sort of opinion... give me a few days & I'll knock together a spike so we can at least explore."

Thread Thread
 
simme profile image
Simme

I'm still very curious about what you meant with undefined Booleans, though. 😅

Thread Thread
 
190245 profile image
Dave • Edited

Again, note the capitalisation.

Consider the following JS:

var someBool;
if (someBool) { console.log("true"); } else if (!someBool) { console.log("false") }
someBool = true;
if (someBool) { console.log("true"); } else if (!someBool) { console.log("false") }
someBool = false;
if (someBool) { console.log("true"); } else if (!someBool) { console.log("false") }

Now, consider that coming from a strictly typed background, the above code shows a boolean variable (not a Boolean) in 3 different states, when the very intent of booleans is a binary state.

If one is not aware of that particular nuance, it leads to frustration & wasted time. Of course, you could make the argument that if you don't understand the nuances of a language, why are you writing in it... but where's the fine line in "sufficient knowledge" there? And why would a Project Manager looking at a deadline care if you know enough or not?

I love the fact that the two people to want to discuss this point, read "boolean" as "Boolean" :D

Thread Thread
 
jpantunes profile image
JP Antunes • Edited

The only data type where the variable name and its value are correlated are symbols (or atoms, or literals depending on what the language you use calls them).

In the example you give, var someBool is no more a boolean than var cow is a bovine animal in any dynamic or statically typed language I can think of at the moment.

What the if statements are evaluating is whether or not the value type is undefined which is only very thinly related to booleans.

For reference:
developer.mozilla.org/en-US/docs/G...
developer.mozilla.org/en-US/docs/W...

Thread Thread
 
simme profile image
Simme • Edited

😅

Well, booleans can only be true or false. however, a variable named in a way that makes it seem like it should reference a boolean can, of course, be uninitialized if you allow uninitialized declarations. And I guess that's the thing; javascript by default allows you to declare uninitialized vars.

So; yes - javascript is useless at being java, c#, or any other strongly typed language, in the same way, those languages are useless at being javascript. But that's not really a fair comparison as they have traits not applicable to the other.

Thread Thread
 
190245 profile image
Dave

Nor did I say it was a fair comparison, nor did I even really say it's an issue (of any size).

But surely, you can see that - as was the intent of my reply to the other person, from an OO/strictly typed background, JavaScript is indeed very easy to get wrong. That's no different to any other language if we only have surface knowledge in them.

In other languages, such as Java, the primitive boolean datatype exists, and null exists, but a boolean can never be null, it is either true or false. Again, that's because of strict typing, and strictly typed languages simply make more sense in my head.

Does that stop me using JS? No... but you were curious, so I expanded on my comment.

Thread Thread
 
190245 profile image
Dave

I'm aware of how to use JavaScript, and do so more times than I'd like, so no need for the documents, or the defence of JS, but thanks.

Thread Thread
 
jpantunes profile image
JP Antunes • Edited

There's no way to respond to that statement productively.

Collapse
 
ozzythegiant profile image
Oziel Perez

I could basically say the same thing about Java: it's a nice programming language that has its use cases but man do I not like the ecosystem it has. So many libraries and frameworks use XML configurations and it's like, am I programming in Java or XML? Then there are frameworks or some applications where everything is overengineered. So many classes that are named AbstractHyperOmegaFactoryConverterConfigurator or some similar tongue twister that leaves you wondering what exactly it does, and all these classes are all over the place when I'm pretty sure most of the work these classes do could have been done with 90% less code.

See? Most of the times it's not a problem with the language, just some people haven't fully mastered how some things get done in a language they are not used to, but that's not to say all programming languages are perfect or anything.

Collapse
 
1e4_ profile image
Ian

You can literally write this article about any language. People always feel the need to bash a language instead of just accepting that it can be used.

Though saying that I couldn't make it through the whole article

Collapse
 
190245 profile image
Dave

I write Java (mostly) for corporate code... in a previous job, just for giggles, we actively had a competition running (monthly winner got a prize) for the longest method names that would still compile and make sense in English. I think the record was somewhere around 130chars - for a method name!

Hating the long names and lack of readability isn't really a reason to bash on any language - the same misuse can happen in all languages. But remember, the original post was (I presume), posted in humour...

Collapse
 
ozzythegiant profile image
Oziel Perez

Agreed, and that's basically my point: a lot of times people don't like certain conventions about a language or its environment and it's not really about the language itself. That or they don't have the full mastery over a programming language's mechanics so "people hate what they don't understand".

Thread Thread
 
190245 profile image
Dave

I tend to hate the people that hate what they don't understand, but maybe that's just me. :D

Collapse
 
giorgosk profile image
Giorgos Kontopoulos 👀

This is hilarious, thanks for the write-up.

Collapse
 
worldpiece profile image
Akaash Patnaik

Thanks! Glad you liked it. :)

Collapse
 
dendekky profile image
Ibrahim Adeniyi

😂😂😂

Collapse
 
nombrekeff profile image
Keff

Cool stuff, I'll be sharing this :)

Collapse
 
waylonwalker profile image
Waylon Walker

Amazing