this post was submitted on 23 Jun 2024
732 points (96.4% liked)

Programmer Humor

23507 readers
1763 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
[–] [email protected] 4 points 11 months ago* (last edited 11 months ago)

I'm in this no-experience-to-apprenticeship program and everyone in my class thinks type coercion is the greatest thing ever.

[–] [email protected] 4 points 11 months ago

Just be better lmao

[–] [email protected] 0 points 11 months ago
[–] [email protected] 19 points 11 months ago* (last edited 11 months ago) (2 children)

Who would use that kind of type coercion? Who? I want to see his face.

[–] [email protected] 5 points 11 months ago

It's not even the coercion that is the problem here. The types are already bad by themselves.

[–] [email protected] 12 points 11 months ago (1 children)

I take this as less of a "I can't use this intuitive feature reliably" thing and more of a "the truth table will bite you in the ass when you least expect it and/or make a mistake" thing.

[–] [email protected] 6 points 11 months ago (1 children)

Just use a formatter. It'll show you that the second one is two statements:

  1. {} (the empty block)
  2. +[] coerce an empty array to a number: new Number(new Array())
[–] [email protected] 1 points 11 months ago (1 children)

I totally get that: use the right tools and you'll be okay. This applies to many technologies in this space.

With respect, I still take this advice like hearing "look out for rattlesnakes if you're hiking there." It might be safer to just hike where there are no rattlesnakes, instead.

[–] [email protected] 1 points 11 months ago* (last edited 11 months ago)

You're right, of you have compete freedom, do that. If the place you want or need to go to is most comfortably reachable via rattlesnake road, bring boots.

In other words, if you don't think the wasm landscape is mature enough to build a web thing with it, you are stuck with JavaScript, but you don't have to rawdog it. I haven't run in a single weird thing like this in years of writing typescript with the help of its type system, ESLint and a formatter.

[–] [email protected] 25 points 11 months ago (2 children)

This is why I try my damnedest not to write in weakly typed languages.

string + object makes no logical sense, but the language will be like "'no biggie, you probably meant string + string so let's convert the object to string"! And so all hell breaks loose when the language's assumption is wrong.

[–] [email protected] 4 points 11 months ago

Some automatic conversion is fine.

a=3+0.2

print("Hello {name}. You are {age} years old")

That kind of thing. But the principle of least surprise definitely applies. If you get to the point where you're adding two booleans and a string, I feel like the language should at least say something. At least until the technology exists for it to physically reach out of your screen and slap you.

[–] [email protected] 4 points 11 months ago

You don't necessarily need types for that kind of thing though, a strict linter that flags that code works just as well

[–] [email protected] 15 points 11 months ago* (last edited 11 months ago) (1 children)
{} + 0
>> 0

0 + {}
>> "0[object Object]"

I'm going home.

[–] [email protected] 3 points 11 months ago
0 == []
>> true

"0" == []
>> false

0 == "0"
>> true
[–] [email protected] 20 points 11 months ago* (last edited 11 months ago) (2 children)

It's best not to touch anything web related, lest you want to go mad. It's like the elder scrolls or laying eyes on some cosmic horror creature. Tbf this also goes for C++

[–] [email protected] 3 points 11 months ago* (last edited 11 months ago) (1 children)

At least C++ build tools are easier than modern JS.

[–] [email protected] 6 points 11 months ago

I don't think "easier" is the right way to compare here. The C++ build tools will absolutely rewrite your code into something you can't expect to guess, but it doesn't make them hard to "use".

[–] [email protected] 2 points 11 months ago

Keep to sane environments to keep sane.

load more comments
view more: next ›