[1065] in java-interest
Yet more operator overloading & other trivia
daemon@ATHENA.MIT.EDU (kevin@elvis.wicat.com)
Thu Aug 17 22:44:24 1995
From: kevin@elvis.wicat.com
Date: Thu, 17 Aug 95 11:19:35 MDT
To: java-interest@java.sun.com
Sorry to drag this out further (and I really doubt the Java folk at
Sun care), but since I haven't got my two cents in yet, the debate can;t
possible be over yet.
The debate over operator overloading seems to come down to the
question of what the programmer can take for granted in reading valid
source. For example, I am told that in the ancient days of Algol, there
were no reserved words, so that the programmer could not take basic
tokens such as "if" at face value. This can be taken to ridiculous
extremes: about a year ago, Stroustrup had a (hopefully joke) article in
the JOOP about overloading white-space in C++.
Now, I'm not aware of any major modern language that doesn't have
reserved words, and I don't hear the pro-op-ov crowd clamoring for the
right clamoring for the right to overload "throw" or "this", even though
precisely the same arguments could be made for this as can for op-ov
("Improved readability!" "Introduced ambiguity!").
So, why does nobody seem to want this feature that is basically so
similar to op-ov? I believe it is because most current programmers (OK,
so I really mean "me and my circle of friends & co-workers") grew up
with BASIC and procedural languages where keywords have always been
sacred. From the first "10: PRINT$ Hello World" we have had reserved
words that we had no ability to change. In other words, it is quite
purely a cultural thing.
But in this case, the programming culture is important to a
language. Why else would Java co-opt C(++) syntax, if not to make it
easier to assimilate into the large group of C and C++ programmers? And
as a result of extensive research (i.e. talking to my buddies), I
believe that the basic operators are widely considered fixed in the same
way as keywords. In other words, if I see an "if" token, I don't have to
question it; likewise, I believe "+" to mean integer, or at worst,
numeric addition (consider this a vote against the special case +
operator for strings). Forcing myself to suspect every "+" and ">" is a
change in mindset that comes with some difficulty.
This makes op-ov an easy source of error; it goes against a basic
assumption that I have taken for granted for over a decade. Now, it's
easy enough to say that what needs fixing is my assumptions, not the
language, and there really is no reasonable response to that except to
say that I would rather use a language that matches my assumptions that
once that doesn't. And that I believe that there is a large group, if
not a majority, of programmers that share this assumption (of course,
new languages like Java tend to attract people a little further out on
the fringes, and I believe this is skewing the results on this mailing
list). As I said before: culture counts. If Java wishes to become widely
accepted, it doesn't help to alienate me and others like me.
So - not that we actually get a vote, but consider this one against
overloading existing operators. I do like the notion of user defined
infix operators, particularly with the proposed (+) or <+> syntax; this
preserves the readability the op-ov folk tout so highly, while providing
a red flag to those of us who have learned to ignore a naked +.
And as a special added bonus who plowed through all this, I would
like to propose a little syntactic sugar stolen from Modula-3: they have
the very useful construct (I probably have the syntax wrong, since it
has been a while since I dabbled with M-3):
Typecase (X)
case Class1:
case Class2:
which is simply sugar for the (Java) construct:
if (X instanceof Class1) { ... }
else if (X instance of Class2) { ... }
...
So, adding a "typeswitch" or equivalent keyword would bring a little joy
into my life. Not worth arguing over if nobody else likes it, though.
Kevin
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com