If Else format

T

Thomas 'PointedEars' Lahn

beegee said:
Yes, I agree completely. Unfortunately, at my shop, we have tons on
ASP pages ('mixin' of server-side VBScript and client-side JScript)
where not one semicolon can be found.

Non sequitur. ASP is an (IIS-based) application framework that supports
both VBScript and JScript, among other programming languages. In VBScript,
a semicolon is a syntax error, and there are no braces.
However, now that we've decided that {} should always be used, we need
to decide where. Should the opening curly bracket be on the same line
as the conditional,function etc. or on the next line?

A matter of taste and teamwork.
if (blah) {
}

or

if (blah)
{
}

The readability of the second case is considered superior, however in
some cases it can cause program errors. As Crockford points out in
"Javascript: The Good Parts",

return
{
status: true
};

returns undefined, whereas

return {
status: true
};

returns true.

You (and Douglas) would need to recognize the difference between a block
statement and an Object initializer; here, the latter is meant (else it
would be a syntax error). Writing the braces for the former on their own
line always, and for the latter not, helps to see that difference. This is
also how I recommend to make the difference between function statements and
function expressions:

function foo()
{
// ...
}

but

var bar = function baz() {
// ...
};

foobar(
/x/,
function baz() {
// ...
});


HTH

PointedEars
 
B

beegee

Non sequitur.  ASP is an (IIS-based) application framework that supports
both VBScript and JScript, among other programming languages.  In VBScript,
a semicolon is a syntax error, and there are no braces.

Could have sworn I implied that if not actually said that.
...Writing the braces for the former on their own
line always, and for the latter not, helps to see that difference.  This is
also how I recommend to make the difference between function statements and
function expressions:

  function foo()
  {
    // ...
  }

but

  var bar = function baz() {
    // ...
  };

  foobar(
    /x/,
    function baz() {
      // ...
    });


Good suggestion. Thanks.

Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,139
Messages
2,570,805
Members
47,351
Latest member
LolaD32479

Latest Threads

Top