View Single Post
Old 05-20-2009, 09:27 AM   #13 (permalink)
kmote
 

Join Date: Jul 2005

Location: England

Posts: 2,198

kmote has a spectacular aura aboutkmote has a spectacular aura about

Default Re: the tricky business of programming

Quote:
Originally Posted by oldskool View Post
^ If you are using a compiler. For Javascript you can use Notepad, and some people do. Javascript doesn't get compiled, like the other languages mentioned. The browser "renders" it, but Javascript doesn't get compiled. It is not a stand-alone application, just code used within HTML in the form of a script.

^^ Yes the moral of the thread is be careful, but don't let it end like that. I was just trying to think of some obvious mistakes.



^ Yes that would be an error, if you try to say:

If (someVariable = someOtherVariable) {
// the code here wouldn't work if, if "someVariable were equal
//to 5 and someOtherVariable = 5 as well.
}

That is because the code is NOT COMPARING the two values. It is trying to make
someVariable receive the value of someOtherVariable, not compare the two.
What would be needed in this case would be the == .

So you are wrong, Soulphire. Sorry. Unless you can show me what you mean, with an example.
What soulphire is saying (and he is right) is that
Code:
if (something = another)
is not a syntax error, put that into a compiler and it will be fine (which is what makes it is so tricky). If the compiler produced an error as in the case of a syntax mistake eg. a missing '}' or ';' then it wouldn't be such a problem.
Interestingly enough, according to standards (note that I have not read the standard myself to verify this) javascript does not require semicolons though they are considered good practice. And while you are right to note that javascript is an interpreted language and as such is not compiled, you can usually set the browser to pop up with an error if there is a problem.

EDIT: if anyone wants an example of why this isn't a syntax error (although arguably it should be) then I would be more than happy
__________________
MSI P43 Neo|Enermax Pro82+ 425W|E5200|silent 8500GT|250GB Samsung spinpoint F1|Samsung SATA DVD RW|4GB Corsair|Antec SOLO|openSUSE11


There are in order of increasing severity: lies, darn lies, statistics, and computer benchmarks. - diskinfo man page

Last edited by kmote; 05-20-2009 at 09:34 AM.
kmote is offline   Reply With Quote