YARTH-JS : Yet Another Reason To Hate JavaScript
-
if you learn the rules of coercion you may love the language. it's nothing ambiguous. you will become more expressive, but your expressions may look like gibberish to people coming from more strict languages. on the other hand if you too are used to stricter language, didn't if bother you that you are assigning
null
toextra
and then adding characters or integers to it? don't you fell more natural to defineextra
as""
if you add strings to it or as0
if you add integers to it?sickfile wrote:
didn't if bother you that you are assigning
null
toextra
and then adding characters or integers to it?That's actually a good point and good thinking. I actually do like JavaScript, I just find that I get bit by these things and there are a lot of esoteric things to know about the language that cause my brain to burn more calories than I probably should have to. But that is the natural laziness that all we devs have I suppose. The real thing that bothers me about JavaScript is the fact that there are two values which are so similar but are different:
undefined
nullI could just use one or the other really. But then I become unusre at times and think, "hmm...is JS going to think this is undefined at this point? Is it going to think it is null?" then additionally in the case of a string I have to wonder if it is an empty string too (and there is no String.Empty to compare to so I have to use double-quotes ""). These are the things that are just bothersome. But they are bothersome because I cannot concentrate on JavaScript as much as I'd like too, since I'm an attempting to create solutions in software -- not just understand pedantic syntax. I think that is why at times, I finally just have to rant about JS. :)
-
sickfile wrote:
didn't if bother you that you are assigning
null
toextra
and then adding characters or integers to it?That's actually a good point and good thinking. I actually do like JavaScript, I just find that I get bit by these things and there are a lot of esoteric things to know about the language that cause my brain to burn more calories than I probably should have to. But that is the natural laziness that all we devs have I suppose. The real thing that bothers me about JavaScript is the fact that there are two values which are so similar but are different:
undefined
nullI could just use one or the other really. But then I become unusre at times and think, "hmm...is JS going to think this is undefined at this point? Is it going to think it is null?" then additionally in the case of a string I have to wonder if it is an empty string too (and there is no String.Empty to compare to so I have to use double-quotes ""). These are the things that are just bothersome. But they are bothersome because I cannot concentrate on JavaScript as much as I'd like too, since I'm an attempting to create solutions in software -- not just understand pedantic syntax. I think that is why at times, I finally just have to rant about JS. :)
that's ok, we all rant here and there.
null
is an object. it has it's purposes. it just takes time to make a significant difference betweennull
andundefined
. not so long ago i have stumbled upon a situation at work where a coworker had decided to write the absence of an object in the database simply as0
, instead ofnull
. all i can tell you is, and i remembered well, that the logic i had to use, because the field was either an object or0
in it's absence, was like 3 boolean expressions concatenated with || or &&. if the absence of the object was marked withnull
i would have to use only one boolean expression. even thoif (0)
andif (null)
yield the same result. there are many articles on the net that explain the differences between:0, "", undefined, null,
... etc. and the subject can be sometimes so confusing that you would have to go through the comments of the article to figure it out and i'm talking about the best articles out there. no good text will only confuse a person. -
sickfile wrote:
didn't if bother you that you are assigning
null
toextra
and then adding characters or integers to it?That's actually a good point and good thinking. I actually do like JavaScript, I just find that I get bit by these things and there are a lot of esoteric things to know about the language that cause my brain to burn more calories than I probably should have to. But that is the natural laziness that all we devs have I suppose. The real thing that bothers me about JavaScript is the fact that there are two values which are so similar but are different:
undefined
nullI could just use one or the other really. But then I become unusre at times and think, "hmm...is JS going to think this is undefined at this point? Is it going to think it is null?" then additionally in the case of a string I have to wonder if it is an empty string too (and there is no String.Empty to compare to so I have to use double-quotes ""). These are the things that are just bothersome. But they are bothersome because I cannot concentrate on JavaScript as much as I'd like too, since I'm an attempting to create solutions in software -- not just understand pedantic syntax. I think that is why at times, I finally just have to rant about JS. :)
hey, i remember bookmarking your Practical Electronics For Makers articles just a few days ago. nice work!
-
sickfile wrote:
didn't if bother you that you are assigning
null
toextra
and then adding characters or integers to it?That's actually a good point and good thinking. I actually do like JavaScript, I just find that I get bit by these things and there are a lot of esoteric things to know about the language that cause my brain to burn more calories than I probably should have to. But that is the natural laziness that all we devs have I suppose. The real thing that bothers me about JavaScript is the fact that there are two values which are so similar but are different:
undefined
nullI could just use one or the other really. But then I become unusre at times and think, "hmm...is JS going to think this is undefined at this point? Is it going to think it is null?" then additionally in the case of a string I have to wonder if it is an empty string too (and there is no String.Empty to compare to so I have to use double-quotes ""). These are the things that are just bothersome. But they are bothersome because I cannot concentrate on JavaScript as much as I'd like too, since I'm an attempting to create solutions in software -- not just understand pedantic syntax. I think that is why at times, I finally just have to rant about JS. :)
-
if you learn the rules of coercion you may love the language. it's nothing ambiguous. you will become more expressive, but your expressions may look like gibberish to people coming from more strict languages. on the other hand if you too are used to stricter language, didn't if bother you that you are assigning
null
toextra
and then adding characters or integers to it? don't you fell more natural to defineextra
as""
if you add strings to it or as0
if you add integers to it?sickfile wrote:
you will become more expressive, but your expressions may look like gibberish to people coming from more strict languages.
Which makes stuff easy for maintenance, ofcourse.
sickfile wrote:
on the other hand if you too are used to stricter language, didn't if bother you that you are assigning
null
toextra
and then adding characters or integers to it?No, it would result in a compiler error.
sickfile wrote:
don't you fell more natural to define
extra
as""
if you add strings to it or as0
if you add integers to it?Yes, either and int or string, not a var. We don't DIM.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
-
As if you need another reason. :rolleyes: But here is a good one that maybe you've seen before.
var extra = null; // feeling like you are initializing a var for later use.
// ## Now, try either of the following lines
extra += 'a' + 'b' + 'c';
extra += "abc";// Guess what the value of extra is??? G'head and guess.
// Yes it is "nullabc" What!?!// But try it with a number
var numberTest = null; // feeling like you are initializing a var for later use.
numberTest += 55 + 33 + 38;
//Guess what the value is?
// Yep, 126X| Here's a snapshot (via imgur) of the FireFox dev console[^] in case you find it difficult to believe. I've been using JS for quite some time and try to stay up on these types of things but this one bit me today. Really quite annoying. I guess it pre-decides that it's a string so it figures it should convert the null object to the null string. I'm so glad it does that!!! X| X| :mad::mad: Really a PEBKAC error but still quite annoying.
Type coercion in JS has long been a known area of difficulty. However, if you learn it's peculiar rules, you may start to appreciate the method to the madness :)
"There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." - C.A.R. Hoare Home | LinkedIn | Google+ | Twitter
-
As if you need another reason. :rolleyes: But here is a good one that maybe you've seen before.
var extra = null; // feeling like you are initializing a var for later use.
// ## Now, try either of the following lines
extra += 'a' + 'b' + 'c';
extra += "abc";// Guess what the value of extra is??? G'head and guess.
// Yes it is "nullabc" What!?!// But try it with a number
var numberTest = null; // feeling like you are initializing a var for later use.
numberTest += 55 + 33 + 38;
//Guess what the value is?
// Yep, 126X| Here's a snapshot (via imgur) of the FireFox dev console[^] in case you find it difficult to believe. I've been using JS for quite some time and try to stay up on these types of things but this one bit me today. Really quite annoying. I guess it pre-decides that it's a string so it figures it should convert the null object to the null string. I'm so glad it does that!!! X| X| :mad::mad: Really a PEBKAC error but still quite annoying.
Good to know! :) The good thing with JavaScript is that there is an endless stream of trick trivia question that can be made with it! :laugh: But it's better left to... others... :O
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Good to know! :) The good thing with JavaScript is that there is an endless stream of trick trivia question that can be made with it! :laugh: But it's better left to... others... :O
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
As if you need another reason. :rolleyes: But here is a good one that maybe you've seen before.
var extra = null; // feeling like you are initializing a var for later use.
// ## Now, try either of the following lines
extra += 'a' + 'b' + 'c';
extra += "abc";// Guess what the value of extra is??? G'head and guess.
// Yes it is "nullabc" What!?!// But try it with a number
var numberTest = null; // feeling like you are initializing a var for later use.
numberTest += 55 + 33 + 38;
//Guess what the value is?
// Yep, 126X| Here's a snapshot (via imgur) of the FireFox dev console[^] in case you find it difficult to believe. I've been using JS for quite some time and try to stay up on these types of things but this one bit me today. Really quite annoying. I guess it pre-decides that it's a string so it figures it should convert the null object to the null string. I'm so glad it does that!!! X| X| :mad::mad: Really a PEBKAC error but still quite annoying.
raddevus wrote:
var extra = null; // feeling like you are initializing a var for later use.
Isn't this sort of thing why TypeScript was invented? ;-) In TypeScript:
var extra:string;
-
raddevus wrote:
var extra = null; // feeling like you are initializing a var for later use.
Isn't this sort of thing why TypeScript was invented? ;-) In TypeScript:
var extra:string;