Code snippets on Microsoft website shown in form of images.
21–30 of 58 posts
Re: Code snippets on Microsoft website shown in form of images.
#22More importantly, that is some of the nastiest looking JavaScript I've seen in a while. I think MS are doing everyone a favour.
I am learning javascript nowadays. Can you describe, what is wrong with this javascript? So that, I won't learn any bad practice.
The formatting is non-existant. That makes me angry. Because I have OCD. Most programmers do.
There's a lot of direct use of DOM traversing, which makes the code rather brittle. (Use a css selector for binding to the DOM - jQuery is the de-facto standard tool here).
Variables are not encoded in the URL. And when it is, it happens on a separate line from where it's used. That's just bad style.
Oh, and what's the point of those declared-but-unused variables (`spanish, german, english`).
And why aren't they in a hashmap?
Re: Code snippets on Microsoft website shown in form of images.
#23Earlier quoted context omitted.
I am learning javascript nowadays. Can you describe, what is wrong with this javascript? So that, I won't learn any bad practice.
When the code was adjusted to fit on the website they lost a lot of the formatting, and severely hurt the readability of the code. It appears that the lines of code were rather long, but were word-wrapped to fit within the size of that image, creating linebreaks at unexpected places. The first and last lines of the block open and close curly braces, but the rest of the code is not indented. Readability is something y…
So true.
Re: Code snippets on Microsoft website shown in form of images.
#24More importantly, that is some of the nastiest looking JavaScript I've seen in a while. I think MS are doing everyone a favour.
I am learning javascript nowadays. Can you describe, what is wrong with this javascript? So that, I won't learn any bad practice.
Variable declarations and assignments happen on multiple lines in the 2nd snippet instead of all being defined at once.
var currentLanguage = "en";
var spanish = "es";
var german = "de";
var english = "en";
vs var currentLanguage = "en", spanish = "es", german = "de", english = "en";
Additionally, "en" is assigned twice. If you're going to take the time to assign the "en" abbreviation into the "english" variable, then you should use it when assigning to "currentLanguage", in my opinion, if only to avoid typos and redundancy. var spanish = "es", german = "de", english = "en", currentLanguage = english;
The "disclaimer" element is accessed using the documentGetElementById DOM call twice. javascript is getting faster, but forcing multiple DOM calls when it's not necessary is bad practice. Ideally, you'd access it once and save it into a reference. document.getElementById("disclaimer").firstChild.nodeValue = response;
var text = encodeURIComponent(document.getElementById("disclaimer").firstChild.nodeValue);
vs var disclaimer = document.getElementById("disclaimer"), text = disclaimer.firstChild.nodeValue;
disclaimer.firstChild.nodeValue = response;
The code formatting is poor and inconsistent, notice an incorrect space after "encodeURIComponent (", but no spaces after "getElementById(" and "getElementsByTagName(". Also notice no indentation anywhere, or line-breaks after the function signatures and opening brackets "{";The code is polluting the global namespace by not being enclosed in its own namespace or perhaps an immediately executed anonymous function.
I'm sure more seasoned JS devs can list some more things wrong with the code, but those are the ones that stood out to me.
Re: Code snippets on Microsoft website shown in form of images.
#25Or, does Google Translate etc. handle this and not attempt to 'translate' code?
Re: Code snippets on Microsoft website shown in form of images.
#26Earlier quoted context omitted.
I am learning javascript nowadays. Can you describe, what is wrong with this javascript? So that, I won't learn any bad practice.
Just a few quick observations: The formatting is non-existant. That makes me angry. Because I have OCD. Most programmers do. There's a lot of direct use of DOM traversing, which makes the code rather brittle. (Use a css selector for binding to the DOM - jQuery is the de-facto standard tool here). Variables are not encoded in the URL. And when it is, it happens on a separate line from where it's used. That's just bad…
I assume you mean fake, self-diagnosed OCD, then.
Re: Code snippets on Microsoft website shown in form of images.
#27Re: Code snippets on Microsoft website shown in form of images.
#28I would like to see how long it stays that way ... people make mistakes, but if you are on the front page of HN for a wrong reason, you leave everything aside and fix it.
Re: Code snippets on Microsoft website shown in form of images.
#29Re: Code snippets on Microsoft website shown in form of images.
#30On the plus side having to manually type all of it will help developers learn it better.