Java Syntax Extensions

M

Martin Gregorie

I'm with you here. I like overloading. Used in moderation it can clarify
what you're doing by making it concise. I remember that the Algol 68 R
graphics package defined a sketch (a drawable but unscaled object),
picture (scaled, ready to output) and overloaded +, so you could write:

sketch disk = circle(0, 0, 30);
sketch frame = rectangle(0, 0, 60, 30);
sketch caption = text(0, -20 "A label);
picture mydrawing = circle + frame + caption;

Works for me, anyway.
As a comparison: as much as I love the preprocessor in C (it was such a
cool idea in 1980), it's a huge mistake. It suffers from the same sorts
of abuses (sometimes worse) as operator overloading.
Agreed. Some people can make a mess. I knew a programmer who hated curly
brackets, so he always defined:

#define begin {
#define end }

Just so he could write:

int main(int argc, char **argv)
begin
printf("Hello World");
end
 
M

Martin Gregorie

PL/I and Ada95 was even more complex than C++. And even though
they are still used, then they are definitely in decline.
Yes, an PL/I is horrible, particularly in the way that it uses exceptions
for EVERYTHING including end of file and has no concept of try/catch
blocks. Sometimes you have to really hunt to find the exception handler
dealing with your problem.

I still think the best of the pre-OO languages was Algol 68.

One (minor) change I'd like to see in Java, though it will never happen,
would be to replace the 'static' keyword with something thats a better
description of its purpose - maybe 'singular' or 'unique' would be better.
'static' is confusing to those of us who write C and are used to 'static'
affecting the variable's lifetime without altering its scope.
 
J

Jussi Piitulainen

Roedy said:
That request logically does not make sense, though I agree it is an
nuisance to create the finals. I explain why at

http://mindprod.com/jgloss/nestedclasses.html#ANONYMOUSVISIBILITY

This piece of Java syntax makes me cringe.

I think it makes perfect sense. (This does not mean that I am asking
for them in Java.)

The obvious implementation would be that the compiler boxes those
local-to-method variables that the inner class instance references,
because they may need to live indefinitely.

Consider code like this, where the method user(Upper) is arbitrary:

int maker() {
int counter = 3;
user(new Upper() { void up() { ++ counter; } })
return counter;
}

It would be compiled as if it had been something like this:

int maker() {
final Box counter = new Box(3);
user(new Upper() {
private final Box b = counter;
void up() { ++ b.contents; }
});
return counter.contents;
}

The Box class would be compiler generated to match the situation at
hand (the contents field is an int). Now the inner class instance may
be live after the maker() call has returned, but that is not a
problem: instead of the forgotten stack frame it refers to the box
that still lives in the heap like any other object.

The programmer can write the latter code now. They need to write the
Box class, too, of course, so there would be a few more lines.

(No, I'm not asking for Java to do this. I'm only saying that if it
wanted, it could. I think.)
 
S

Stefan Ram

Jussi Piitulainen said:
The obvious implementation would be that the compiler boxes those

The implementation should not be too difficult as there actually
was an effort undertaken to /remove/ it from the implementation:

»Guy Steele wrote:

Actually, the prototype implementation *did* allow
non-final variables to be referenced from within inner
classes. There was an outcry from *users*, complaining
that they did not want this!«

http://madbean.com/2003/mb2003-49/
 
J

Jussi Piitulainen

Stefan said:
The implementation should not be too difficult as there actually
was an effort undertaken to /remove/ it from the implementation:

»Guy Steele wrote:

Actually, the prototype implementation *did* allow
non-final variables to be referenced from within inner
classes. There was an outcry from *users*, complaining
that they did not want this!«

http://madbean.com/2003/mb2003-49/

Amusing. Thanks. Yes, Steele should know this very well. I learnt to
think this way when I read about Scheme implementation techniques, and
Steele was one of the original perpetrators.
 
A

Andreas Leitgeb

Chase Preuninger said:
3)Operator Overloading

I wouldn't really propose it as free as in C++, but I'd
very much like it, if Java were to overload the arithmetic
operators specifically to BigDecimal and BigInteger, and
also sensible variants with different-typed arguments, like
adding 1, 1L, 1.0 or 1.0f to a BigDecimal, or just the
former two of them to a BigInteger all by use of + operator.

While free use of operator overloading as in C++ is
obviously too sharp a tool for most Java-programmers'
taste, allowing it for well selected standard Java
classes doesn't appear to me to have that downside.
 
