🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #314

Re: case()

#314
From: Kent Paul Dolan
Date: Tue, 14 Aug 1990 01:16
43 lines
2106 bytes
bobatk@microsoft.UUCP (Bob ATKINSON) writes:
>bilmes@icsib (Jeff Bilmes) writes:
>>krste@ICSI.Berkeley.EDU ( Krste Asanovic) writes:
>>>The C/C++ switch statement is very limited as it only allows integer
>>>expressions. 
>...
>>
>>This does not warrant
>>extending the language when you can do the semantic equivalent as
>>easily as:
>>
>>    if (exp == val1) 
>>	s1 
>>    else if (exp == val2)
>>	s2
>>    else if (exp == val3 || exp == val4 || exp == val5 || ...)
>>	s3
>>    ...
>
>By this logic, switch statements should not have been invented
>in the first place.  Clearly in C a need was felt for this syntactic
>sugar.  Krste was merely pointing out that one can argue that
>the same needs can motivate a similar extension for non-integral
>types, of which there are a significantly larger number in C++
>(that have equality operators) than in C.
>
>I guess I don't feel particularly strongly about this issue;
>I just felt the reasoning being used was flawed.

Perhaps, but there is a more important reason to leave things alone:
there are well known problems with testing equality with, explicitly,
floating point values, and an extension of the case statement, where
the test is unobvious, to allow, explicitly, floating point case
switches, would promote maintenance problems.

When the test is done with the "else if" paradigm, the use of the
equality test is explicit, obvious, and thus easier to spot as a
possible source of trouble during maintenance.

Just a thought.

Kent, the man from xanth.
<xanthian@Zorch.SF-Bay.ORG> <xanthian@well.sf.ca.us>
Technical Details
Message-ID: <1990Aug14.011655.18253@zorch.SF-Bay.ORG>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!vsi1!zorch!xanthian
References: <26842@pasteur.Berkeley.EDU> <26857@pasteur.Berkeley.EDU> <56515@microsoft.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!ucsd!swrinde!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!vsi1!zorch!xanthian
From: xanthian@zorch.SF-Bay.ORG (Kent Paul Dolan)
Newsgroups: comp.std.c++
Subject: Re: case()
Keywords: case statement
Message-ID: <1990Aug14.011655.18253@zorch.SF-Bay.ORG>
Date: 14 Aug 90 01:16:55 GMT
References: <26842@pasteur.Berkeley.EDU> <26857@pasteur.Berkeley.EDU> <56515@microsoft.UUCP>
Organization: SF Bay Public-Access Unix
Lines: 43