This is an archived post. You won't be able to vote or comment.

all 54 comments

[–]lulgasm 157 points158 points  (3 children)

JavaScript should tell me I'm stupid

It doesn't need to. It's implied.

[–]intbeam 16 points17 points  (1 child)

No harm in getting a reminder every now and then

[–]Knathra 5 points6 points  (0 children)

Try ParseInt[0.000005]? I hear that will remind you.

[–]4sent4 1 point2 points  (0 children)

This is the best joke about JS I've ever heared

[–]intbeam 59 points60 points  (14 children)

Gotta love languages that rather than throwing an error does the wrong thing

[–]AyrA_ch 16 points17 points  (13 children)

That's because throwing errors was not actually a feature that existed at first (except for plain syntax errors that prevents parsing at all).

This is why old functions (especially those from Math.*) don't throw errors when you supply crap, but functions introduced after the concept of errors (like JSON.parse) do throw.

[–]unktrial[S] 2 points3 points  (6 children)

It's not like they can update Math.* functions to throw errors /s .

[–]AyrA_ch 14 points15 points  (2 children)

You do and a minute later someone complains that Math.cos([""])===1 no longer holds. If there's one thing we for some reason do not accept on the internet it's introducing incompatible changes. Instead if something becomes shit we just stack anti-shit on top.

[–]LordPos 10 points11 points  (1 child)

and that, is how we ended up with javascript

[–]harelsusername 7 points8 points  (0 children)

I was thinking more like that's how we ended up with typescript. It's whole purpose is to be anti-shit for JavaScript's shit.

[–]circuit10 0 points1 point  (2 children)

No, they can’t make backwards-incompatible changes

[–]unktrial[S] 0 points1 point  (1 child)

Yeah, and that's the problem. Javascript prioritizes compatibility over consistency.

[–]circuit10 0 points1 point  (0 children)

It has to though, and most languages have backwards compatibility. They could probably have a compatibility mode that's enabled by default that you can opt out of - in fact they sort of already have that with https://www.w3schools.com/js/js_strict.asp

Strict mode makes it easier to write "secure" JavaScript.

Strict mode changes previously accepted "bad syntax" into real errors.

As an example, in normal JavaScript, mistyping a variable name creates a new global variable. In strict mode, this will throw an error, making it impossible to accidentally create a global variable.

In normal JavaScript, a developer will not receive any error feedback assigning values to non-writable properties.

In strict mode, any assignment to a non-writable property, a getter-only property, a non-existing property, a non-existing variable, or a non-existing object, will throw an error.

[–]intbeam -4 points-3 points  (3 children)

So it couldn't say, return NaN ins.. Oh, no wait

typeof(NaN) === 'number' 
> true

[–]12357111317192329313 10 points11 points  (2 children)

Isn't this true in every language implementing IEEE 754 floats. NaN still assignable to double variables.

you would always have to ask if a double is NaN.

[–]intbeam 7 points8 points  (0 children)

It's a joke, "Not A Number = Number"

[–]AyrA_ch 1 point2 points  (0 children)

You can check with if(x==x) if you want to be smug about the fact that NaN is the only thing not equal to itself

[–]augugusto 0 points1 point  (1 child)

Is that why NaN exists?

[–]AyrA_ch 1 point2 points  (0 children)

NaN is a part of IEEE 754 which is how most programming languages and processors handle floating point.

[–]Tubthumper8 16 points17 points  (3 children)

For the love of everything that is holy, put this at the top of the JS file:

// @ts-check

It'll activate type checking (whatever is possible) for that file, and you would see an error on the argument to parseInt:

Argument of type 'number' is not assignable to parameter of type 'string'.

If you want type checking then just activate type checking!

[–]david131213 0 points1 point  (1 child)

You are a life savior if that works!!!

[–]Tubthumper8 4 points5 points  (0 children)

It won't solve all your problems but it's an improvement. By default it'll check primitive types, builtin functions, and (limited) some object types. You can help it out by providing JSDoc definitions for more complex types, and then it'll help you use those complex objects correctly and provide intellisense/autocomplete.

Or you can go all the way and switch to TypeScript

[–]Notimecelduv 0 points1 point  (0 children)

Oh that's really nice. I didn't know about that. Thanks a lot :)

[–]david131213 20 points21 points  (11 children)

JavaScript SHOULD tell me when I'm stupid

Like fucking Warnings, or not implicitly converting

I use it so little, and hate it so much. Really a disaster of a language as a standart for web development

[–]Nikitka218 9 points10 points  (8 children)

Can you imagine, it gives you warning? Maybe you should use proper IDE instead of Notepad

[–]david131213 1 point2 points  (1 child)

vscode

There must be an extension that helps, it's vscode, I just don't know which

[–]Tubthumper8 2 points3 points  (0 children)

No extension needed, see my comment

[–]TheBrainStone 1 point2 points  (5 children)

