Today's rant: JavaScript's type system.

I realized halfway through that I can't happily call JavaScript a "programming language" so just assume
alias programming="scripting"

I'm sure it's not actually as frustrating as it seems to me. Thing is, I'm used to either statically-typed languages or dynamically-typed languages that actually make sense. If I were to try to add an integer to something I'd forgotten was a string in Python, it'd immediately tell me "look, buddy, do you want me to treat this as a concatenation or an addition? I have no idea the way you've got this written." I've found that mistakes are a common thing with dynamic typing. Maybe I'm just not experienced enough yet, maybe it's really as stupid as it looks. JavaScript just goes "hey look I'm gonna tack all of these guys together and make a weird franken-string like '$NaN34.$&' because that's absolutely what we want here!" Then I run my webpage and instead of a nice numeric total like I wanted, good old JavaScript just went "Yep, I have no idea what I'm doing here I'm just gonna drop this here and pretend it's right." Now absolutely I do not expect my programming language to make correct assumptions and read my mind, otherwise JavaScript would be programming me and not the other way around. But it could at least let me know that I had incompatible types going on rather than just shamelessly going along with what it's doing. Good GRIEF, man, some of the idiosyncrasies of the EMCAScript language definition itself just make me want to punch a horse.

  • 5
    I feel your pain. I was so happy when my boss finally accepted my proposal to use TypeScript. It's far from perfect, but at least some types are being checked and it has much better autocompletion in IDEs.
  • 4
    One word: Typescript
  • 2
    I hate it when people complain that you can't concatenate a string and an integer in Python. There's not much point in it, and it's the only way a dynamically typed language can really work.
  • 2
    @TheInitializer Exactly and I hate that JavaScript just lets you do it.
  • 0
    If you add a number to a string, that's on you. Java will automatically concatenate too, and if you don't keep track of what is in each variable, that's on you. Adding to a string is concatenation. Accept it and expect it
  • 1
    You know what you can do in Python that is harder to run in js? Variable mistyping.

    Example in Python:
    carpet = JavaScript
    #### tons of carpet code
    car = Java # doesn't flag as uninitialized/defined variable cause there is no distinction between declaration syntax and reinitialization
Add Comment