M

Mark Space

Patricia said:
Given the capabilities of modern IDEs, I don't think it should be up to
the programmer to look for overloaded operators. An IDE could use a
different color for overloaded operators than for language-defined
operators, and a quick option to display the declaration.

Oh you *want* operator overloading? Oh no, I don't agree. Use C++ if
you must overload(*), we have a language that does that already. Your
IDE will already correctly syntax high-light C++ too. Why re-invent the
wheel?

Java has a nice interface for calling external libraries that you can
maintain in C++.


(*) Or some other language. I just looked up a list on Wikipedia. Hey!
Perl 6 has operator overloading! There's a great language to maintain!
I think they threw in the kitchen sink for you too. ;) And some web
programmer said it was really fast! Or use ALGOL! Or Fortran 90! or ...
you get the idea. There are lots of options if you must have operator
overloading. Please don't mess up Java, I like it the way it is.
 
M

Mark Thornton

Mark said:
Oh you *want* operator overloading? Oh no, I don't agree. Use C++ if
you must overload(*), we have a language that does that already. Your
IDE will already correctly syntax high-light C++ too. Why re-invent the
wheel?

Perhaps because we like other features of Java and dislike some of C++.
The problem with operator overloading is what happens when used by non
mathematicians.

Mark Thornton
 
M

Mark Thornton

Roedy said:
I could have strangled Stroustrup and his overloading of the shift
operators in C++ to do I/O. Java has the entire Unicode character
set. There are plenty of unused symbols. There is no need to overload
and confuse the meaning of the currently defined operators with
overloading.

I would like however to define new operators in Java, just as you can
in Forth, but not overloading the primitive operators, using symbols
like Circle Plus.

I find even Java's overload of + for both addition and concatenation
infuriating. see
http://mindprod.com/jgloss/gotchas.html#CONCATENATION

To the mathematician, it sounds like a good idea, but in practice,
e.g. in C++, it primarily becomes a technique for writing
impenetrable code.

It would be quite proper to overload + for Complex and interval
arithmetic in addition to the existing byte, short, char, int, long,
float and double.

Mark Thornton
 
M

Martin Gregorie

Why should Java be written in terms of C, or any other language? Why
shouldn't Java keywords appeal to former FORTRAN programmers? What
makes C so special that a different language should coddle people who
learned it, and not, say, COBOL?
I'm not saying it should be written in terms of any other language, though
it has obvious C antecedents in addition to static - such as &&, || and
the 'main' method.

My objection to Java's use of static is primarily it doesn't really do
what it says. Something else, such as 'singleton' would be more
descriptive. However, I'm not holding my breath for this suggestion to be
implemented: its only intended as a minor innerlekchewal hand grenade.
 
A

Arne Vajhøj

Roedy said:
Good. :) That would discourage frivolous use, and would encourage
proper tools for writing international code.

I strongly disagree.

It is a good thing to be able to write Java code in
notepad or vi if necessary.

Arne
 
A

Arne Vajhøj

Martin said:
Yes, an PL/I is horrible, particularly in the way that it uses exceptions
for EVERYTHING including end of file and has no concept of try/catch
blocks. Sometimes you have to really hunt to find the exception handler
dealing with your problem.

I still think the best of the pre-OO languages was Algol 68.

Modula-2 looked rather nice also.

Arne
 
A

Arne Vajhøj

Patricia said:
However, the combination of a very limited set of primitive arithmetic
types and the lack of operator overloading also risks increasing the
difficulty of code maintenance - or forces people to avoid Java for
anything that has non-trivial arithmetic expressions in any types other
than the Java numeric primitives.

Operator overloading is very rarely needed. Basically only when you
create custom numeric types. But in that case it really makes
the code much nicer.

So we have two opposite requirements: make custom numeric types
easier or keep the language simple.

At least if they added operators for BigInteger, BigDecimal and Complex
then I would prioritize the simpleness.

But I can understand if people doing numerical stuff has different
priorities.

Arne
 
A

Arne Vajhøj

Lew said:
Why should Java be written in terms of C, or any other language? Why
shouldn't Java keywords appeal to former FORTRAN programmers? What
makes C so special that a different language should coddle people who
learned it, and not, say, COBOL?

It should not.

But I agree with Martin that static is not so great a word.

The english meaning and its Java meaning are not that close.

Nut it is a rather pointless discussion, because it will
never change.

