comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Vector (container) initialization: the schizophrenic ampersand
Date: Mon, 21 May 2012 08:57:18 -0700 (PDT)
Date: 2012-05-21T08:57:18-07:00	[thread overview]
Message-ID: <b3903ca0-c92f-4c19-86bb-bb5370f7c329@googlegroups.com> (raw)
In-Reply-To: <70817af5-96c3-4ca7-8d1c-b7635452bf4c@googlegroups.com>

On Saturday, May 19, 2012 2:03:56 AM UTC-7, marius63 wrote:
> > > V : My_Vectors.Vector := Element1 + Element2 + Element3;
> > >
> > > A bit less inelegant.
> > >
> > > /* But more than parenthesis or T'(...) in my view. */
> > 
> > You mean more inelegant, or more elegant?
> 
> Oops, sorry, I mean more elegant, i.e. I find
> 
>    Element1 + Element2 + Element3
> 
> more elegant than
> 
>    (T'(Element1) & T'(Element2)) & T'(Element3)
> 
> or variations thereof. (Textual elegancy. I agree the latter form has more semantic rigour = abstract elegancy.)

FYI, the last expression won't work the way you wrote it.  If Element1 is an object declared with type T, then saying T'(Element1) won't gain you anything (other than possibly clarifying things for a reader), since the compiler already knows that Element1 has type T.  The & operation needs to be enclosed in the parentheses in T'(...) to make a difference.  That's what tells the compiler that when there are competing possibilities for &, to use the one that returns T.

As for which one is more elegant: this is a matter of opinion, but personally, if you have a small (maybe 15 lines) subprogram or block that uses this expression, and the "+" rename is declared locally within that subprogram or block, it wouldn't be hard to figure out.  But if I'm trying to read your code, and I see this expression and start having to hunt for what "+" means, the result will probably include a set of curse words that are not very elegant.  So in that sense, using the "+" rename reduces overall elegance.  I'm sure you already realize this, but for others' benefit: elegance is a worthwhile goal only if it enhances readability by removing clutter without doing anything else that makes it harder to understand.  Otherwise, the only way elegance is useful is if your goal is to hang a framed listing of your program on the wall, rather than to run it.

                           -- Adam 



  parent reply	other threads:[~2012-05-21 16:01 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-17 20:20 Vector (container) initialization: the schizophrenic ampersand Marius Amado-Alves
2012-05-17 20:24 ` Jeffrey Carter
2012-05-17 20:26 ` Pascal Obry
2012-05-17 23:33 ` Adam Beneschan
2012-05-18  6:34   ` Marius Amado-Alves
2012-05-18  6:51   ` Marius Amado-Alves
2012-05-18 13:31     ` Robert A Duff
2012-05-18 18:55       ` Shark8
2012-05-18 22:44         ` Robert A Duff
2012-05-19  9:03       ` Marius Amado-Alves
2012-05-19 16:15         ` Robert A Duff
2012-05-21 16:02           ` Adam Beneschan
2012-05-21 17:04             ` Robert A Duff
2012-05-21 17:57               ` Adam Beneschan
2012-05-21 15:57         ` Adam Beneschan [this message]
2012-05-19  9:28     ` Dmitry A. Kazakov
replies disabled

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