From: Brad Moore <bj.mooremr@gmail.com>
Subject: Re: Ada needs some modernization
Date: Fri, 10 Jun 2022 09:38:35 -0700 (PDT) [thread overview]
Message-ID: <3eb11358-66a5-4a87-b8ec-2328bbbb73acn@googlegroups.com> (raw)
In-Reply-To: <75d90749-242f-42b8-ba0b-299f7ac693e0n@googlegroups.com>
On Tuesday, May 31, 2022 at 10:54:47 AM UTC-7, Matt Borchers wrote:
> Throughout my career, I often find myself writing code similar to:
>
> if (A and B) or else (not A and C) then...
>
> and I always wished there was a better and clearer way to write this in Ada. Then along came if expressions. But, if expressions don't help that much with readablity although it is arguably simpler:
>
> if (if A then B else C) then...
>
I agree with the other comments, and in a case like this, I might consider writing an expression function to improve readability.
Using cryptic letters for Booleans makes it difficult to assign a name to the expression function, but if you apply to
less generic example, this becomes easier to do.
For example, if A is renamed to Weekday, B means (time < 9:00pm), and C means (time < 6:00pm) you could write:
function Shopping_Mall_is_Open return Boolean is (if Weekday then Earlier_than_9_PM else Earlier_than_6_PM);
Then your other code would simply be,'
if Shopping_Mall_is_Open then ...
Brad
prev parent reply other threads:[~2022-06-10 16:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-31 17:54 Ada needs some modernization Matt Borchers
2022-05-31 19:05 ` Gautier write-only address
2022-05-31 19:55 ` Dmitry A. Kazakov
2022-05-31 22:46 ` Randy Brukardt
2022-06-01 7:24 ` John McCabe
2022-06-01 19:00 ` Jeffrey R.Carter
2022-06-02 5:56 ` G.B.
2022-06-10 16:38 ` Brad Moore [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox