[1757] in java-interest
RE: A few queries...
daemon@ATHENA.MIT.EDU (Nelson Yu)
Sat Sep 16 07:48:12 1995
From: Nelson Yu <nyu@gpu.srv.ualberta.ca>
To: "'java-interest@java.sun.com'" <java-interest@java.sun.com>
Date: Sat, 16 Sep 1995 01:51:53 -0600
Llew,
>1) Pass-by-value vs pass-by-reference vs pass-by-const-reference
> As far as I could tell this wasn't discussed in any of the provided =
>documention. Java currently passes class arguments by non-const =
>reference. I assume that the currently reserved const keyword will =
allow >argument passing by const reference eventually. I can't see any =
point in >Java ever providing pass-by-value support.
> Why was argument passing by non-const reference chosen as the =
>default? This seems to be a dangerous practice and inconsistent with =
>Java's efforts at removing unsafe practices from the C++ language. =
>(removal of pointers was a good start)
In C++ the copy constructor is called whenever you call-by-value. In =
Java you'd _probably_(I'm no expert) call copy() or clone() which is in =
Object.
Java removes the need to have virtual destructors, copy constructors, =
assignment operators in every *well-designed* C++ class, through =
equivalent 'class methods' (in smalltalk-speak) of Object.
And as a added bonus it implements RTTI(Run-Time Type Information) and =
Threads rather nicely too.
>2) Meta-classes (template classes for those unfortunate C++ people)
> There seems to be no way to implement meta-classes within Java. The =
>interface mechanism allows for class methods to operate on any class =
>which implements a particular interface, but cannot guarantee the =
>homogeneity of instantiated classes. This makes usage of classes like =
>Vector unsafe (not to mention inelegant) since all elements need to be =
>typecast to the required type upon extraction.
Like Dylan and its setter/getter functions or in C++-speak templated =
functions. Let me get this straight you want something like an iterator =
called 'Next' that works on Arrays(aka Vectors) and Linked List?
I haven't thought about this much, but since all classes are derived =
from Object, its really just a matter of polymorphmism vs. =
parameterization(slower speed vs. code bloat). The Vector class is =
interesting, as it appears to be able to store heterogenous objects, =
where as parameterized classes in C++ are instantiated with a specific =
type and operate *safely* only on that type.
For example you derive(from Object or Person) a class called =
PersonVector with a method 'Next' and a PersonList also with a method =
'Next'.
Are you saying the follow would be type-unsafe? It should be safe under =
Java.
// Method in some class
GetNextValue(Object o)
{
o.Next();
}
So you can't just write one generic function/iterators as in C++ that =
operates on ALL data structures with a particular interface and data =
types, but considering the complexity that brings I won't miss it.
>3) Operator overloading
> Why was this omitted from the Java language? This is one of the =
'neat' >features of languages like C++. (although I'd prefer overloaded =
operator >support like that provided by ML, where new operators can be =
defined and >operator precedence can be redefined)
'Neat', but I've always considered them syntactical sugar. Using the =
operators is easy, but programming them is a different matter.
>Web applets would rarely require operator overloading, but if Java is =
>intended to be used for any serious development where mathematical =
>classes are required then it quickly becomes unwieldy.
>Specifying complex numbers as z.mul(z).plus(c) for Mandelbrot =
>generation is ugly compared with z =3D z * z + c. Reading code =
consisting >of operations on complex number, vector, matrix and tensor =
classes >becomes almost impossible without overloaded operators being =
defined >for these classes.
> I admit that operator overloading can be abused, but then so can =
>function naming.
I'm not sure if OO programming applies well to algorithmic problems. .
Shouldn't you be using Maple V or Mathematica? How about a functional =
language?
>Overall I'm quite impressed with what I've seen of Java. With native =
>machine-code compiler support, meta-classes and operator overloading I =
>see no reason why Java couldn't become as popular as C++.
Or as complex, UN-understandable.... C++ is powerful. Similar to using a =
sledgehammer to tack a photograph on the wall.
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com