52
etrock
5y

JavaScript 🤣

Comments
  • 8
    The fact that someone performs math operations with strings and numbers (and expects sensible results) is arguably more silly than some of JavaScript's quirky behaviours.
  • 5
    Just use the long plus operator.

    "11" -+- 1 => 12
  • 3
    don't forget kids:

    0 == "0"

    0 == []

    but

    [] != "0"
  • 6
    @kamen the fact that javascript is not staticaly typed allows passing strings to math functions by mistake. In the end you might post data to the backend as a urlParam where in no way you will be able to determine whether it's a string or not, and you will have a fucked up database entry and undef behaviour.

    How do you find where in the process the math didn't work as expected? You don't. You stall that ticket as long as you can because it means looong debugging hours. Esp if that calc function is called from many places, and only one of them is passing a string. And if client does not know steps to repro the bug - it's even more stalling! Meanwhile your db records keep on getting fucked up.
  • 3
    @netikras That's why I'd advise against using bare JavaScript (unless you're doing something very small). Using TypeScript (or at least a linter or Flow for bare JavaScript) seems like a much more sensible approach.
  • 3
    @amatrelan It's the same thing as double -. Additional + has no effect in a chain of addition/subtraction ops as long as parser doesn't get confused. With -- it gets confused because it's a decrement operator, similarly -++- contains an increment operator, so you need an extra space inbetween. -+- is unambiguous and fun because it looks like a long plus =)
  • 0
    This is C++:

    void (*(*f[])())();

    This way I define an "f" variable as an array of unspecified size which contains pointers to functions that return void.

    Now have fun with C++
  • 1
    @Manjia But in this case it's perfectly logical!
    Couldn't say the same about js.
  • 0
    @gronostaj uhm, where did you find it? I think that I had invented it, and I had also written a post on DevRant😂
  • 1
    @netikras void (*(*f[])())() is nonsense bullshit,

    this is (quite) the same thing in a language that makes sense (eg C#):

    List<Action> f = new List<Action>();

    And this is it in JavaScript:

    f = [];

    JavaScript: too versatile to be understood.. :(
  • 0
    @Manjia that is an array of procedures, i.E. a list of items that can be called to change some state.

    Ofc you could implement it with structs to be more readable but imo that mash of pointers still makes perfect sense.
  • 2
    I love JavaScript.

    ((r/roastme))
  • 0
    @netikras Is there really any developer who still uses structs in 2019? Why not punched cards then? They are a development pattern quite as modern as structs are
  • 0
    @Manjia my bad.. I didn't notice the ++es
  • 0
    @netikras Yeah it seems I'm pretty new to development, that's why I've got a pretty objective point of view
  • 2
    @Manjia I meant ++es next to the C 😁 as in C one does not have classes to use as data structures
  • 1
    @Manjia Almost everyone uses classes as a struct replacement. A class with properties, getters and setters only is nothing but a fancy struct.
  • 1
    @netikras I totally misunderstood, my fault actually.. XD
  • 0
    @gronostaj Yeah I meant that
Add Comment