comp.lang.ada
 help / color / mirror / Atom feed
From: stt@henning.camb.inmet.com (Tucker Taft)
Subject: Re: Something like "->" in Ada?
Date: 1996/04/03
Date: 1996-04-03T00:00:00+00:00	[thread overview]
Message-ID: <DpB8vK.Kv7.0.-s@inmet.camb.inmet.com> (raw)
In-Reply-To: 31620B5E.FCD@mcs.com

Mike Young (mikey@mcs.com) wrote:

: ...
: 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))
: ...

Of course, given my background, I find this latter form much 
easier to grok.  Perhaps something like the following is
going on (speculating on how my perception works here; add
big grain of salt... ;-):

   with the prefix form g.f(a).h(b,c), the name of the thing you 
   are getting ("h") is buried in the middle of the expression, 
   whereas with the "params inside" form, the function name comes 
   at the front, so you know right away that you are getting a 
   stringWidth.  With field selection the name at least comes at 
   the very end, rather than buried in the middle.

It is interesting that Java code examples often have very short
variable names.  If your variable names are relative long, such
as:
    currentGraphicsObj.getFontMetrics().stringWidth(stringOfInterest)

then it becomes even harder to find the important signal with all the noise.

As another example, in using Java, one of the "perceptually" confusing 
lines I see frequently is:

    System.out.println(Message);

whereas in Ada/Java this becomes (presuming "use" clauses):

    println(stdout, Message);

Again, I find the Ada usage much easier to understand at first glance, 
given my background.  The complete conceptual switches between 
"System" (a class), "out" (an object), and "println" (a method) in 
the Java version is particularly unhelpful to my perception.

I suppose in Ada, I think of "." as meaning "digging into" the
guts of an object or package, and I think of "()" as performing
some operation.  When "." means both digging in and invoking
a method, depending on context, I find it harder to intuit the
meaning on a first reading.

I suspect it is somewhat the reverse-polish
vs. infix issue again.  One is easier to write, the other is
(at least for some folks!) easier to read.  Since on a calculator,
noone is generally reading the result of your button pushes, a 
reverse-polish approach makes good sense.  In a programming language,
you can argue for the most readable -- which is unfortunately
going to vary depending on your background.

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

For sure.  Vive la difference.

: Mike.

-Tucker Taft   stt@inmet.com   http://www.inmet.com/~stt/
Intermetrics, Inc.  Cambridge, MA  USA




  reply	other threads:[~1996-04-03  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
1996-04-03  0:00     ` Tucker Taft [this message]
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