91
cgrey
7y

'2' + 2 => '22'
'2' - 2 => 0

Js devs will understand

Comments
  • 2
    Yikes, weak typing
  • 7
    One of the things i don't like in JavaScript. In Python for example, you will get an exception if you try this, because it is strongly typed even though it's dynamic.
  • 1
    @kpenc same with Ruby. I really like that behavior. Prevents side effects
  • 4
    I can see why this is. Tho to me, this would be better and probably more consistent like this:

    2 + 2 => 4
    2 - 2 => 0
    '2' + '2' => '22'
    '2' - '2' => '' //empty string
    '2' + 2 => '22'
    '2' - 2 => '' //empty string
    2 + '2' => 4
    2 - '2' => 0

    Where whatever the first type is, the result will be of that type. This would mean that for strings, minus should be a "de-concatination" or something.

    Edit: tho of course, a type mismatch error is the Real best way to go.
  • 2
    @DLMousey I was reading the rant and the comments mildly entertained then I came across your comment and literally laughed out loud.
  • 0
    Weak typing gives me debugging nightmares
  • 4
  • 3
    I love a strongly typed language
  • 0
    @Neotelos that's beautiful, thanks for sharing xD
  • 0
    @Neotelos didn't know that one 😂 thanks for sharing
  • 0
    Wtf. And web-people say C++ sucks because of pointers ... I have types. I have the best types! JS sooo depressing! Baaaad!!!

    Ok, you could define an operator, that does the JS obstruction of logic for you ...

    std::string operator+(const std::string& a, const int b){ return a + std::to_string(b);}

    ... and all the other crazy people rules ...
  • 2
    If you are subtracting a string, you've fucked up enough you deserve that behavior.
  • 1
    @hube that happens when an old guy stays in the past. We had to learn turbo Pascal first. I hated it an frankly cared so little about it that during exams I let somebody else code the stuff for me 😁 after that we started with C and that's when I really woke up because I knew it already. I think the best languages for programming beginners are either Ruby or Python.
  • 0
    @corscheid This is waaay worse than now. Explicit is always better than implicit.
  • 0
    doesn't 'use strict' solves this thing?
Add Comment