What would you like to see in Java?

Again, I’m too lazy to yet again state how horrid is it not to have operator overloading. The brush strokes are: “People can write bad code”. That happens the moment a language has the complexity of a macro assember…so you’ve already failed to nanny them. “I don’t want to look at badly written operators”. Then don’t…why would you want to look a badly written code anyway. “But it’s at work”. Somebody’s not doing their job then…hopefully it isn’t you.

The bottom line is that, yeah operator overloading can be used to make horrid things. The flip side is that without operator overloading any mathematical type which isn’t natively supported by the language will be insured to be horrid. Do the math. Oh yeah and limited operators? Once you get past reals and integers…that tiny set of operator symbols make the feature bordering on useless. Besides most of the “issues” with bad operators in C++ would be a non-issue in java. An IDE would decorate differently and you’re just a click away from implementation.

Oh and: ACCESSORS. If the VM supported accessors where would be much happiness…the rest is just sugar.

Structures is a real biggy for a long list of reasons…to lazy to repeat.
Templates…you really want macros (no not preprocessing macros). To be practical would need a new transport IR…which would be awesome for a long list of reasons…again too lazy to repeat.
manual memory management: you don’t need it if you have structures and arrays of structures.
methods that return more an one thing: structures again.
pointers: Your point (yuck yuck) isn’t clear…why?

I’m a bit pampered by PHP but I’d like to name my array keys. One other thing is Java2D. It’s fine the way it is, but sometime I’d like to style it with CSS. It would be so much easier than calculating each and every coordinate.

You’re right, I want macro’d classes/methods.

This is true, I wanted memory management because there can be such a large volume of objects the JVM has to check for garbage collection that it shouldn’t have to because I know exactly when I want it deallocated.

Yeah, didn’t realize the overlap.

Hmm at first it’s because I wanted a chunk of data and have the ability to cast any point in that memory to any data type… then I realized you can do this with ByteBuffers (which are nicely “compiled” down into very efficient code) and having structs would also make pointers useless.

I also want some things added to the language that would make some nice syntactic sugar… like a nice clean way to instantiate and populate maps… and instantiating objects while setting they values. Meh.

Say you have a function that returns a pair-of-integers. That’s effectively a structure in the caller’s frame.

Not language feature, but this would be very useful in IDE like Eclipse or NetBeans: ability to visually “merge” superclass fields and methods in class you currently edit.

Oh yeah, I forgot unions.

That would make color implementations sexy.

You don’t need unions…you need SIMD, which allows for a subset of unions and is then acceptable. Which again means structures.

From James Gosling (the father of Java)
“I left out operator overloading as a fairly personal choice because I had seen too many people abuse it in C++…Then there’s a community of about 10 percent that have actually used operator overloading appropriately and who really care about it, and for whom it’s actually really important; this is almost exclusively people who do numerical work, where the notation is very important to appealing to people’s intuition, because they come into it with an intuition about what the + means, and the ability to say “a + b” where a and b are complex numbers or matrices or something really does make sense.”

A lot was done on C++'s account, and Java appealed primarily to C++ users when it arrived.

There is no reason you can’t replace << with write, >> with read, + with add, - with subtract * with dot (or cross?)

It’s just ascii art. You aren’t an ascii artist, you’re a programmer. There is no reason in hell for us to be throwing ascii art into our code.

Do people actually like “<<” and “>>” in C++? I thought that was the dumbest thing. C was doing just fine with printf/scanf and the variants.

That’s the thing about languages like C++ and Perl: How hard can language design be? Let’s toss together features from various places and keep the “familiar” syntax…what could go wrong? Everybody uses redirection in shell scripts…so that’s how it should look in my grab-bag language to communicate with a stream. I’m so awesome!

No, it wasn’t. printf and the like are fundamentally type-unsafe and not extendable. You can scribble all over memory by accidentally mis-matching your format code and the actual type you pass it. And you’re limited to the built-in type formatting that the functions support.

C++ streams and the insertion (<<) operator is always type safe, and you can override the insertion operator per-type to provide custom formatters (much like Java does with toString(), but more generically). The only disadvantage is the different syntax, and once you’ve used it for a while both become equally natural.

I’m literally only talking about the syntax, mate. I’m saying C was fine without special IO operators. C++ could have just as easily accomplished what “<<” and “>>” do with simple function names.

Err…ninja’d.

Not without either horrible resulting syntax, or a reduction in functionality.

The syntax would just be a function name? How that looks horrible to you, I don’t know.

cout(string);
coutf(string, …);

Then again, I would just name them print/printf. Either way. That’s just as clean as any method.
And what can those operators do that you can’t do in a function?

Either way. It’s preference. I’d prefer a function. You’d prefer the operators. This thread is about what we would like. (Though, in Java, but that’s beside the point).

ostream.put(foo).put(bar).eof();

But this really isn’t what operator overloading is about anyway.

A simple Sound library like:


Sound mySound= new Sound();//create new sound
mySound.load("/bang.ogg");//load sound many different file types
mySound.play(23);//loop 23 times
if(mySound.isPlaying()==false){
//do something
}

That’s not (in C++ land) equivalent functionality. The use of an operator allows for the conversion to string to be overridden per-type in a non-member function and in a way that decouples it from both the stream code and the type that’s being output.

Java gets around this by saying “everything is an Object, and all objects have toString()”. Even then it’s not functionally equivalent since it tightly links the formatting of an object to the type’s definition (which is not always desirable). And only works because the language has an implicit understanding of how + works for strings and how that is mapped into a toString() call. ie. it’s a single specific case hardcoded into the language, whereas the C++ streams system is constructed entirely with language features available to any developer.

Getting really off topic here, and maybe this is simple, as I haven’t really touched C++ in ages, but…

One advantage printf() seems to have over e.g. std::cout is localization, particularly positional parameter substitution. For example, if I have a message template like so:

English: “Hello, {0}!”
Other-Language: “{0} xcvlxcvj!”

It’s easy enough to handle this with a printf call:


printf(template, param);

But how is this sort of thing handled with C++ streams?

Would be nice to have string interpolation in Java.