[130] in java-interest
new things in the java language
daemon@ATHENA.MIT.EDU (Dan.Oscarsson@malmo.trab.se)
Sat May 27 18:09:41 1995
From: Dan.Oscarsson@malmo.trab.se
Date: Sat, 27 May 95 12:45:42 +0200
To: java-interest@java.Eng.Sun.COM
Here are some of my thoughts about Java and new things:
There have been som talk about strings and string concatenation.
I think "+" is a good operator for string concatenation, that is what
I used in my C++ implementation I did some time ago. Though, some of
the difficulties in Java is because of the special overloaded "+"
for strings that makes anything be converted to a string.
There are some other operators for strings that are missing.
Why not allow: string == string
to compare strings? Very useful and easy to read. "!=" should also be used.
And why not: string ~= string
for case ignored comparison.
And string[pos] should return character at position pos of the string.
Now with garbage collection it is possible to do sharing of arrays (and
strings), why not allow slices?
For an array or a string I would like to write: a = b[3:5]
making a into an array (or string) that is the slice of b consisting
of the postions 3 to 5.
To make a into a separate copy of the slice one could write: a.copy(b[3:5])
The new way to declare arrays is very nice (int [] a,b).
This is much like many non C:ish languages. It is easier to understand
that a declaration has the format: type variables
than the C:ish where part of the type must be attached to the variable name.
In some languages you declare an array as: integer array a[10],b[20]
this means in Java: int [] a = new int[10],b = new int[20] (if now this complex
declaration is allowed). Why not allow the shorter form?
Also it would be nice if the old form (int a[]) gets a warning from the
compiler and is removed in a later version.
There has also been som talk about returning values from a method.
There has been some suggested formats:
int foo(in int a, out int b, inout int c)
int foo(int a, return int b, return int c)
I have used one language that used the format (C:ished)
int foo(int read a, int write b, int read write c)
that language allows access modifiers on a variable. Something declared
with only read is more or less equivalent with javas final allowing only
read access to the variable and allowing the compiler to optimise this as
works best. Using this on a parameter (it is of course allowed on variable
declarations also) allows only read access so cannot be changed even
in the method (same as const in C++).
write access in a parameter makes it a return parameter that can be
written to. The value is return to the caller when the method returns, so
an exception will not change the value.
I think read/write modifiers are quite good, though might not mean the
same thing as in/out. in may mean that the parameter can be written to, but
will not be returned to the caller (C:ish call by value).
I see no reason to and three new reserver words, inout can be written in out.
Also I would prefer to see the parameter access modification to be treated
as a type modifier, that is it should follow base type:
int foo(int in a, int out b, int in out c) or
int foo(int a, int return b, int return c).
I am not sure what format I like best, in out looks ok, read write is nice,
return disturbes a little. Maybe I could in Java write
int foo(int final a,int return b, int c)
meaning a is in parameter and cannot be changed, b is an in parameter
that is also returned (no way to say it need not be initialised from
caller as would be the case with just out) and c is an in variable that can
be changed. Or I could write
int foo(int final a, int out b, int c, int in out d)
meaning in parameter a with read access (implicit in)
parameter b is not initialised from caller, read/write variable, value returned.
parameter c: in parameter (implicit in) read/write access.
parameter d is initialised from caller and the value is return when the
method returns (not on exceptions).
Hope this gives some new though about development of the Java language.
Some of them are about changing C:ish syntax to that used in other
languages (why is Java using int for integer, todays modern workstations
are not as slow as teletypes?), and more could be done but that may be too
much for the C-followers.
Dan
--
Dan Oscarsson
Telia Research AB Email: Dan.Oscarsson@malmo.trab.se
Box 85
201 20 Malmo, Sweden
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com