ECMAScript syntax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe Kelsey

    ECMAScript syntax

    Does the "semicolon insertion" really affect you if you format code as

    function x (y)
    {
    // ...
    }

    instead of:

    function x (y) {
    // ...
    }

    The jslint page complains about lines ending in ) due to the nebulous
    idea of "semicolon insertion". I have not reviewed the ECMAScript pdf
    in great detail to try to pin this pretty-printing issue down. In
    general, I find that code formatted in the "K&R" style (opening brace
    on same line as if, while, function) confusing and difficult to read
    compared with placing curly braces on separate lines.

    On another subject, the difference between inner functions defined
    explicitly versus defined using function expressions seems like a good
    one for a FAQ. Under what circumstances does it make a real
    difference whether you use function expression versus function
    statement versus Function object?

    /Joe
  • Douglas Crockford

    #2
    Re: ECMAScript syntax

    > Does the "semicolon insertion" really affect you if you format code as[color=blue]
    >
    > function x (y)
    > {
    > // ...
    > }
    >
    > instead of:
    >
    > function x (y) {
    > // ...
    > }
    >
    > The jslint page complains about lines ending in ) due to the nebulous
    > idea of "semicolon insertion". I have not reviewed the ECMAScript pdf
    > in great detail to try to pin this pretty-printing issue down. In
    > general, I find that code formatted in the "K&R" style (opening brace
    > on same line as if, while, function) confusing and difficult to read
    > compared with placing curly braces on separate lines.[/color]

    I like to avoid insecurities in languages. I prefer to work where the ice is
    thickest. Since I am the one who wrote jslint, that's what it likes, too. But it
    has a checkbox that you can clear that turns off that check.

    Legibility is of paramount importance. If you find the K&R convention difficult
    to read, then don't use it. One of the deficiencies of the C family is that
    there is no ideal way to make them pretty. I think that should be an important
    consideration in the design of syntax, but clearly I am not with the mainstream
    on this.



    Comment

    Working...