4 points
*

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

permalink
report
reply
3 points

Just be better lmao

permalink
report
reply
18 points
*

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

permalink
report
reply
5 points

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

permalink
report
parent
reply
11 points

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.

permalink
report
parent
reply
6 points

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())
permalink
report
parent
reply
1 point

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.

permalink
report
parent
reply
25 points

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.

permalink
report
reply
4 points

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.

permalink
report
parent
reply
4 points

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

permalink
report
parent
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 2K

    Monthly active users

  • 861

    Posts

  • 14K

    Comments