From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,f822ae7b0f7433c1 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!news1.google.com!news.maxwell.syr.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Translating an embedded C algorithm Date: Fri, 19 Jan 2007 15:34:11 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1168871816.263502.212100@11g2000cwr.googlegroups.com> <45ace573$1_3@news.bluewin.ch> <68qioe.mes.ln@hunter.axlog.fr> <1168963927.396654.169380@s34g2000cwa.googlegroups.com> <11e7vht8gdl0z$.2dypcyr85i3w.dlg@40tude.net> <147rcq0tjavdf.lzroutxxh59k$.dlg@40tude.net> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pcls4.std.com 1169238851 945 192.74.137.71 (19 Jan 2007 20:34:11 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Fri, 19 Jan 2007 20:34:11 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:lw92kOpskkKr1O9kBJOvzFIl4Cc= Xref: g2news2.google.com comp.lang.ada:8349 Date: 2007-01-19T15:34:11-05:00 List-Id: Bj�rn Persson writes: > Maciej Sobczak wrote: > >> Bj�rn Persson wrote: >> >>>> C has case statements as well. >>> >>> The switch statement is utterly broken (so to speak). I prefer not to use >>> it. I suppose my code contains slightly more "==" because of this. >> >> What have you gained? Is your code more readable? Easier for maintenance? > > I get rid of the risk of forgetting a break, so my code is hopefully less > buggy. > > I feel that the risk that I'll forget a break is greater than the risk that > I'll make an assignment instead of a comparison. If you feel the other way, > maybe you'll choose to use the switch statement. A switch statement in C is really just a computed goto. Google for "duff's device" for an "interesting" example. (No relation, by the way.) I agree that "forgetting break" is an issue. But the much bigger issue is that Ada case statements have full-coverage rules, checked at compile time. That's one of my favorite features of Ada. - Bob