this post was submitted on 27 Dec 2023
723 points (98.7% liked)

Programmer Humor

24736 readers
1960 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 2 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] guy@lemmy.world 70 points 2 years ago (2 children)

== is a heathen with no rightful place except equality to null. All praise ===

[–] cmdrkeen@programming.dev 35 points 2 years ago

That’s what I used to think but it turns out to be the most Christian operator there is.

[–] match@pawb.social 25 points 2 years ago (1 children)

Eval works in mysterious ways

[–] ADTJ@feddit.uk 7 points 2 years ago

I Object to your terrible pun

[–] sbv@sh.itjust.works 29 points 2 years ago (3 children)
[–] Limitless_screaming@kbin.social 18 points 2 years ago* (last edited 2 years ago) (4 children)

that's not "t", it's "\t" which is just a tab. There's also "\n" for newline.

[–] Sonotsugipaa@lemmy.dbzer0.com 20 points 2 years ago (1 children)

It still makes no sense though

[–] Limitless_screaming@kbin.social 22 points 2 years ago (1 children)

If " " wasn't equal to 0, it wouldn't make sense, but since a string containing a space equals 0, you'd expect the same to apply to a string containing a tab or a newline. (or at least I'd expect that)

[–] FaceDeer@kbin.social 5 points 2 years ago (1 children)

I admit I have never dabbled in javascript, despite being a proficient programmer. I now dread to ask... would any string that contains only whitespace == 0? " \t\n \t " for example?

[–] Limitless_screaming@kbin.social 7 points 2 years ago (4 children)

Yes, it would. Just like a string of spaces " " == 0, but it isn't that bad; === is Javascript's version of == in other languages, and, thus, you should be using it if you don't want that wonkiness.

== is just for convenience, like when you want to make sure that the user didn't leave the form empty and the button shouldn't be greyed out, and other UI stuff. Without these kinds of features JS wouldn't be used in so many toolkits.

load more comments (4 replies)
[–] sbv@sh.itjust.works 10 points 2 years ago (3 children)

It's a slash-t in the comment. Maybe kbin has different rendering rules for comments?

load more comments (3 replies)
[–] MinekPo1@lemmygrad.ml 2 points 2 years ago (3 children)

yeah but why is a single character string containing a tab equal to zero ???

[–] Limitless_screaming@kbin.social 2 points 2 years ago* (last edited 2 years ago)

That would be weird if a string containing a space wasn't equal to 0 " " == 0, but that's not the case in JS. If you think that "" and " " being equal to 0 is weird then I agree, but since they are, you should expect "\t" and "\n" to equal 0 too.

load more comments (2 replies)
load more comments (1 replies)
[–] jtk@lemmy.sdf.org 8 points 2 years ago

Yeah, it's true. I knew all the other ones, had to put that one in the dev tools console to believe it. I was just happy to know === continues to be sane in that comparison.

[–] Blackmist@feddit.uk 5 points 2 years ago

You have to remember that the underlying principle of JavaScript seemed to be "never throw an error", even if what it's being told to do is weapons grade bollocks.

[–] TrickDacy@lemmy.world 25 points 2 years ago (1 children)

Are people really not using the strict equality operator?

[–] BatmanAoD@programming.dev 7 points 2 years ago (8 children)

It's still pretty bad that the normal equality operator is as bad as it is.

load more comments (8 replies)
[–] uid0gid0@lemmy.world 18 points 2 years ago

Violating the transitive property? Go home JavaScript, you're drunk.

[–] Thcdenton@lemmy.world 18 points 2 years ago

Fuck this language with a pineapple

[–] mindbleach@sh.itjust.works 18 points 2 years ago

"The trinity makes as much sense as Javascript" is a vulgar condemnation of Christian dogma.

[–] kamen@lemmy.world 16 points 2 years ago (1 children)

Lots of silliness indeed, yet I can't remember the last time I had to use a non-strict comparison.

[–] CanadaPlus@futurology.today 12 points 2 years ago

Yes, it's been established that you can still use JavaScript, and it will only backfire sometimes, even though it's a bad language. And yet, people try to use it where it's not even required.

[–] tiny_electron@sh.itjust.works 11 points 2 years ago

This never gets old lmao

[–] tacosplease@lemmy.world 10 points 2 years ago

As a person who is coding adjacent (I work with basic SQL and VBA, once learned but never used HTML & CSS, learned some C+, some JavaScript...) I don't fully understand most of the memes here, but it feels like I'm learning a bit through immersion like being a non-native speaker in a foreign land. It's a fun ride.

[–] zqwzzle@lemmy.ca 6 points 2 years ago* (last edited 2 years ago) (2 children)

=== is just == with extra steps

[–] thanks_shakey_snake@lemmy.ca 23 points 2 years ago

It's actually the other way around. == has to perform type coercions as part of its equality algorithm, whereas === does not, so == has more steps.

load more comments (1 replies)
[–] ilovesatan@lemmy.world 5 points 2 years ago

Gonna show this to my Discrete math professor

[–] Bye@lemmy.world 5 points 2 years ago (4 children)

I don’t work with web stuff, why is js so weird? Can you write a website in other languages, like c# or python?

