904
The birth of JS (lemmy.world)
top 21 comments
sorted by: hot top new old
[-] nxfsi@lemmy.world 37 points 3 years ago

The tech equivalent of inventing leaded gasoline.

[-] devious@lemmy.world 37 points 3 years ago

This is one of the most educational and entertaining reads on the internet, if you are into that kind of thing:

https://github.com/denysdovhan/wtfjs

[-] rikudou@lemmings.world 29 points 3 years ago

Has anyone actually read through that? Reading the first few examples and it's just not understanding how languages work half of the time:

!!"false" == !!"true"; // -> true
!!"false" === !!"true"; // -> true

Wow, no shit, non-empty string coerces to true, who would've guessed! Did you know that !!"bullshit" === !!"true" as well? Mind=blown.

NaN === NaN; // -> false

Again, no shit, that's in the NaN specification and the page even mentions it, so why even include it?

[-] noli@programming.dev 20 points 3 years ago

Which is why I'm of the opinion that dynamically typed languages are evil. !!"false" should either be caught at compile time or raise an exception.

I'm thoroughly convinced that the only use of dynamically typed languages is to introduce bugs

[-] Camilo@discuss.tchncs.de 7 points 3 years ago

I am with you. To me these are non-obvious details, just a bug waiting to silently happen in production.

[-] rikudou@lemmings.world 1 points 3 years ago

Why? IMO that's perfectly valid. The various type coercions are sometimes crazy, but IMO the rule that non-empty string is coerced to true and empty string to false is very simple to follow. The snippet is not even a gotcha, I don't see anything worth failing over. Putting "true" or "false" in a string doesn't change that.

[-] noli@programming.dev 4 points 3 years ago* (last edited 3 years ago)

I am dumb. The more things I need to think about when reading code that is not the logic of the code, the worse it is. Any time I have to spend thinking about the peculiarities of the way the language handles something is time wasted.

I'll give a very simple example, think like you're trying to find a bug. Assume we're in a dynamic language that allows implicit conversion like this. We can write our code very "cleanly" as follows:

if(!someVar) doSomething();

-> ok, now we gotta check where someVar's value is last set to know what type of data this is. Then I need to remember or look up how those specific types are coerced into a bool.

When trying the same code in a statically typed language that doesn't do implicit coercion that code will fail to run/compile so probably you'll have something like this:

if(someVar.length() == 0) doSomething();

-> this time I can just look at the type of someVar to see it's a string and it's clear what the condition actually means.

The second option is both easier to read and less bug prone even without the type system. It takes maybe 3 seconds longer to type, but if your productivity in coding is that limited by typing speed then I envy you

[-] darcy@sh.itjust.works 4 points 3 years ago

NaN===NaN is the fault of the floating point standard tho i believe.

[-] rikudou@lemmings.world 6 points 3 years ago

Yes, that's my point.

[-] icesentry@programming.dev 1 points 3 years ago

Also, a huge proportion of the list is just not understanding IEEE floats behaviour and blaming the language for it. Exactly like this post is doing. All those weird number things js does is because it only uses floats for everything and every language that uses floats will behave the exact same way.

[-] MonkderZweite@feddit.ch 1 points 3 years ago

So, uh, first example, the developer decided instead of comparing based on type, he rather converts the values? Why?!

[-] AbsolutelyNotCats@lemdro.id 36 points 3 years ago* (last edited 3 years ago)

Just a reminder that JavaScript was developed in 10 days, the same amount of time i spend fixing bugs when i just miss a ","

[-] SnipingNinja@slrpnk.net 14 points 3 years ago* (last edited 3 years ago)

The world was made in 7 days, so it should have been 3 days left to develop js

[-] AbsolutelyNotCats@lemdro.id 7 points 3 years ago

This sounds more credible than the big bang theory. I no longer believe in science

[-] dukk@programming.dev 8 points 3 years ago

Physics was written in JavaScript?

…checks out.

[-] MentalEdge@sopuli.xyz 22 points 3 years ago

Ah. The shork did the math. This explains a lot.

[-] DanielCF@discuss.tchncs.de 21 points 3 years ago

You just have to look at the problem from a different angle.

[-] Cocoa6790@kbin.social 8 points 3 years ago

Not enough alcohol involved.

[-] MonkderZweite@feddit.ch 6 points 3 years ago
[-] FehrIsFair@lemmy.world 9 points 3 years ago

This image is fan art of Gawr Gura from Hololive EN's 1st Gen VTuber group HoloMyth.

She is their most subscribed talent and is known for being computationally challenged.

[-] tun@lemm.ee 1 points 3 years ago

Approach the problem from different angle!

this post was submitted on 07 Sep 2023
904 points (99.0% liked)

Programmer Humor

33049 readers
822 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 3 years ago
MODERATORS