|
Sander Rossel wrote: Yeah, but this was really like one tool showing "abc" while another showed "123"
That is interesting and painful. Very similar to my problem.
|
|
|
|
|
Mostly painful
|
|
|
|
|
Oh no my friend, it gets far worse than that A GUID is simply an 128 bit number in 5 chunks of 32-16-16-16-48. GUIDs like {0C2D39CD-F486-435B-BDBA-64A124D04D31} are when the first chunk of 32 bits is converted into hex, then the next chunk and so on, but when you use some dumb-ass third-party system that stores the bytes in a different order *cough*mongodb*cough* then the string representation of the same data can look different in two different systems despite being equal. I know this is more of a UUID issue than a GUID one, but it shows the kind of nightmares you come across when you stray from the Microsoft path.
|
|
|
|
|
Quote: when you stray from the Microsoft path Stay on the path! Mirkwoodicrosoft has many hidden dangers!
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
+1 for the {4C 4F 54 52} reference
|
|
|
|
|
F-ES Sitecore wrote: A GUID is simply an 128 bit number in 5 chunks of 32-16-16-16-48. GUIDs like {0C2D39CD-F486-435B-BDBA-64A124D04D31} are when the first chunk of 32 bits is converted into hex, then the next chunk and so on, but when you use some dumb-ass third-party system that stores the bytes in a different order *cough*mongodb*cough* then the string representation of the same data can look different in two different systems despite being equal.
Oh that is really terrible. You'd think they'd mention Big-Endian v. Little-Endian or some such.
|
|
|
|
|
Sander Rossel wrote: different ways to look at a GUID Yes, there are "case-sensitive" Guids. I guess it was project ids in a Visual Studio solution file...
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
A good reason to ALWAYS add your own abstraction layer on top of ANY API that you use.
It is a lot easier to do it up front then try to retrofit it later.
This keeps your dependencies well documented as well.
String jsonSiteKeys = MyLib.json.toJson(allSiteKeys);
Or maybe better
String jsonSiteKeys = MyLib.toJson(allSiteKeys);
|
|
|
|
|
The bigger issue is that the difference in encoding doesn't make any difference.
According to the JSON standard this encoding is valid and will make no difference to the deserialization operation. In fact, all the characters could be encoded in this way, and it should still work.
Mike...
|
|
|
|
|
As if you need another reason.
But here is a good one that maybe you've seen before.
var extra = null;
extra += 'a' + 'b' + 'c';
extra += "abc";
var numberTest = null;
numberTest += 55 + 33 + 38;
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!!!
Really a PEBKAC error but still quite annoying.
|
|
|
|
|
raddevus wrote: I guess it pre-decides that it's a string so it figures it should convert the null object to the null string.
Nope - it "decides" when it executes the addition operator.
JavaScript Addition Operator in Details[^]
If one operand is a string , the other is converted to a string and the values are concatenated. String(null) === "null"
Otherwise, they are converted to numbers and added. Number(null) === 0
And yes, it sucks. Just be grateful it doesn't borrow VB's habit of coercing strings that look like numbers into numbers, adding them together, and then converting the result back to a string.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Nope - it "decides" when it executes the addition operator.
Thanks for the info. It's a very good point and I should've thought of it myself -- that it occurs when the concatenation is done.
|
|
|
|
|
|
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 to extra and then adding characters or integers to it?
don't you fell more natural to define extra as "" if you add strings to it or as 0 if you add integers to it?
|
|
|
|
|
sickfile wrote: didn't if bother you that you are assigning null to extra 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
null
I 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 between null and undefined .
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 as 0 , instead of null .
all i can tell you is, and i remembered well, that the logic i had to use, because the field was either an object or 0 in it's absence, was like 3 boolean expressions concatenated with || or &&. if the absence of the object was marked with null i would have to use only one boolean expression. even tho if (0) and if (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.
|
|
|
|
|
raddevus wrote: there are two values which are so similar but are different:
undefined
null
or three. Don't forget
void 0
|
|
|
|
|
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 to extra 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 as 0 if you add integers to it? Yes, either and int or string, not a var. We don't DIM.
Bastard Programmer from Hell
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.
|
|
|
|
|
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
|
|
|
|
|
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!
But it's better left to... others...
|
|
|
|
|
Super Lloyd wrote: there is an endless stream of trick trivia question that can be made with it!
Yeah, I often see those posted all over the place.
|
|
|
|
|
raddevus wrote: var extra = null;
Isn't this sort of thing why TypeScript was invented?
In TypeScript:
var extra:string;
|
|
|
|
|
markrlondon wrote: Isn't this sort of thing why TypeScript was invented?
Yes it is!
I will switch to TS one day too. I'm just so lazy I haven't gotten around to it.
|
|
|
|
|
Message Removed
modified 17-Sep-19 9:20am.
|
|
|
|
|
Message Removed
modified 17-Sep-19 9:20am.
|
|
|
|