In comp.lang.java.advocacy, Tor Iver Wilhelmsen
<
[email protected]>
wrote
Well, there are a few problems I can readily identify in Java; these
are either bugs, warts, missing, or just par for the course.
Most of these don't seem that bad or
[W] int vs. Integer, float vs. Float, boolean vs. Boolean. Boxing
helps but is a band-aid.
I'm for a purer object model also but C# does the same thing, doesn't it?
[W] Call me a purist, but encouraging expensive operations in Java is
not good; an example of course is List.get(int). Granted, this is
always possible, but the C++/STL implementation makes more sense.
Well, no one makes you use it. :> If I need to look at all the elements,
I'll iterate, but sometimes you just know what you need.
There's also java.util.RandomAccess, to confuse/add/assist.
Is this really any different that the std::iterator_traits. Both are ways
of letting you know the capabilities of the collection so you can pass
them along optimized code paths.
[?] Are the non-byte datatypes fixed-size?
Not sure what you mean. I believe that int,long, double and the like are
all fixed size.
[P] The Enumerator/Iterator dichotomy doesn't look necessary.
Evolution in action. We have redundant DNA code also. Enumerator is
almost missing in the current docs.
[W] AWT and Swing work well enough together but do we really need
both?
Again, change happens. AWT came first and was roundly criticised for not
providing a good cross-platform solution. So in comes Swing. But you
can't just drop support for AWT without killing all your previous code.
All you can do is encourage people t move away.
[W] [].length vs. String.length() vs. Collection.size(). Can we
clean this up?
Why? Conceptually, I see a difference. Arrays and Strings are linear.
Collections are not. What is the 'length' of a HashMap?
[W] a.equals(b) requires that a be non-null.
I tend to declare things as I instantiate them, both in C++ and my rare
ventures into Java, so I cannot remember this ever being a problem. At
least for me. In the odd case where it shows up, it is almost certainly a
bug that a was being accesed and I forgot to init it.
[W] "".equals(null) returns false. Granted, maybe they're supposed to
be unequal, but one wonders if there shouldn't be an
equalsNullIsEmpty(), at least, ugly as that is. Most people ensure
Strings are non-null so this isn't that big a deal but it is annoying.
equals is documented as having certain behaviors. One of them is that:
"For any non-null reference value x, x.equals(null) should return false."
Maybe it is thing that comes from working with Databases but null strings
and empty strings are completely different to me. And I cannot imagine
what would cause me to type "".equals(null). if I really needed it:
boolean equalOrNull(String a,String b){
if(a==null || a.equals("")){
if(b==null || b.equals(""))
return true;
else
return false;
}
return a.equals(b);
}
Could be put somewhere for use.
[W] Various protocols in J2EE assume a mapping of xzy -> getXyz,
setXyz. Unfortunately, class is a reserved keyword, although
getClass() exists. In a way, that's good news, as that means
getClass() isn't available for the casual user and he would have to
use things such as getDefiningClass(), getClazz(), or other such junk.
Having never done J2EE I cannot comment.
[?] I'm not sure about catching run-time exceptions such
as NullPointerException and IllegalArgumentException.
It's convenient to catch them, of course, print the
traceback, and keep the app from dying. However, it also
is probably being misused. How to prevent this, I for one
don't know; I doubt C# has a much better solution here,
and I certainly do not.
Don't catch them. OK, that isn't completely what I think. I do think that
RunTimeExceptions are usually the result of bugs and it is better to fix
the bug that caused it than to try and handle after the fact.
[P] java.io.Serializable should have generated XML from the
beginning. Of course there's the little issue of timing;
I don't think Java, in its alpha stages, knew about XML.
Ditto for java.rmi.
I'm no big fan of XML. I cannot see why you should require its use for
Serialization. Binary is more compact and in many cases, less costly to
use.
And as you said, XML was appearing at the same time as Serialization.
[P] It is possible that Java.io.File et al could have
avoided some silliness by pathname translation -- in other
words, '/' is always the path delimiter, and there is
only one root, so that G: would be mapped to, say, /g.
However, there's the flip side of possibly requiring
escapes for certain characters in that case. For instance,
old MacOS pathnames were delimited by ':', which means a
':' in a MacOS jvm under this new scheme would have to
be very carefully handled; in the current scheme nothing
really special needs to be done but the app might have
to wonder why it gets a directory not found condition or
strange pathnames such as 'c:\application\data\path'.
OK, you just alienated everyone that is used to a different convention.
File.separator and File.pathSeparator are always the setup. It really
isn't that hard to do but it does require you to think about multiple
platforms.
[M] The "webbrowser" of javax.swing.JEditorPane has
many problems. Ideally, it would understand XML by
now as well, and, with additional machinery (xalan,
probably), preprocessing instructions. As it is, it can
understand HTML and some CSS constructs, and now isn't
quite as stupid as it was with the <link/> construct.
Embeddable local objects is a plus, but not understanding
applets is a minus. It is possible Java will eventually
simply punt on this issue to more capable hands such as
FireFox and a local text editor. It is also possible
Java will allow integration of Firefox and editor widgets,
for a seamless-looking GUI.
As I said, I am not that into XML and haven't needed to embed fancy HTML
in my GUI. This item does what little I need and I am not sure dragging
in a more complete but larger engine would be justified for most apps.
They do claim to be moving toward HTML 4.0 support.
And aren't there problems with the <applet> tag in some browsers? The doc
do say the <object> is partially supported. Wonder what would happen if
you had an applet that displayed a JEditPane that displayed the Applet.
[M] A PDF Swing viewer would be nice. There might actually
be one, but if so I'd have to find it; it's not part of
Java currently. RTF, strangely enough, is.
PDF was a proprietary format. I don't know what its current status is.
[M] Built-in support for ASN.1 would be nice as well.
Admittedly, ASN.1 has apparently been relegated to "just
for SNMP traps", despite the fact that ASN.1 can in theory
replace RMI entirely, much like SOAP. Watch this space.
No Comment
[P] Is there a good reason why Runnable.run() can't throw
a Throwable? (Apart from the perhaps obvious one of
trying to disentangle Throwables in the calling thread,
which are not thrown by the calling thread?)
Just where would you catch it? The code in your launching thread could be
anywhere when the Runnable throws. So even if the Exception carried some
info that told it what thread it came from, you would either no call
stack for it to unwind or it would arive at whatever random place you are
currently and it would be very ugly to have to code everywhere for the
possibility of any exception.
[P] ThreadLocals are interesting. Are there better
methods by which a Thread can have its own value of certain
statics? For example, a Thread might extend Comparable,
allowing Threads to be put into the key side of a Map.
Of course the user could implement that himself, but this
is a little weird.
I would not be surprised if something similar was not done behind the
scenes by ThreadLocal.get/set. Sometimes you need threadlocal variables.
[?] Is java.lang.ThreadDeath going away anytime soon,
since the only method causing it is deprecated?
Not until that deprecated method is removed. What would you do if it went
away but the generating method remained?
[?] Point2D is a little strange since it assumes double instead of
java.lang.Number in various areas.
There's probably more but this already grows overlong.