comp.lang.ada
 help / color / mirror / Atom feed
From: Mike Young <mikey@mcs.com>
Subject: Re: Something like "->" in Ada?
Date: 1996/04/02
Date: 1996-04-02T00:00:00+00:00	[thread overview]
Message-ID: <31620B5E.FCD@mcs.com> (raw)
In-Reply-To: dewar.828419317@schonberg

Robert Dewar wrote:
> 
> Chris says
> 
> "   I am learning OOP with Ada 95.  Although I have only a bit of experience,
> mostly with Perl 5, I find that the "->" operator is much more intuitive
> than passing an object as a parameter to a subprogram.  Is it possible to
> define "->" as the following:"
> 
> What you are used to always seems more intuitive than what you are
> getting used to. Wait till you can say "I have completely learned OOP
> with Ada 95", then see what you think. Many people think that the
> procdure argument approach is in fact much simpler, and that the ->
> is unnecssarily restrictive and over-specific.

=======
Mayhaps, Robert. I would appreciate any help you might offer.

In playing with Intermetric's adajava package last night, I had 
an interesting few minutes translating the following Java statement into 
Ada-ish code:

   (size().width - g.getFontMetrics().stringWidth(helloStr))

The Ada equivalents I finally coughed up are:

1) (size(this).width - stringWidth(getFontMetrics(G), hello_Str))

2) declare
     pSize : Rectangle_Ptr := size(this);
     fontM : FontMetrics_Ptr := getFontMetrics(G);
   begin
     ...
       (pSize.width - stringWidth(fontM, hello_Str)),
       ...
   end;

In other words:          g().f().func(...);
compares to:             func(f(g(this)), ...);

I'm not drawing any conclusions from this exercise, but the contrast 
between Java's cascading style and Ada's func(f(g(x)), ...) style 
appears somewhat extreme. The Java version is consistent with a 
heirarchy (g.getFontMetrics().stringWidth(...)); this has some value 
when trying to unravel what stringWidth is. Also, there's a certain 
inconsistency in inverting the relationship when an attribute is 
directly accessed, compared to calling functions only. Changing an 
attribute into a function call would involve more work in re-ordering 
the statement.

But, as you say, it's probably a matter of acclimation. 

Mike.




  reply	other threads:[~1996-04-02  0:00 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-01  0:00 Something like "->" in Ada? Chris O'Regan
1996-04-01  0:00 ` Robert Dewar
1996-04-02  0:00   ` Mike Young [this message]
1996-04-03  0:00     ` Tucker Taft
1996-04-03  0:00     ` Robert Dewar
1996-04-04  0:00       ` Mike Young
1996-04-04  0:00       ` Mike Young
replies disabled

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