13

I love javascript, but sometimes it's just an incredibly stupid language, such as when undefined variables get interpreted as string literal "undefined" when concatenating strings. I like it better how, for example, PHP handles undefined values, that nulls just turn into "". Better still: typed languages, where most stupid mistakes are caught already at compilation, instead of having to spend hours to track down where that mysterious "undefined" comes from. As I said, I love javascript - because it is easy to code, flexible and forgiving in many ways. But I hate it for the exact same reason, for being such a sloppy fluffy...thing, and a bugger to debug. If javascript would be an animal, it would be a cute and cuddly cat that you instantly find adorable, but it's actually quite fat and lazy, plus its fur is littered with ticks and other bugs.

Comments
  • 4
    How about ES6 or Typescript?
    I recently started a project with Typescript using strict and i think i'll use it for future projects because of the compile-time type checking.
  • 0
    @Bimpfi I suppose I'd first need to decide which IDE to use from now on. I'm currently using Notepad++, but am not happy with it. I've had a lot of suggestions as comments to other rants, such as Sublime, Atom etc., but so far none of them has really cut it for me.
  • 3
    @TerriToniAX About the IDE, I recommend Visual Studio Code. I love coding in JS with it and they are some cool extension and built-in debug which I use all the time with NodeJS.
  • 3
    @TerriToniAX like @MrMargouillat I also can recommend VS Code for js/ts. I use it for js/ts too and love it due to MrMargouillat mentioned reasons.
  • 0
    Making undefined values into "" sounds really stupid to me. That's like super silently failing without any notification to the developer that something went wrong. No, that's not a good language feature. "undefined" at least tells you something.
  • 0
    @simeg That's one reasons why debugging in php can be such a pain. I don't hate php at all but things like that let me think twice about using it.
  • 0
    @simeg I agree that when something goes wrong, you should get to know about it. But I strongly disagree that putting the exception message inside the string would be the way to go. No the string is not undefined, but "undefined". Then it suddenly is something, a string of 9 characters. That if anything is really stupid. No, the way I think it should work is that an undefined string is an empty string, but JS should throw an exception that I as developer could see in the console, along with the line number where the exception occured. As it is now, JS actually fails silently when trying to concatenate an undefined string because it is not really undefined but "undefined". See my point?
  • 1
    @Bimpfi I agree, both PHP and Javascript are a pain to debug. This probably goes for most interpreted and loosely typed languages.
  • 1
    @TerriToniAX I don't see your point I think. But I agree, exceptions in the console would be nice. I also agree php and JS are cumbersome to debug.
  • 0
    @simeg OK, I'll try to clarify my point. Imagine the following scenario:
    var str;
    ...
    for(var key in elements)
    {
    str += elements[key]["content"];
    }
    Now, JS should throw an error when concatening str as it is undefined. But there never is an error as JS translates the undefined variable str into "undefined" which is a valid string. In other words JS tricks itself to believe everything is OK. This is the exact opposite of giving the developer useful information.
  • 0
    @TerriToniAX Yes this point I see. But I don't see how by giving an empty string is better? "undefined" at least tells you that something is undefined, with an empty string you don't know. It could be two empty strings that are being concatenated and then all of the sudden you're debugging a false-negative.
  • 1
    @simeg I still beg to differ. My point is that variables shall only be used as variables, and error messages shall be thrown as exceptions. What if a = b/0 would result in a = "division by zero"? No, that's insane. IMHO, returning exceptions as the value of variables is bad practice.
Add Comment