TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Forum View

Use Proportional Font
Show Text Part by Default
Condense Mail Headers

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

Print Reply
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Tucker Taft <[log in to unmask]>
Wed, 21 Apr 1999 11:46:31 -0400
Tucker Taft <[log in to unmask]>
text/plain (54 lines)
Rick Duley wrote:

> ...I can only overload existing operators, but then:
>         My_Integer_Io.Put(Value1 + Value2);  or
>         My_Integer_Io.Put("*"(Value1, Value2);
>         when the result is a maximum is very misleading.
>         Two questions:
> 1. Is it possible to generate user defined binary operators?


> 2. If not, then why not?

Ada has an intentional bias in favor of readability over writability.

Allowing users to invent their own operators using special characters,
with semantics unrelated to any preexisting operator, creates notation that
has no hint of what it means, nor what precedence it should have
(e.g. how does "a + b # c" get interpreted, "(a + b) # c" or "a + (b # c)"?).

Presumably if you overload "+" or "*" you would do so only when you
are defining an operation that has a lot in common with "+" or "*"
respectively, and you like the "precedence" implied.   However, someone
reading code scattered with the use of a "#" operator would have
no way of "intuiting" what it means, nor what is its precedence.

The number of keystrokes saved by writing "Value1 # Value2" versus writing
"Max(Value1, Value2)" was not felt to pay off in the long run,
given that code is read much more frequently than it is written.

At least that's the official rationale...

So stick with good old "prefix" function notation, with names in English
(or your local language ;-).

> --------------------------------------------------------------------------
> Rick Duley
> Edith Cowan University
> Perth, Western Australia
> tel: +61 (08) 9370 6619
>                                                                    /-_|\
> fax: +61 (08) 9370 6100                                           /     \
>                                                             perth *_.-._/
> "The lonliest place in the world                                       v
>                           is the loosin' champ's dressin' room!"
>                                                              (Jack Dempsey)
> "He wasn't an Ada programmer in Perth!" (Rick Duley) J

-Tucker Taft  [log in to unmask]