Loading ...
Sorry, an error occurred while loading the content.
 

[jslint] Re: continue

Expand Messages
  • sandyhead25
    ... Break is not evil. It forces early return from a loop, which results in a value for the iterator that is neither the start or end value of the loop. That
    Message 1 of 28 , Jun 20, 2009
      --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
      >
      > Since everyone asked, here is my personal Scale of Evil Control Structures, from most to least:
      >
      > goto -- so evil, you probably shouldn't even use a language that has it.
      > break, continue -- mmm, kinda evil. If you have a very, very good reason, use it. Once.
      > return -- OK, if you're right at the top of the function and you have to quit early because of bad parameters or bad state or something
      > while -- Fine, just be careful of infinite loops.
      > if -- Good
      > for -- Better than while, maybe a little clunky
      > each -- Good (not the JS foreach, which is a little broken, but JQuery-style each or Java's iterated for)
      > function -- Perfect
      >

      Break is not evil. It forces early return from a loop, which results in a value for the iterator that is neither the start or end value of the loop. That is useful for making decisions about positions of points in a group. This sort of logic is necessary.

      Return forces and early return from a function. This not only increases efficency by warding off undesired execution, but also impacts the values of closures. That sort of logic is very similar to the example mentioned above and is absolutely necessary.

      To solve everybody else's whining with regard to understandability versus indentation proper code should be broken into as many small functions as possible to eliminate restatement. This sort of design is vital for taking advantage of simplistic unit testing. That sort of design also eliminates confusion with regard to condition complexity.
    • Randall Lee Spence
      ... I am sure that if this topic is debated long enough, almost every statement or method will have someone calling it evil or declaring its use as counter
      Message 2 of 28 , Jun 20, 2009
        --- In jslint_com@yahoogroups.com, "sandyhead25" <austin.cheney@...> wrote:
        >
        > --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@> wrote:
        > >
        > > Since everyone asked, here is my personal Scale of Evil Control Structures, from most to least:
        > >
        > > goto -- so evil, you probably shouldn't even use a language that has it.
        > > break, continue -- mmm, kinda evil. If you have a very, very good reason, use it. Once.
        > > return -- OK, if you're right at the top of the function and you have to quit early because of bad parameters or bad state or something
        > > while -- Fine, just be careful of infinite loops.
        > > if -- Good
        > > for -- Better than while, maybe a little clunky
        > > each -- Good (not the JS foreach, which is a little broken, but JQuery-style each or Java's iterated for)
        > > function -- Perfect
        > >
        >
        > Break is not evil. It forces early return from a loop, which results in a value for the iterator that is neither the start or end value of the loop. That is useful for making decisions about positions of points in a group. This sort of logic is necessary.
        >
        > Return forces and early return from a function. This not only increases efficency by warding off undesired execution, but also impacts the values of closures. That sort of logic is very similar to the example mentioned above and is absolutely necessary.
        >
        > To solve everybody else's whining with regard to understandability versus indentation proper code should be broken into as many small functions as possible to eliminate restatement. This sort of design is vital for taking advantage of simplistic unit testing. That sort of design also eliminates confusion with regard to condition complexity.
        >

        I am sure that if this topic is debated long enough, almost every
        statement or method will have someone calling it evil or declaring
        its use as counter intuitive. But at what point do we stop? If we
        warn about breaks, returns, continues and switches, what's to stop us
        from eliminating for loops and if statements since they can also be
        misused and abused? Eventually we will be left with only empty
        function statements, and I am sure someone would have a perfectly
        valid complaint about that.

        I supposed it would be much easier to write JavaScript if that were
        the case:

        var doNothing = function () {
        //Success!;
        }

        Randall
      • jeddahbill
        ... Good one, Randall! Dittos!
        Message 3 of 28 , Jun 20, 2009
          --- In jslint_com@yahoogroups.com, "Randall Lee Spence" <analogueweb@...> wrote:
          >
          > --- In jslint_com@yahoogroups.com, "sandyhead25" <austin.cheney@> wrote:
          > >
          > > --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@> wrote:
          > > >
          > > > Since everyone asked, here is my personal Scale of Evil Control Structures, from most to least:
          > > >
          > > > goto -- so evil, you probably shouldn't even use a language that has it.
          > > > break, continue -- mmm, kinda evil. If you have a very, very good reason, use it. Once.
          > > > return -- OK, if you're right at the top of the function and you have to quit early because of bad parameters or bad state or something
          > > > while -- Fine, just be careful of infinite loops.
          > > > if -- Good
          > > > for -- Better than while, maybe a little clunky
          > > > each -- Good (not the JS foreach, which is a little broken, but JQuery-style each or Java's iterated for)
          > > > function -- Perfect
          > > >
          > >
          > > Break is not evil. It forces early return from a loop, which results in a value for the iterator that is neither the start or end value of the loop. That is useful for making decisions about positions of points in a group. This sort of logic is necessary.
          > >
          > > Return forces and early return from a function. This not only increases efficency by warding off undesired execution, but also impacts the values of closures. That sort of logic is very similar to the example mentioned above and is absolutely necessary.
          > >
          > > To solve everybody else's whining with regard to understandability versus indentation proper code should be broken into as many small functions as possible to eliminate restatement. This sort of design is vital for taking advantage of simplistic unit testing. That sort of design also eliminates confusion with regard to condition complexity.
          > >
          >
          > I am sure that if this topic is debated long enough, almost every
          > statement or method will have someone calling it evil or declaring
          > its use as counter intuitive. But at what point do we stop? If we
          > warn about breaks, returns, continues and switches, what's to stop us
          > from eliminating for loops and if statements since they can also be
          > misused and abused? Eventually we will be left with only empty
          > function statements, and I am sure someone would have a perfectly
          > valid complaint about that.
          >
          > I supposed it would be much easier to write JavaScript if that were
          > the case:
          >
          > var doNothing = function () {
          > //Success!;
          > }
          >
          > Randall
          >
          Good one, Randall! Dittos!
        • Jean-Charles Meyrignac
          ... You forgot while , which can be replaced by for. ... Sorry, but it doesn t pass JsLint: Problem at line 3 character 2: Missing semicolon. JC
          Message 4 of 28 , Jun 20, 2009
            On Sat, Jun 20, 2009 at 10:47 PM, Randall Lee Spence wrote:
            >
            > But at what point do we stop? If we
            > warn about breaks, returns, continues and switches, what's to stop us
            > from eliminating for loops and if statements since they can also be
            > misused and abused?

            You forgot 'while', which can be replaced by for.

            > I supposed it would be much easier to write JavaScript if that were
            > the case:
            >
            > var doNothing = function () {
            > //Success!;
            > }
            >
            Sorry, but it doesn't pass JsLint:
            Problem at line 3 character 2: Missing semicolon.

            JC
          • Michael Lorton
            ... How is that a good one? Yes, nothing on this earth is perfectly good and few things are perfectly evil, but we still have the daily task of figuring out
            Message 5 of 28 , Jun 20, 2009
              >> I am sure that if this topic is debated long enough, almost every
              >> statement or method will have someone calling it evil or declaring
              >> its use as counter intuitive. But at what point do we stop? If we
              >> warn about breaks, returns, continues and switches, what's to stop us
              >> from eliminating for loops and if statements since they can also be
              >> misused and abused? Eventually we will be left with only empty
              >> function statements, and I am sure someone would have a perfectly
              >> valid complaint about that.
              >>
              >> I supposed it would be much easier to write JavaScript if that were
              >> the case:
              >>
              >> var doNothing = function () {
              >> //Success!;
              >> }
              >>
              >> Randall
              >>
              >Good one, Randall! Dittos!

              How is that a good one? Yes, nothing on this earth is perfectly good and few things are perfectly evil, but we still have the daily task of figuring out what to do, and reductionist sarcasm like "well, anything can be misused" doesn't help at all.

              > Jean-Charles Meyrignac <jcmeyrignac@gm...> writes:

              > Sorry, but it doesn't pass JsLint:
              > Problem at line 3 character 2: Missing semicolon.

              Now *that* is a good one.

              M.

              [Non-text portions of this message have been removed]
            • Randall Lee Spence
              ... I agree Michael, that was a good one! Reductionist sarcasm aside, I d like to state again that I do agree with JSLint throwing a warning on continue, I
              Message 6 of 28 , Jun 20, 2009
                --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
                >
                > >> I am sure that if this topic is debated long enough, almost every
                > >> statement or method will have someone calling it evil or declaring
                > >> its use as counter intuitive. But at what point do we stop? If we
                > >> warn about breaks, returns, continues and switches, what's to stop us
                > >> from eliminating for loops and if statements since they can also be
                > >> misused and abused? Eventually we will be left with only empty
                > >> function statements, and I am sure someone would have a perfectly
                > >> valid complaint about that.
                > >>
                > >> I supposed it would be much easier to write JavaScript if that were
                > >> the case:
                > >>
                > >> var doNothing = function () {
                > >> //Success!;
                > >> }
                > >>
                > >> Randall
                > >>
                > >Good one, Randall! Dittos!
                >
                > How is that a good one? Yes, nothing on this earth is perfectly good and few things are perfectly evil, but we still have the daily task of figuring out what to do, and reductionist sarcasm like "well, anything can be misused" doesn't help at all.
                >
                > > Jean-Charles Meyrignac <jcmeyrignac@gm...> writes:
                >
                > > Sorry, but it doesn't pass JsLint:
                > > Problem at line 3 character 2: Missing semicolon.
                >
                > Now *that* is a good one.
                >
                > M.
                >
                > [Non-text portions of this message have been removed]
                >

                I agree Michael, that was a good one!

                Reductionist sarcasm aside, I'd like to state again that I do agree
                with JSLint throwing a warning on continue, I just don't agree with
                throwing a warning on break or return. Since the original post was
                about continue, and it seems as if enough people have agreed it would
                make a good addition, I suspect we will this as an option in the next
                version of JSLint.

                As I was re-reading the thread I noticed you asked if JSlint warned
                about missing breaks in switch statements, but I didn't see where
                anyone addressed that directly. You may have already found the answer
                on your own, but in case you didn't, and for the benefit of others,
                it does. JSLint expects that the statement before the next case or
                default is either a break, return or throw.

                Randall
              Your message has been successfully submitted and would be delivered to recipients shortly.