Open letter to sun about java generics syntax

R

Roedy Green

Sun's additions are certainly not perfect but they're
about as good as can be expected.

The me they smell of eau de kludge. Use of extends to mean implements
and & to mean comma really stink. I would far sooner have gone with
some more consistent, even if it meant cleaning up some old code that
used a keyword by accident.
 
H

Hamilcar Barca

The me they smell of eau de kludge.

I don't really agree. When I first saw Java's Collection collection, I
thought it was a serious mistake that generics meant "containers hold
Objects" and require lots of casting by the programmer. In the last few
months, I've read all the formal proposals, from which came Java's new
parametric polymorphism. I now believe there is no way to do what
programmers might wish without some serious tradeoffs.
Use of extends to mean implements

There seems to be a premium on simplicity in Java, even at the cost of
expressiveness and/or power. I don't really disagree with you on this
point, although I find Sun's keyword usage acceptable.
and & to mean comma really stink.

This I find a bit bizarre and I don't see any precedent for the syntax.
I would far sooner have gone with some more consistent, even if it meant
cleaning up some old code that used a keyword by accident.

Here, I'm in perfect agreement, except I'd be quite willing to break
backwards compatibility in both the language, the libraries, and the JVM.
Sun's engineers (and undoubtedly their marketroids and management-types)
obviously disagree with me.
 
J

javadesigner

Tor said:
Why mix Pascal syntax into a C-family language?

Why not use :: instead of a .
foo::bar() is more C++ like for method invokation, not foo.bar()

In fact, you may want to read about why java was invented in
the first place. Syntactical clarity had a lot to do with it.
It would! That's the point of reserving certain words as keywords, you
make sure they're not used as variable names. This is why programs
that used "delegate" as a variable name failed to compile when
Microsoft introduced that keyword in their dialect of Java.

Type of Type

would break existing programs that used "of as variable ?

I'm guessing foo<bar> should also break existing programs
that use said:
Are you totally ignorant as to how a parser functions in a language
that uses keywords?

