If Else format

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

    #16
    Re: Ot: opinions vs facts

    optimistx wrote on 21 sep 2008 in comp.lang.javas cript:
    Evertjan. wrote:
    >optimistx wrote on 21 sep 2008 in comp.lang.javas cript:
    ...
    >... good recommendation to use {} in ALL ifs and loops' ...
    >>
    >I do not agree with that.
    >>
    >>'about everyone' might not be correct official English, but I
    >>as a foreigner understand that meaning 'almost all'. And how many
    >>percent of all that might be? at least 51%? at least 75 %? at least
    >>90%?
    >>
    >You were on the wrong track.
    >
    Yes, I was, thanks for the correction.
    >
    If we consider everyday language expression
    >
    '...good recommendation to use {} in all ifs and loops'
    >
    we may ask :' if it is not a good recommendation, what is it? Bad?'.
    >
    http://jslint.com recommends:
    >
    --- start of quote ---
    '
    Required Blocks
    JSLint expects that if and for statements will be made with blocks
    {that is, with statements enclosed in braces}.
    >
    JavaScript allows an if to be written like this:
    >
    if (condition)
    statement;That form is known to contribute to mistakes in projects
    where
    many programmers are working on the same code. That is why JSLint
    expects the use of a block:
    >
    if (condition) {
    statements;
    >}Experience shows that this form is more resilient.'
    >
    ---end of quote ---
    The idea's or experiences of jslint do not prove anything.

    I concede it is more resilient,
    but that does not warrant a general advisory rule.

    Example:

    Not using javascript is very resilient.
    It even is a good advice in cases where html only get you as or more
    easily to the same end.
    and I believe that this IS a good recommendation and I believe most
    other writers in this newsgroup agree with that :).
    I do not attack your believes. I attack the advice with "always".
    I think it is wrong to advice such semantics.

    Example:

    I love nicely indented code,
    but there are situations it does not add to the usefullness,
    but instead is even harmfull.



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Gregor Kofler

      #17
      Re: Ot: opinions vs facts

      Evertjan. meinte:
      Example:
      >
      I love nicely indented code,
      but there are situations it does not add to the usefullness,
      but instead is even harmfull.
      Harmful? When?

      And what are the advantages of not using curly braces - apart from
      saving say 4 to 5 bytes each time they are omitted?

      Gregor


      --
      http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
      http://web.gregorkofler.com ::: meine JS-Spielwiese
      http://www.image2d.com ::: Bildagentur für den alpinen Raum

      Comment

      • Erwin Moller

        #18
        Re: Ot: opinions vs facts


        Evertjan. schreef:
        optimistx wrote on 21 sep 2008 in comp.lang.javas cript:
        >
        >Evertjan. wrote:
        >>optimistx wrote on 21 sep 2008 in comp.lang.javas cript:
        >...
        >>... good recommendation to use {} in ALL ifs and loops' ...
        >>>
        >>I do not agree with that.
        >>>
        >>>'about everyone' might not be correct official English, but I
        >>>as a foreigner understand that meaning 'almost all'. And how many
        >>>percent of all that might be? at least 51%? at least 75 %? at least
        >>>90%?
        >>You were on the wrong track.
        >Yes, I was, thanks for the correction.
        >>
        >If we consider everyday language expression
        >>
        >'...good recommendation to use {} in all ifs and loops'
        >>
        >we may ask :' if it is not a good recommendation, what is it? Bad?'.
        >>
        >http://jslint.com recommends:
        >>
        >--- start of quote ---
        >'
        >Required Blocks
        >JSLint expects that if and for statements will be made with blocks
        >{that is, with statements enclosed in braces}.
        >>
        >JavaScript allows an if to be written like this:
        >>
        >if (condition)
        > statement;That form is known to contribute to mistakes in projects
        > where
        >many programmers are working on the same code. That is why JSLint
        >expects the use of a block:
        >>
        >if (condition) {
        > statements;
        >}Experience shows that this form is more resilient.'
        >>
        >---end of quote ---
        >
        The idea's or experiences of jslint do not prove anything.
        >
        I concede it is more resilient,
        but that does not warrant a general advisory rule.
        >
        Example:
        >
        Not using javascript is very resilient.
        It even is a good advice in cases where html only get you as or more
        easily to the same end.
        >
        >and I believe that this IS a good recommendation and I believe most
        >other writers in this newsgroup agree with that :).
        >
        I do not attack your believes. I attack the advice with "always".
        I think it is wrong to advice such semantics.
        >
        Example:
        >
        I love nicely indented code,
        but there are situations it does not add to the usefullness,
        but instead is even harmfull.
        >
        Oh come on, this is a nondiscussion.

        I'll settle it for you, once and for all ;-)

        1) Always use {} for all your logical block (if/then/else, foreach, etc)
        2) Always end a command with semicolon ;

        That way your code is understandable (syntaxwise) for any other programmer.

        IMHO it is a designmistake that {} and ; are allowed to be omitted in
        certain situations.

        Erwin Moller

        --
        =============== =============
        Erwin Moller
        Now dropping all postings from googlegroups.
        Why? http://improve-usenet.org/
        =============== =============

        Comment

        • beegee

          #19
          Re: Ot: opinions vs facts

          On Sep 22, 7:56 am, Erwin Moller
          <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
          I'll settle it for you, once and for all ;-)
          >
          1) Always use {} for all your logical block (if/then/else, foreach, etc)
          2) Always end a command with semicolon ;
          >
          That way your code is understandable (syntaxwise) for any other programmer.
          >
          IMHO it is a designmistake that {} and ; are allowed to be omitted in
          certain situations.

          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.

          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,fun ction etc. or on the next line?

          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.


          Bob

          Comment

          • Henry

            #20
            Re: Ot: opinions vs facts

            On Sep 22, 2:34 pm, beegee wrote:
            <snip>
            if (blah) {
            >
            }
            >
            or
            >
            if (blah)
            {
            >
            }
            >
            The readability of the second case is considered superior,
            <snip>

            Not universally. Personally I find the first more readable.

            I would want to see any instance on one or the other (and/or the other
            variations) accompanied by some genuine (peer reviewed) research into
            their relative readabilities. Otherwise it is just personal opinion.

            (I also _always_ put braces around if/else, with, while, do and for
            blocks regardless of whether they are strictly required.)

            Comment

            • Thomas 'PointedEars' Lahn

              #21
              Re: Ot: opinions vs facts

              beegee wrote:
              On Sep 22, 7:56 am, Erwin Moller
              <Since_humans_r ead_this_I_am_s pammed_too_m... @spamyourself.c omwrote:
              >I'll settle it for you, once and for all ;-)
              >>
              >1) Always use {} for all your logical block (if/then/else, foreach, etc)
              >2) Always end a command with semicolon ;
              >>
              >That way your code is understandable (syntaxwise) for any other programmer.
              >>
              >IMHO it is a designmistake that {} and ; are allowed to be omitted in
              >certain situations.
              >
              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,fun ction 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
              --
              realism: HTML 4.01 Strict
              evangelism: XHTML 1.0 Strict
              madness: XHTML 1.1 as application/xhtml+xml
              -- Bjoern Hoehrmann

              Comment

              • beegee

                #22
                Re: Ot: opinions vs facts

                On Sep 22, 1:00 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                wrote:
                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

                Comment

                Working...