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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!peer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!Xl.tags.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.nethere.com!news.nethere.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 20 Apr 2016 02:56:39 -0500 Newsgroups: comp.lang.ada Subject: Re: if-then-no-else Programming From: csampson@inetworld.net (Charles H. Sampson) Date: Wed, 20 Apr 2016 00:56:39 -0700 Message-ID: <1mlzbr3.1ivik7416ts9sjN%csampson@inetworld.net> References: <1mlx1gf.ebrae11jak5tyN%csampson@inetworld.net> User-Agent: MacSOUP/2.8.3 (Mac OS X version 10.5.8 (PPC)) X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-SEqnGv09crMDXO/hKAJePJwYWMSHcHudCUd3f9Ww3rbTNsuc7NxapYUBN61Yc/3slvVdiOZgtDGAXqw!13T/qZG0+llt/1PatJOKnkq5yc3LKNTfpI8q0QlN3rxQuueFQOGtha0RrFA/ymTYILJa72x6lzwq!G7jHuebsgbkR4NNJuKKFyJslG18N0Yg= X-Complaints-To: abuse@nethere.com X-DMCA-Complaints-To: abuse@nethere.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4527 X-Received-Bytes: 4639 X-Received-Body-CRC: 1511727833 Xref: news.eternal-september.org comp.lang.ada:30205 Date: 2016-04-20T00:56:39-07:00 List-Id: Randy Brukardt wrote: > "Charles H. Sampson" wrote in message > news:1mlx1gf.ebrae11jak5tyN%csampson@inetworld.net... > > It's hard to believe that it's been over six years since I wrote a line > > of code for profit. If what my son tells me, there's been what I > > consider a major change in software engineering during that time. > > > > He says that there's a move to ban the use of the else-statement. The > > preferred approach is to execute the else-part first, then change the > > effect if the if-condition is satisfied. For example: > > > > Variable := 3; > > if then > > Variable := 1; > > end if; > > > > In addition to some other goodness attributes, this is supposed to be > > clearer than the if-then-else form. > > > > Is he right? (He's not really a coder. His experience is in wire-frame > > animation but he's being forced into coding by the job market.) If he's > > not right, have any of you even heard of an area of the software > > "profession" where this position is held? > > This sounds like nonsense to me. It wouldn't make sense for the majority of > the code that we have: > > if condition then > Do_It; > else -- Can't get here. > Internal_Error ("Impossible branch"); > end if; > > and > > if Is_Float (Expr.Typ) then > Generate_Float_Code (Expr.Typ); > else > Generate_Integer_Code (Expr.Typ); > end if; > > I think if we generated both kinds of code for a float expression, we > wouldn't have been in the compiler business for long. ;-) > > Indeed, RRS has a style rule which is the exact opposite of his suggestion. > We require either an else or a comment that no else is needed for most if > statements. We found that we had cases like: > > if condition then > Do_Something; > end if; > > and there would be a bug because nothing was done if condition was False. > Errors of omission are the hardest things to find, and we hoped to reduce > the number of them by at least requiring the programmer to think about all > of the possibilities and documenting that they did so. Thus, the above would > have to be written: > > if condition then > Do_Something; > -- else nothing needed. > end if; > > so it's obvious that the reverse condition was considered. > > There are of course cases where the suggested form would work, but even in > those one needs to document that the else was omitted on purpose and not > just forgotten. Otherwise, a future maintainer has to guess which case is > involved and that can cause one to waste a lot of time on things that are > intended. Don't hold me to this, but I have this vague memory that somewhere back at the beginning of Ada there was a proposal that every if-statement had to have an else-statement. I don't remember if it was one of the early incarnations of Ada, somebody's proposed coding style, on one of the non-green language proposals. The point was to indicate in the code that the possibility of the if-condition's being false had been considered. Charlie -- Nobody in this country got rich on his own. You built a factory--good. But you moved your goods on roads we all paid for. You hired workers we all paid to educate. So keep a big hunk of the money from your factory. But take a hunk and pay it forward. Elizabeth Warren (paraphrased)