TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Tucker Taft <[log in to unmask]>
Reply To:
Tucker Taft <[log in to unmask]>
Date:
Fri, 1 May 1998 18:21:01 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (31 lines)
> For the special case where objects don't have 'invalid' states, but
> come fully into existence and stay, in a stack-like way, until they
> die, and where Ada 95's discriminant limitations don't cause
> difficulties, it would, IMHO, be desirable to use constructors rather
> than Create functions.
>    X:Object_Type(params);
> is simpler than
>    X:Object_Type := Create(params);
> and does not even have the possibility of forgetting the initial
> value assignment, or doing an erroneous later assignment.

Using discriminants to serve the role as parameters to constructors
seems to be inappropriate, unless their values are seen as relevant
throughout the life of the object.  If they are only affecting the
initial value of the object, it would seem to be better to use a parameterized
function as initial expression.

If you want to prevent the possibility of forgetting initial
value assignment, you could specify unknown discriminants
in the private type declaration.  E.g.:

    type Object_Type(<>) is private;

The full type need not have any discriminants at all, but by
doing the private declaration this way, a user of the type outside
the package is required to initialize all object declarations,
because simply "X : Object_Type;" is illegal (Object_Type is an
"indefinite" (view of a) type).

-Tucker Taft  [log in to unmask]

ATOM RSS1 RSS2