comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Default value for a record component
Date: Tue, 24 Jul 2007 14:12:46 -0500
Date: 2007-07-24T14:12:46-05:00	[thread overview]
Message-ID: <f85ir2$klu$1@jacob-sparre.dk> (raw)
In-Reply-To: 1185270857.459100.34770@q75g2000hsh.googlegroups.com

"Maciej Sobczak" <see.my.homepage@gmail.com> wrote in message
news:1185270857.459100.34770@q75g2000hsh.googlegroups.com...
> On 24 Lip, 03:27, "Randy Brukardt" <ra...@rrsoftware.com> wrote:
>
> > This is a rather stupid question, especially given the C++ example that
you
> > give later. The closest analog to a C++ class in Ada is a controlled
type.
>
> What is the analog of C++ struct with a constructor, then?

A function is a constructor for Ada; declare an appropriate function and use
it.

> > Hinestly, I don't see any sane reason for being unwilling to use a
> > controlled type here.
>
> Honestly, me neither. The question is really about the language design
> and its ability to express orthogonal concepts. For me field
> visibility and its initialization are orthogonal. Well, should be.

Everything in Ada is inter-related; often in ways that are not obvious. I
learned this the hard way when we were trying to subset Ada in the early
1980's. It just didn't work very well because there always was something
else that you needed to have a full solution. Eventually we ended up with
95% of the language, and then we might as well finish the whole thing.

I realize that someone relatively new to Ada might not know this, but you
cannot usefully look at single features of Ada in a vacuum. You need to use
many of them...

...
> > In any case, having a type that is visible rather than a private type is
> > almost always a mistake.
>
> Can't you think about examples where it isn't? (the "almost always"
> part has to be complemented by something)

I know of various examples where it wasn't, but those examples are almost
always motivated more by laziness (don't want to write a function call to
access a component) or by missing features in the language (Dmitry's
"virtual components", some way to write aggregates and literals for private
types, etc.). These two reasons are really the same, because if the missing
features were available, one could write an appropriate private type but
still use it as if it was a visible type. The net effect is that I think
that if we had a "perfect" programming language, there would never be a
reason to declare a visible type, but there might be such a reason given the
imperfect nature of real programming languages. (But even then, you are
likely to regret it.)

                                 Randy.





      reply	other threads:[~2007-07-24 19:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-21 21:19 Default value for a record component Maciej Sobczak
2007-07-22  8:08 ` Dmitry A. Kazakov
2007-07-22 19:44   ` Maciej Sobczak
2007-07-22 21:44     ` Robert A Duff
2007-07-23 19:17       ` Maciej Sobczak
2007-07-23 19:41         ` Dmitry A. Kazakov
2007-07-22 20:01   ` Jeffrey R. Carter
2007-07-24  1:27 ` Randy Brukardt
2007-07-24  9:54   ` Maciej Sobczak
2007-07-24 19:12     ` Randy Brukardt [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