this post was submitted on 23 Jun 2024
735 points (96.5% liked)

Programmer Humor

19813 readers
153 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
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 19 points 5 months ago* (last edited 5 months ago) (2 children)

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

[–] [email protected] 12 points 5 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 5 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 5 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 5 months ago* (last edited 5 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] 5 points 5 months ago

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