comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: if-then-no-else  Programming
Date: Mon, 18 Apr 2016 23:08:16 -0400
Date: 2016-04-18T23:08:16-04:00	[thread overview]
Message-ID: <in7bhb1s19fvukublmpqo3fs79nqq46qg0@4ax.com> (raw)
In-Reply-To: 1mlx1gf.ebrae11jak5tyN%csampson@inetworld.net

On Mon, 18 Apr 2016 19:24:51 -0700, csampson@inetworld.net (Charles H.
Sampson) declaimed the following:

>
>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:
>
	A "move" where?

>   Variable := 3;
>   if <condtion> then
>      Variable := 1;
>   end if;
>

	Sure wouldn't work anywhere where the alternatives have side-effects

	if New_Record then
		Insert_Record(data);
	else
		Replace_Record(data);
	end if;

vs

	Replace_Record(data):	-- what if there isn't a record?
	if New_Record then
		Insert_Record(data);
	end if;


	And probably is not recommended if (for simple assignment) the target
is a volatile object -- like GPIO pins accessed via a mapped register. One
wouldn't want to trigger some state that isn't really valid.

	if not Walk then
		Walk_Signal = value_of_dont_walk_lights;
	else
		Walk_Signal = value_of_walk_lights;
	end if;

vs

	Walk_Signal = value_of_walk_lights;
	if not Walk then
		Walk_Signal = value_of_dont_walk_lights;
	end if;

	Would you really want the cross-walk lights to flicker "walk" when
determining they should be "don't walk"? {Yes, it's an artifical example,
but still...}
	

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/


  reply	other threads:[~2016-04-19  3:08 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-19  2:24 if-then-no-else Programming Charles H. Sampson
2016-04-19  3:08 ` Dennis Lee Bieber [this message]
2016-04-19  3:19 ` Jeffrey R. Carter
2016-04-19  6:18 ` Nasser M. Abbasi
2016-04-19  7:55 ` Dmitry A. Kazakov
2016-04-19 12:17 ` G.B.
2016-04-20 22:26   ` Martin
2016-04-19 13:27 ` gautier_niouzes
2016-04-19 19:51 ` Randy Brukardt
2016-04-19 22:40   ` Shark8
2016-04-20 22:35     ` Randy Brukardt
2016-04-20  7:56   ` Charles H. Sampson
2016-04-20 11:26     ` Dennis Lee Bieber
2016-04-20 12:32       ` G.B.
2016-04-20 12:36         ` G.B.
2016-04-20 23:07     ` Jeffrey R. Carter
2016-04-19 20:32 ` Charles H. Sampson
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox