Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #9388

Re: Break for last case in switch

Message-ID <2974255.78QauJFxQc@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2011-12-19 00:06 +0100
Subject Re: Break for last case in switch
Newsgroups comp.lang.javascript
References (1 earlier) <fbidncC--v1e33PTnZ2dnUVZ8sWdnZ2d@giganews.com> <2014557.oCFFeib8bu@PointedEars.de> <f5qdnf4Rs5HfyXPTnZ2dnUVZ8v-dnZ2d@giganews.com> <3028473.Ge26DHhYnv@PointedEars.de> <4eydnfAOdKla9XPTnZ2dnUVZ8qWdnZ2d@giganews.com>
Followup-To comp.lang.javascript

Followups directed to: comp.lang.javascript

Show all headers | View raw


Stefan Weiss wrote:

> On 2011-12-18 22:29, Thomas 'PointedEars' Lahn wrote:
>> The "last case" in the original code is the `default' clause.
> 
> Of course. I don't know why you keep going on about that. There were no
> other clauses without breaks. That's why I specifically said "the last
> clause", including both "case" and "default".

"case" obviously does not mean for JavaScriptLint what it means for you, and 
there can only be *one* last clause.  In either case, you are wrong.

>> Stefan Weiss wrote:
>>> And as expected, nothing changes when you add "break" after "y = 23".
>> What changes then is that there is no fall-through in either case.
> 
> Or in other words... nothing changes :)
> Whatever you do, a 'break' at that position cannot possibly change the
> outcome. It is, as I said, redundant.

No, look closer.  It does not change the outcome *here* because `2' cannot 
possibly be a match for the value to be found by the algorithm.

>>> Talking about code conventions... do you think it's a good idea to put
>>> 'default' clauses above 'case' clauses in switch statements?
>> 
>> Mu.  It is syntactically valid and may conveniently do what you expected
>> it to (as specified) in some cases.
> 
> First you ask me if I really expected how your switch worked (implying
> that something unusual or complicated was going on),

It is.

> and now you defend it?

No.  I have merely answered your question in a way that you had not expected 
(or comprehended yet).

> I contend that such constructs are far worse than leaving out the
> final 'break', especially if the last clause is 'default'.

There is no inherent programming problem with it if you put the `break' 
statement where needed, for then the `switch' statement is semantically 
identical.  Of course, leaving the `default' clause in-between would cause 
*maintenance* problems at little advantage *then*, and that would probably 
qualify for a bad idea.

There is no inherent problem with it if the specified behavior when omitting 
the `break' is what is *intended* (like a `finally' clause in `try-catch' 
statements).  Iff that is causing a maintenance problem, then different 
approaches need to be considered.  But it is not a bad idea in itself, and 
so does not qualify as not being a good idea either.

So yours is not a question that can be answered correctly with a simple 
"Yes" or "No"; it is a question that reveals your ignorance about the 
subject discussed.  Which is why I replied "Mu".

> If you find program flow like that "convenient", I have a Duff's device
> to sell you :)

Straw man.

-- 
When all you know is jQuery, every problem looks $(olvable).

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Break for last case in switch Archos <raul.san@sent.com> - 2011-12-18 11:04 -0800
  Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-18 20:43 +0100
    Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-18 22:13 +0200
    Re: Break for last case in switch Antony Scriven <adscriven@gmail.com> - 2011-12-18 12:21 -0800
    Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-18 21:37 +0100
      Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-18 21:58 +0100
        Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-18 22:29 +0100
          Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-18 23:49 +0200
          Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-18 23:09 +0100
            Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-19 00:32 +0200
          Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-18 23:25 +0100
            Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-19 00:06 +0100
              Re: Break for last case in switch Stefan Weiss <krewecherl@gmail.com> - 2011-12-19 05:30 +0100
                Re: Break for last case in switch Andrew Poulos <ap_prog@hotmail.com> - 2011-12-19 16:04 +1100
                Re: Break for last case in switch Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-12-19 12:25 +0100
                Re: Break for last case in switch "Evertjan." <exjxw.hannivoort@interxnl.net> - 2011-12-19 17:17 +0000
                Re: Break for last case in switch Gene Wirchenko <genew@ocis.net> - 2011-12-19 12:19 -0800
                Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-19 14:47 +0200
                Re: Break for last case in switch John G Harris <john@nospam.demon.co.uk> - 2011-12-19 15:50 +0000
                Re: Break for last case in switch "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-12-19 18:45 +0200
                Re: Break for last case in switch Gene Wirchenko <genew@ocis.net> - 2011-12-19 12:22 -0800

csiph-web