Re: Operator overloading in Java ?

From: Anthony Borla (ajborla_at_bigpond.com)
Date: 02/22/05


Date: Tue, 22 Feb 2005 12:08:14 GMT


"Thomas Weidenfeller" <nobody@ericsson.invalid> wrote in message
news:cveu2q$b9b$1@newstree.wise.edt.ericsson.se...
> Paul wrote:
> > The point to operator overloading in C++ [distilled from
> > Stroustrup] was to simply mimic the mathematical operations
> > available on elementary data types and also indexing with [],
> > dereferencing, and most others.
>
> But even the father of C++ (Stroustrup himself) couldn't
> resist the temptation and sanctioned the abuse of the
> bit-shift operators for I/O.
>

Oh you mean overloading them for stream-based I/O ? I find this particular
use quite intuitive [then again, C++ was my first OOPL]. Horses for courses,
I guess :) !

>
> With that he set the precedence for an endless amount of
> operator-overloading abuse in C++ by programmers all
> over the world. If the language's father can't stay clean,
> how should his loyal followers?
>

I don't mind the operator overloading facility in C++ - it is very, very
flexible - and, correctly, and *sparingly* used, can truly enhance a design,
making it more understandable. Of course this is a subjective observation:
it depends very much on whether someone prefers code which looks like this:

    a == b

or like this:

    a.equals(b)

Unfortunately its very flexibility makes it a facility that can be very
easily abused. Not much that can be done about that except perhaps
appropriately educate / train developers, and draw up, and enforce,
standards that will prevent, or at least minimise such abuse.

>
> IMHO, one of the best design decisions for Java was to
> leave out that stuff. Unlike in the 1960s numeric computation
> is no longer what most programs do, so for many programmers
> it is not essential at all. There are other languages for those who
> need it. Sooner or later some scientists with apparently to much
> time on their hands will try to force that stuff into Java because
> they need it, while the many more people who don't need it can't
> spent time in the decision-making comities to fight it.
>
> I could make a similar case for generics. Yes, they are not
> templates. Yes, you can use them for something useful.
> But if I see the many attempts to use them like templates
> and e.g. the number of "generic" classes like Pair classes
> which suddenly pop up left, right and center then I see my
> worries confirmed. Generics will do harm to the language
> in the long term. I bet there are already several people who
> try to build an SGL (Standard Generic Library) for Java to
> mimic C++'s STL and to force it down the throat of Java
> programmers. :-(
>

I haven't experimented enough with 1.5 to venture an opinion on Java
generics. I will say, however, that whilst some of the work with C++
templates - particularly template metaprogramming - is quite astonishing and
clever, but it's also esoteric, mindboggling, and reeks of 'trickery', not
features that I think should be associated with a usable programming
language, and is one aspect of C++ that I've grown to dislike.

As for the future of Java, I can only say that I know of no commercial
programming language that has *removed* features as part of its evolution.
Language standards documents only ever *grow* [resulting in more tree
deaths] over time !

Rememember, also, that when trying to sell a product, one way to
differentiate it from competitors, thus make it more attractive to potential
customers is to enhance existing, and add new, features. I think we all know
what that means when applied to programing languages :) !

Cheers,

Anthony Borla



Relevant Pages

  • Re: Static vs Dynamic
    ... (Java has too much noise in its source code, ... lot to ask and is typical in a typed language supporting polymorphism. ... > developers can easily learn the Java programming language; ... > obivous bugs slip through and b) in many cases, ...
    (comp.lang.lisp)
  • Re: why is "self" used in OO-Python?
    ... and worse this has spread from Java into other ... by whatever happens to be the first OO language they learn". ... If the first programming language (or the ... I have no objection to teaching Java in a CS curriculum. ...
    (comp.lang.python)
  • Re: Public disclosure of discovered vulnerabilities
    ... I spoke of Java; ... > necessary when programming in Java. ... > it is every single programmer who wants to use the language securely. ... this is what we call the "mental model" problem in aerospace. ...
    (sci.crypt)
  • Re: 71% Say Finding New Energy Sources More Important than Conservation
    ... Most of the drive to define was for a test programming language, because each tester had it's own language and the engineer would have to re-write the program every time the testor changed. ... The only reason it was used was because people saw that it would have a longer life time than ADA. ... My group at Stanford switched to Java as their language of choice after giving up on C++ as too flawed to use. ...
    (soc.retirement)
  • Re: C# and C++ Past, Present, Future :: Software Engineer
    ... i know) easy to write client/server apps, n-tier apps, etc. ... You mentioned templates... ... to be addressed with generics in version 2 of the language. ... able to blend C# and C++, getting the best out of the Java design. ...
    (microsoft.public.dotnet.languages.csharp)