Maybe. How about you ? Care to give a concrete example of a non-trivial
program that uses "of" as a variable name that would break ? (since
"of" is not a current keyword, it can be used as a variable, method
or class name.

Best regards,

--j
 
T

Tor Iver Wilhelmsen

javadesigner said:
I'm guessing foo<bar> should also break existing programs
that use "<" and ">", right ?

No, of course not. People don't use < and > in identifiers, since
they're not legal characters in identifiers. So why would it break? By
contrast, "of" is a legal identifier.

Though it should be mentioned that keywords have been added later,
like "assert"; this led to a change in the JUnit library where they
changed the assert() method to assertTrue().
Maybe. How about you ? Care to give a concrete example of a
non-trivial program that uses "of" as a variable name that would
break ? (since "of" is not a current keyword, it can be used as a
variable, method or class name.

File of = new File("output.txt");

Add the non-trivial surroundings yourself as you see fit.
 
P

P.Hill

Roedy said:
What I meant was, from the programmer's point of view, they are just
another parameter. Maybe we don't need to treat them like holy relics
surrounding them in golden horns < >.

Next thing you know you'll want us to program in LISP!
But then you are old Forth programmer.

-Paul
 
S

Stefan Ram

P.Hill said:
Next thing you know you'll want us to program in LISP!

"A good C hacker will use Lisp when possible."
-- Rahul Jain

But look at this:

@ManyToMany(cascade=CREATE)
@AssociationTable(
table=@Table(name="EMP_PROJ"),
joinColumns=
@JoinColumn(name="EMP_ID", referencedColumnName="ID"),
inverseJoinColumns=
@JoinColumn(name="PROJ_ID", referencedColumnName="ID"))

This is Java 1.5, but to me it looks like S-expressions
augmented with attributes.

Recently, i did "invent" a text markup language, which also
happens to be a subset of Java 1.5 and is akin to
S-expressions. A section, beginning with a subsection looks
like this:

Section section =
o(x( "title", "Schnittstellen in Java" ),
o(x( "title", "Nutzen von Schnittstellen" ),
o("Durch den richtigen Einsatz von Schnittstellen ",
"werden alle sinnvollen Bindungen von Methoden an Objekte ",
"möglich. Bei direkter Bindung ohne Schnittstellen, ",
"wären sonst bestimmte sinnvolle Kombinationen ",
"erschwert oder unmöglich. Dadurch können ",
"Methoden und Objekte besser wiederverwendet ",
"werden. Somit verbessert sich letztendlich das ",
"Verhältnis zwischen dem Arbeitsaufwand zur ",
"Programmierung und dem Umfang des damit bewältigten ",
"Anteils eines Problems. " )),
o(x( "title", "Schnittstellen im Alltag" ),
...

A "section" is marked "o" and might contain a list of plain
String entries (thanks to the new varargs feature) and
attributes, which are marked with "x". This markup language
can be used like XML. The example program I have built with
that formats this markup structure to a plain text file, doing
paragraph wrapping and so, but might as well output it to HTML.

For example, "o" and "x" might be defined as:

final static Section o
( final java.lang.Object ... args )
{ return new Section( args ); }

final static java.lang.Object x
( final java.lang.String relation, final java.lang.String text )
{ return new Attribute( relation, text ); }
 
P

P.Hill

Stephan, I was just kidding.
"A good C hacker will use Lisp when possible."
@ManyToMany(cascade=CREATE)
@AssociationTable(
table=@Table(name="EMP_PROJ"),
joinColumns=
@JoinColumn(name="EMP_ID", referencedColumnName="ID"),
inverseJoinColumns=
@JoinColumn(name="PROJ_ID", referencedColumnName="ID"))

So don't complain if your attribute starts looking like S-expressions.
Now you too can do LISP in your Java source! :)

The mixing of syntax will truely become amazing, 'cause we
have Algol-like Java with Lisp-like attributes (or at least all
paren's and lists with named parameters) with embedded bits of things
with possbily their own complex syntax like XML and/or SQL.

Watch those closing curly braces, brackets, paren's, quotes, angle brackets, ...!

Though the at-sign is darn ugly. Yuk.

Have fun.

-Paul
 
R

Roedy Green

Next thing you know you'll want us to program in LISP!
But then you are old Forth programmer.

Forth uses a lot less punctuation than other languages. Everything
DOES something. Further you can pronounce it out loud and there is
even a standard short pronunciation for each operator, e.g. ' is
"tick".

C/Java assault me with parenthesis and brace nests. I have great
difficultly parsing even a 3-deep nest. Everything just starts to
swim. Perhaps it is because I have so much trouble with double
vision, and hence any repeating visual pattern. RPN is a snap by
comparison.

I have partly solved the problem with JDisplay which uses varying size
fences to emphasise the pairings. The problem is that does not work
inside the IDE.

See http://mindprod.com/projects/javapresenter.html
 
R

Roedy Green

File of = new File("output.txt");

Add the non-trivial surroundings yourself as you see fit.

That particular problem could me mechanically fixed. It is even
easier than what IDEs do for global rename since ALL "of" variables
can be changed to the same something else.

Class files continue to work since they don't care about reserved
words.
 
J

javadesigner

File of = new File("output.txt");

Nope. As I explained in the previous post, using "of" in
templates, would mean:

Type of Type
List of String

Your example would cause NO breakage since it's would not
conflict with valid generics usage at all. Just as
foo<String> does not mean the math expression: foo < String

Want to try again ?

Best regards,

--j
 
T

Tor Iver Wilhelmsen

Roedy Green said:
That particular problem could me mechanically fixed. It is even
easier than what IDEs do for global rename since ALL "of" variables
can be changed to the same something else.

Yes, but that goes for any new keyword added. If you just declare that
any introduced error can be fixed using global serch and replace, then
no syntax changes pose a problem.
Class files continue to work since they don't care about reserved
words.

.... except you can no longer refer to public identifiers in those
classes from other code using the "new" compiler.
 
T

Tor Iver Wilhelmsen

javadesigner said:
Your example would cause NO breakage since it's would not
conflict with valid generics usage at all. Just as
foo<String> does not mean the math expression: foo < String

Want to try again ?

Er, have you *any* understanding how reserved word work? I cannot use
"for" as a variable name even if it's obvious I am not using it for a
for-loop. Why do you think "of" would be treated any differently than
any existing reserved word?

For reserved words, it's not *how* they are used, but *that* they are
used. They are eaten by the lexical analysis that precedes syntax
analysis in the traditional way of writing compilers.

*That* is how reserved words differ from other syntactical elements
like < and >.
 
R

Roedy Green

... except you can no longer refer to public identifiers in those
classes from other code using the "new" compiler.

The other way to do it is not to make of a reserved word, simply a
word that has meaning in special context. This is the PL/I approach.
You merely deprecate its use elsewhere.
 
M

Michael Borgwardt

Roedy said:
C/Java assault me with parenthesis and brace nests. I have great
difficultly parsing even a 3-deep nest.

So much for the theory of you being a secret Lisp advocate.
 
R

Roedy Green

So much for the theory of you being a secret Lisp advocate.

LISP is a nightmare for me. Today was the first day it dawned on me
that everyone does not see swimming when presented with parenthesis
forests.

I just presumed people were incredibly stupid or masochistic to put up
with them.
 
P

Patrick May

Roedy Green said:
LISP is a nightmare for me. Today was the first day it dawned on me
that everyone does not see swimming when presented with parenthesis
forests.

"Swimming" isn't a bad analogy to my first reaction, especially
to the closing parentheses in a typical Lisp function, and I don't
suffer from double vision. It only took a week or two before they
disappeared from my conscious recognition, though. Give it a try for
a month, with a good context-sensitive editor, of course, and see if
you don't get the same effect.

Now if I could just stop seeing these "fnords" everywhere....

Regards,

Patrick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,097
Latest member
RayE496148

Latest Threads

Top