[–] fiah@discuss.tchncs.de 23 points 2 years ago (2 children)

Can you write a website in other languages, like c# or python?

sure, as long as it compiles to javascript

[–] Bye@lemmy.world 7 points 2 years ago (5 children)

But the browser can’t handle other languages? That seems a bit silly

[–] pankkake@lemmy.world 17 points 2 years ago (1 children)

There's a push towards WebAssembly. Officially it's not supported yet, but most browsers can handle it. I don't know how mature the project is though.

But yeah, essentially everything on the web is JS.

[–] Static_Rocket@lemmy.world 15 points 2 years ago (4 children)

Even webassembly needs a JS stub loader right now. I still can't believe that's a requirement.

[–] Ephera@lemmy.ml 3 points 2 years ago (1 children)

Sure, but you can get frameworks that generate that for you. I've written whole webpages in WASM without writing any JS.

You don't get around reading JS documentation, though. Especially the DOM API is just documented as JS, and you basically hope that your framework makes it obvious enough how to write that in your non-JS language of choice.

[–] Static_Rocket@lemmy.world 5 points 2 years ago (1 children)

This is exactly the reason why I can't believe that was ever a requirement. I would have crazy respect for webassembly if it could stand on it's own as it would allow people to completely move away from JS, but if JS is still in the stack in any way it will introduce a (even if it is minimal) compatibility and maintenance cost in the long run.

[–] Ephera@lemmy.ml 3 points 2 years ago

I used to think so, too, but on the one hand, the DOM API is absolutely massive. Going through the standardization, implementation and documentation process another time would take decades.

And on the other hand, a language-agnostic API in WebAssembly would mean specifying it WebAssembly itself. And well, it's Assembly-like, so what's currently a single line for calling a JS function would turn into tens of lines of low-level code.

Ultimately, you'd want code from some other high-level language to give you a summary of how you may need to call your language-specific wrapper. In practice, that's likely even worse than translating it from JS, because the high-level call isn't standardized.

load more comments (3 replies)
[–] Anafabula@discuss.tchncs.de 5 points 2 years ago

If they could, JavaScript wouldn't be nearly a popular

[–] Ephera@lemmy.ml 3 points 2 years ago

There's actually in theory all the pieces in place to use a different scripting language, because in the early days, there really were multiple. But yeah, the massive DOM API is only really standardized+implemented+documented for JS, so you don't get around it in the end.

As the others said, though, WebAssembly is starting to become a thing and the JS boilerplate for calling the DOM API can be generated for you.

[–] mindbleach@sh.itjust.works 3 points 2 years ago

When you see the entire world agree to one standard about anything, leave it the fuck alone.

load more comments (1 replies)
[–] thanks_shakey_snake@lemmy.ca 7 points 2 years ago (1 children)

Most of the weirdness comes from being designed for the web, and specifically for working with forms. The value of a form field will always be a string, which is a simple and straightforward idea, but then the trouble showed up when we tried to make it more convenient to work that way.

[–] cmdrkeen@programming.dev 17 points 2 years ago (2 children)

Actually, most of the weirdness comes from having been originally designed in a matter of 10 days by a single engineer working to accommodate a tight release schedule.

[–] thanks_shakey_snake@lemmy.ca 2 points 2 years ago (1 children)

I mean, do you think that has more explanatory power though? The type coercion rules are actually more elaborate with == than necessary for equality checking, because it was intended as a clever convenience for working with strings. If it was really all about the short timeline, wouldn't you just skip that and do a more straightforward equality comparison, like the algorithm that === implements?

Besides, it's not like everything in the language was conceived and implemented in those 10 days. The language has been evolving steadily since then. I'm not even sure if the modern == comparison algorithm worked that way in the first iteration.

Personally, I find it more useful to understand the context that lets me say "that's a quirky consequence of a sensible principle," rather than blaming it on the "ten days" legend generically.

[–] BatmanAoD@programming.dev 2 points 2 years ago (2 children)

I think the "ten days" explanation has the merit of being charitable, because it implies that Brendan Eich wouldn't have made such short-sighted design choices under more favorable circumstances.

(I do not believe that it's a "sensible principle" to treat text as such a fundamental form of data that a basic language feature like the equality operator should be entirely shaped around it. Surely the consequences of building an entire language around text manipulation should be apparent by considering how awkward Posix-style shells are for any nontrivial scripts.)

load more comments (2 replies)
load more comments (1 replies)
load more comments (2 replies)
[–] Sanchokan@kbin.social 2 points 2 years ago* (last edited 2 years ago) (1 children)

A few years back I came to the conclusion that the holy trinity in Christianity are three levels of abstraction: the son => God walks on earth and tangible, the father => God in heaven untangible but still reachable by speech, holy spirit => God in who knows where.

Then I thought that as a way of imparting the thought that any level of abstraction of the universe would also be inhabitated by God, those which we can sense, and those where our senses can't reach. The idea that omniprescense is not only limited to our dimension.

I'm not sure if that is the original meaning but is a way of seeing it that I can relate to, since I've always been akeen to a more abstract idea of God, and not so much to a figure that praises itself of thought, which is a human attribute.

load more comments
view more: next ›