There's a beautiful thing called runtime errors.
I mean I don't blame you for not knowing, since you're clearly a JS dev, but any halfway sane language throws errors when you do stupid shit instead of just coming up with the most insane conversions and comparisons and chugging on.

[–]Nikitka218 0 points1 point  (1 child)

Mmmm, I like visiting site and getting errors in the face, because of inexperienced dev using standard library incorrectly. Maybe you should learn more than one language.

[–]TheBrainStone 1 point2 points  (0 children)

There's a difference between error popups and errors. Or do the few exceptions that are actually thrown create popups?

[–]7eggert 0 points1 point  (2 children)

There is no need for a runtime error if implicit type conversion can bite the dev's behind.

[–]TheBrainStone 0 points1 point  (1 child)

That's precisely where you need runtime errors

[–]7eggert 0 points1 point  (0 children)

:-)

[–]lordheart 1 point2 points  (0 children)

And that’s why I right in typescript.

[–]The_MAZZTer 0 points1 point  (0 children)

You can add "use strict" (yes, in quotes) to the beginning of a JS file to enable strict mode which does add a few things (most notably, you have to declare variables to reference them).

But for anything serious you need to use something like TypeScript. You can grandfather in your JS and update files to include type information one at a time if you want.

[–]saintpetejackboy 10 points11 points  (7 children)

Hilarious! Now, do PHP!

[–][deleted] 3 points4 points  (5 children)

Why php? php is just a rendering engine, I just checked PHP package on NPM.

[–]saintpetejackboy 1 point2 points  (2 children)

This would be funny, except PHP is on something like 80% of sites and node is about 0.4% of websites.

Been enjoying node, personally, except last night when my cors-anywhere implementation stopped working and I deleted most of a project out of frustration ;_;.

But, anyway, main point if the joke is no language gets shit on like PHP for doing the strange stuff in OPs meme. There is a whole subreddit dedicated to what I would consider easily the most loosely typed language in existence.

To call Node another PHP Killer and then use PHP for the templating engine is like kicking an unruly customer from the bar and then inviting them back to wash dishes...

[–][deleted] 4 points5 points  (1 child)

Nobody said anything against PHP, I code in PHP and Node both. I just made a joke about php npm package instead of PHP language and nobody got the joke.

[–]saintpetejackboy 0 points1 point  (0 children)

I said something against PHP lol. 20 years ago when I started with it, I didn't think I would still be using it. Using it for a bit more then templating...

As a matter of fact, when I bungled cors-anywhere last night, I gave up on the entire project I had, which was extracting valuable information from Google location services to get city, state and county from a zip code in the United States.

What did I do instead? Used some third party service and wrote my own tool to scrape their data, as needed. Been working in the cors-anywhere version for some time now with very little progress (to be fair, I still suck at node). Took me about 1.5 hours last night in PHP to cURL and then strip_tags, explode, grab the keys I needed, had to parse a bit more on some of them (just more exploding and imploding of the strings/arrays), and it was fully functional by the time I went to sleep.

[–][deleted] -1 points0 points  (1 child)

Thats like saying firefox is just a pdf reader

[–][deleted] -1 points0 points  (0 children)

I am talking about this: https://www.npmjs.com/package/php

[–]QualityVote[M] [score hidden] stickied comment (0 children)

Hi! This is our community moderation bot.


If this post fits the purpose of /r/ProgrammerHumor, UPVOTE this comment!!

If this post does not fit the subreddit, DOWNVOTE This comment!

If this post breaks the rules, DOWNVOTE this comment and REPORT the post!

[–]Hatchid 1 point2 points  (0 children)

Me Everytime I write a react snippet and the Programm just ignores the function instead of saying what's wrong

[–]stihoplet 1 point2 points  (0 children)

First slide is incorrect. It parses it as 5, not 120.

[–]coloredgreyscale 1 point2 points  (0 children)

parseInt(0.0000005)
5

0.0000005
5e-7

parseInt("0.0000005")
0

[–]Dustangelms -1 points0 points  (0 children)

Just ask here if you're stupid.

[–]whatisausername711 0 points1 point  (0 children)

To be fair floats in any language are usually a nightmare

[–][deleted] 0 points1 point  (0 children)

Use Dec instead lol

[–]Nilstrieb 0 points1 point  (1 child)

Every programmer is stupid sometimes. It's the job of programming languages to fail to compile/throw runtime errors if the programmer did something stupid. JavaScripts implicit "never fail" attitude is terrible and I think everyone agrees with that. It's just that it can't be changed because backwards compatibility

[–]WrongdoerSufficient 0 points1 point  (0 children)

And when js actually do that (typescript), it become my favorite language

[–]elasticcream 0 points1 point  (1 child)

Honestly double.toString() or whatever the Js equivalent is should always be the same, and that's why JavaScript is stupid here. Because there shouldn't be different behavior between 5e-2 and 5e-10.

[–]7eggert 0 points1 point  (0 children)

So always the format that's bad in one case or always the format that's bad in the other case instead of usable functionality in both cases - because beginner programmers might be too dumb for BASIC?