All C++, Java and C# programmers know what static is.

Arne
 
M

Mark Space

Arne said:
At least if they added operators for BigInteger, BigDecimal and Complex
then I would prioritize the simpleness.

But I can understand if people doing numerical stuff has different
priorities.


I'd like to see some kind of specialized language that compiles to
..class files, then use Java for the mundane things like networking, web,
SQL and plain IO.

That would be the best of both worlds, imo. But not trying to import
every grammar under the sun into Java, please never that.

Here's a MATLAB product that compiles to Java .class files, btw.

<http://www.mathworks.com/products/javabuilder/>

This seems to me to be a more useful direction.
 
L

Lasse Reichstein Nielsen

Martin Gregorie said:
My objection to Java's use of static is primarily it doesn't really do
what it says.

Sure it does :)
Or rather, what do you think it says it does?

A field, method or class defined without "static" lives in instances
of the class it is defined in. Which object it belongs to, i.e., how
a reference to it is resolved, depends on runtime information. It is dynamic.

A field, method or class defined as static exists at the class level.
A reference is resolved at compile time. I.e., it is static.

It all depends on what you think "static" means.
Something else, such as 'singleton' would be more descriptive.

Not really. Singleton is a pattern (some would say an anti-pattern,
I'd say it's just a degenerate enum). I.e., it is a recipe for
achieving a specific goal using object oriented modelling.
A traditional singleton will not allow you to change the
singleton instance. A (non-final) static field, would.

/L
 
H

Hendrik Maryns

Martin Gregorie schreef:

innerlekchewal

Nice, took me a while to figure it out, but then I made this:
http://en.wiktionary.org/wiki/innerlekchewal. I took the freedom to
correct the spelling error.

:) H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFIBcqle+7xMGD3itQRAkPNAJ0Y4WpCNeYcfel1bVq8Xe8dOLeyhgCfdR5G
lDhBlX8fV32qGLDIHSL9Mms=
=5ldL
-----END PGP SIGNATURE-----
 
H

Hendrik Maryns

Lew schreef:
Shouldn't a word be in use by more than one person in order to merit
inclusion in the dictionary?

You’ve got a point. Sometimes I am a bit too enthusiatic. I’m unsure
where it would belong, if at all, I’ll start a discussion there.

H.
--
Hendrik Maryns
http://tcl.sfs.uni-tuebingen.de/~hendrik/
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFIBfREe+7xMGD3itQRArb/AJ9J5IuHHT/DC4kvXkVSqXOtNDC6jgCcCDxF
KAOJxHq+10hcktTDXbVM4YY=
=z1ql
-----END PGP SIGNATURE-----
 
W

Wojtek

Martin Gregorie wrote :
sketch disk = circle(0, 0, 30);
sketch frame = rectangle(0, 0, 60, 30);
sketch caption = text(0, -20 "A label);
picture mydrawing = circle + frame + caption;

Works for me, anyway.

Masive confustion here.

picture mydrawing.place(circle).place(frame).place(caption);

Makes more sense. Well to me anyways.

I absolutley HATE operator overloading. Because the programmer can make
any symbol do any arbitrary thing. Yes, yes, there are guidelines.
Which every programmer always follows. Right? Right?

So someone is able to write your example as:
picture mydrawing = circle * frame * caption;
picture mydrawing = circle >> frame >> caption;
picture mydrawing = circle << frame << caption;
picture mydrawing = circle \ frame \ caption;
picture mydrawing = circle ^ frame ^ caption;

The only way to figure out what the operator is doing, is to read the
source code of the object.

And yes, a Java programmer can mis-name the methods. But that would be
a deliberate attempt at confusion.

Whereas some of my examples look reasonable.
 
M

Martin Gregorie

Sure it does :)
Or rather, what do you think it says it does?
I'm referring to static variables, not other uses which more or less do
what they say.

The problem is that declaring a variable as 'static' doesn't really
indicate that its common to all instances of the declaring class as well
as containing a persistent value.

The same argument applies to C, where 'persistent' would be a better
modifier than 'static', because thats really what 'static' means in that
language.

In Java 'static' could usefully be replaced by 'singular' or 'common' to
indicate that the variable is accessible from several class instances.

I think this is something that all language designers have tripped over:
IIRC in Algol 60 the modifier was 'own', which is really obtuse.
 

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,785
Messages
2,569,624
Members
45,318
Latest member
LuisWestma

Latest Threads

Top