comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: ADA and return functions (Strings)
Date: Sun, 19 May 2002 15:27:29 -0500
Date: 2002-05-19T15:27:29-05:00	[thread overview]
Message-ID: <mailman.1021840081.14696.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 5ee5b646.0205190630.237196b3@posting.google.com


----- Original Message -----
From: "Robert Dewar" <dewar@gnat.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: May 19, 2002 9:30 AM
Subject: Re: ADA and return functions (Strings)


> "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com> wrote in message
news:<mailman.1021804803.32634.comp.lang.ada@ada.eu.org>...
>
> > The best way to do this without spaces is something like this:
> >
> > return Ada.Strings.Fixed.Trim (Version.Major'img, Ada.Strings.Left) &
> >  "." & Ada.Strings.Fixed.Trim (Version.Minor'img, Ada.Strings.Left);
>
> Seems very heavy to drag in the whole of Ada.Strings.Fixed for such a
trivial
> task, and even heavier to call Trim repeatedly. Why not just write a little
> function called Semsible_Image that you then call. Actually you can use the
> name Image for this function.
>
After having pressed the "Send" button, I thought I had been a bit
presumptuous to say "the best way ...";

Robert's comment about dragging in the whole of Ada.Strings.Fixed is certainly
appropriate, if there were no other reason to drag it in.  As far as the
overhead of calling Trim twice is concerned, I reasoned that the function
getVersion would likely be called only once, but certainly not frequently.

This, too, is presumptuous, so I offer another implementation, perhaps not
as (humanly) readable as my previous offering, but certainly more efficient:

function getVersion return String is
   Major : constant string := Version.Major'img;
   Minor : constant string := Version.Minor'img;
begin
   return Major (Major'First + 1 .. Major'Last) &
     "." & Minor (Minor'First + 1 .. Minor'Last);
end;

While we're looking at this function, I'll offer another comment.

The use of verb phrases as the names of functions is not considered the
best practice addording tho the Ada Style Guide.  Instead function names
should be noun phrases.  So I would simply name this function Version.






  parent reply	other threads:[~2002-05-19 20:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-19  7:20 ADA and return functions (Strings) ProLogic
2002-05-19 10:38 ` David C. Hoos, Sr.
2002-05-19 14:14   ` ProLogic
2002-05-19 14:30   ` Robert Dewar
2002-05-19 20:23     ` sk
2002-05-20 13:08       ` Marin David Condic
2002-05-21  2:51         ` sk
2002-05-21 10:50           ` John English
2002-05-21 12:52           ` Marin David Condic
2002-05-21 14:39           ` Ted Dennison
2002-05-21 16:27             ` Jean-Pierre Rosen
2002-05-21 20:39             ` sk
     [not found]             ` <3CEAB094.6B9E14F7@myob.com>
2002-05-21 21:07               ` sk
2002-05-21 19:52         ` sk
2002-05-19 20:27     ` David C. Hoos, Sr. [this message]
2002-05-20  3:06       ` Robert Dewar
2002-05-20 15:29         ` Kevin Cline
2002-05-20 17:16           ` Larry Kilgallen
2002-05-19 21:06 ` Jeffrey Carter
2002-05-20  1:58   ` tmoran
2002-05-20  2:28     ` David C. Hoos, Sr.
2002-05-20  3:05       ` tmoran
2002-05-20  3:35         ` David C. Hoos, Sr.
replies disabled

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