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!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: if-then-no-else Programming Date: Tue, 19 Apr 2016 09:55:59 +0200 Organization: Aioe.org NNTP Server Message-ID: References: <1mlx1gf.ebrae11jak5tyN%csampson@inetworld.net> NNTP-Posting-Host: bqgfK7NL3xTHnr0WRaLl4g.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:30185 Date: 2016-04-19T09:55:59+02:00 List-Id: On 19/04/2016 04:24, Charles H. Sampson wrote: > 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? There are only few cases when asymmetric if-then is ever used. 1. Initialized default Variable : Integer := 3; begin ... if then Variable := 1; end if; Similar case is bulk initialization of arrays: Variable : String (1..80) := (others => ' '); begin ... if then Variable (20) := 'a'; end if; 2. Unbalanced terminating alternative. When THEN is very short and terminates some execution control path: procedure Foo (Variable : out Integer) is begin ... if then Variable := 1; return; end if; ... -- Do a lot of stuff end Foo; It could be "raise" instead of return, or "exit" when the variable is set as the result of a loop execution. Otherwise, the advice is evident rubbish, as others have pointed out already. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de