comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: formal array types and default values
Date: Wed, 3 Jan 2018 15:16:34 -0600
Date: 2018-01-03T15:16:34-06:00	[thread overview]
Message-ID: <p2jh7j$d8g$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 5c75fcdd-c965-4d03-9161-3576212e674d@googlegroups.com

"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:5c75fcdd-c965-4d03-9161-3576212e674d@googlegroups.com...
> Let's make it a proposal for the next norm then. I'm half serious: 
> depending on the difficulty,
> which I know nothing of, I am ok to help, however I can.
> Such a nice (and logical) feature, would a shame not to do.

You mean a useless feature. :-)  (See my response to Niklas about the 
difficulty.)

The primary purpose of Default_Value is to detect errors. Specifically, most 
enumeration types have (or could have) a value that means Unknown or 
Uninitialized. For instance:

    type My_Color is (Unknown, Black, Red, Green, Blue, White)
        with Default_Value => Unknown;

With this declaration, any programming errors that fail to set an object of 
My_Color will show up as a value of "Unknown". Which can be reliably 
detected.

Other uses of default values are evil, because they hide an operation that 
should always be explicit. For instance:
     type Evil_Integer is new Integer
         with Default_Value => 0;

Since 0 is a legal, useful value of type Evil_Natural, some code might work 
by accident when an uninitialized object happened to get the right value by 
default. That sort of thing will not help future readers.

                                   Randy.



  reply	other threads:[~2018-01-03 21:16 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-30 21:42 formal array types and default values Mehdi Saada
2017-12-30 22:20 ` Niklas Holsti
2017-12-30 23:59   ` Mehdi Saada
2018-01-03  0:52   ` Randy Brukardt
2018-01-03  8:33     ` Niklas Holsti
2018-01-03 20:53       ` Randy Brukardt
2018-01-06  0:10         ` Niklas Holsti
2018-01-08 21:12           ` Randy Brukardt
2017-12-31 12:34 ` Jeffrey R. Carter
2017-12-31 14:55   ` Mehdi Saada
2018-01-03 15:47 ` Mehdi Saada
2018-01-03 21:16   ` Randy Brukardt [this message]
2018-01-04 15:02 ` Mehdi Saada
replies disabled

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