quote:
Originally posted by CookieRevised
But this was exactly because he did not nested the IF structure between { }. So reading and debugging made easier if you don't nest stuff? I dont think so... it's more confusing and mistakes happen more quickly, especially when you split things out on several lines. (and reading other scripting topics, such mistakes happen all the time)...
I agree it can be harder to read if you omit the braces, but what I meant was, for example, the difference between these two code blocks:
js code:
if(functionA()) {
if(functionB()) {
// do something
}
else {
// handle error b
}
}
else {
// handle error a
}
// ==========
if(!functionA()) {
// handle error a
return;
}
if(!functionB()) {
// handle error b
return;
}
// do something
It keeps everything together nicely imo, with the error handling right next to the error. Obviously it might not always be applicable, and everything is open to argument
[/off-topic]