comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@futureapps.invalid>
Subject: Re: if-then-no-else Programming
Date: Tue, 19 Apr 2016 14:17:16 +0200
Date: 2016-04-19T14:17:16+02:00	[thread overview]
Message-ID: <nf57e2$lr5$1@dont-email.me> (raw)
In-Reply-To: <1mlx1gf.ebrae11jak5tyN%csampson@inetworld.net>

On 19.04.16 04:24, Charles H. Sampson wrote:
> 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 <condtion> then
>        Variable := 1;
>     end if;

I think that "software engineering" here might mean web development
or media development; not the typical areas of engineering, AFAIK.
But while speculation, this really seems to about making sure that
variables have a value assigned, not so much about conditionals
per se.

If about guaranteed assignment, then languages have started
supporting the initialization problem in much better ways.
The above example reminds me of PHP/Python/Javascript, etc.
Swift, OTOH, a newly developed language, guarantees assignment
before use and rejects, as do some older language for constants,
this definition:

     func foo(condition: Bool) {
         var Variable : Int

         if condition {
             Variable = 1
         }
         bar(Variable)
NN:error:   ^ variable 'Variable' used before being initialized
     }


GNAT has a similar warning. Is there still a reason why,
in embedded system, assignment is considered costly, maybe,
and thus had better be done only as necessary, instead
of being enforced, using default values, or dummy values?
Or even constructor invocations?

Ada 2012 adds conditional expressions (in addition to the
old nested functions that need to return). So, if the value
that is to be assigned depends on Condition,

    Variable :=
     (if Condition
       then 1
       else 3);

is another way of making sure that Variable is initialized,
in *one* statement!

This expression is part of many languages, albeit using
different syntax. The list includes Python, Javascript, C, ...

  parent reply	other threads:[~2016-04-19 12:17 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
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. [this message]
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