Max Lybbert
Posts: 314
Nickname: mlybbert
Registered: Apr, 2005
|
|
Re: Why I don't like Java
|
Posted: Feb 13, 2007 8:59 PM
|
|
Let me try again.
/* [Me] But you cannot create a program without classes. You can't create a function outside of a class. You can't write a program without creating a class with a public static method named Main(). I don't know of any technical reason for this; it's just what Gosling says good programmers must do, and all Java programmers take him at his word.
[Response] Is there something specific about this that causes problems? It's just the way the language is structured. I can't create python code outside of a module. It's not clear why this is a pain-point to me. */
Today I wrote a ten-line Perl script that reads a comma-separated file and, after massaging the data, puts that info into a database. Most of those ten lines had to do with ODBC.
If I wanted to write a similar Java program, I'd need to create a scanner class to read the file, a transformer class to take the string from the scanner and massage the data, and then I'd cry because I'd need to write JDBC code. I suspect it would take fifty lines of code to do that, and fifteen of those lines would be needless infrastructure (class declarations, opening and closing braces).
The problem I was solving was an imperative, or at the least declarative problem. And Java lets me write imperative and declarative solutions, so long as I filter them through OOP first.
Of course, Perl lets me write OOP code when I want to; but doesn't force me to write that code when I don't want to.
Anyhow, writing fifty lines of code to do a ten-line job is a pain point similar to water torture. You slowly burn out typing the same thing over and over.
The issue about "public static void main" is that it must be in a magically-named file (named after the class). I can't name a file try.java, because "try" is a keyword and can't be a class name. I can't name a file 1.java, or 1goodTest.java because those aren't valid classnames. There's no technical reason for this restriction, it's just how things are.
/* Classes aren't Objects and static methods in Java have basically nothing to do with OO. */
That detour was my attempt to understand what you meant by "you don't need to create Objects." I misunderstod you, and so we can disregard that.
Although.
I want to transform data from my scanner before putting it in the database. I don't think those methods "belong" in the scanner class because the scanner's job is to read in data, not process it. So I create a class, and give it some forgetable name. I then realize that I don't need to create objects of type "transformer," so I make every method static. I don't see why this is better than simply having free functions like every other language has. Java programmers I know can never figure out why I would want methods not attached to classes: "the almighty Gosling says that this is the One True Way and Any Other Way would Confuse Programmers."
/* In any event this seems more like a complaint that you would aim at SmallTalk or other language where everything is truly an Object. */
I don't have any experience with Smalltalk. I plan on getting some after I really feel comfortable with Lisp and Felix ( http://felix.sourceforge.net/ ). /* You can argue that this requires a lot of verbose boilerplate but that really has nothing to do with OO. */
Yes, water tortue style verbosity. No, it's not OO per se. But it's the "Java is an OOP language *only*" problem. Want to write something in another style? Tough luck. you can only do that if you can convert it to OOP.
/* [me] I don't want pointer arithmetic so much as I want access to raw pointers or references. I don't want to have to remember the details about when the implementation will pass things by value and when it will pass things by reference. Instead I want to be able to control that.
[Response] There's not much to remember. Everything is passed by value. I can't think of how it could be any less complex than that. */
My mistake. I run into issues trying to remember if Java does deep copy of objects and shallow copy of primitives or vice versa (that is, when can I say x = y, and when do I have to say x.member = y.member; x.otherMember = y.otherMember; ...). The rules seem to be based on the implementation. That is, Java 1.0 did it this way because of how Java 1.0 was implemented, therefore all versions of Java shall forever do it this way.
/* [Me] I realize Java may well have listened to C++ on [having different syntax for static and regular methods] and decided against [doing so], but I find beginning programmers get confused between when you can call static methods and when you can call regular methods.
[Response] This is a valid complaint. The Eclipse IDE will warn you when you are calling a static method as if it were an Object method for this reason. ... On the other hand it's not a problem that I've seen come up much. I can't recall any bug that I ever seen being caused by this. */
It doesn't lead to bugs, per se, but compile time errors. And then the programmer comes to me saying "I'm writing this static method, and I want to call this non-static method, and the compiler won't let me." Then I've got to explain things. It's a pain point to me to have to teach other programmers to distinguish between two different thing that look identical (called through the dot operator). /* [other gripes I have about Java] [Response] I'm going to assume this is back to RAII. Personally I think RAII is overrated. I also think that the downsides of RAII are understated by it's proponents. */
Not RAII, per se. It's about the language designer putting in finalizers, selling them as being useful for RAII, and not realizing the garbage collector would muck up any attempt to use finalizers for their intended purpose. Finalizers were not thought out, and I have never seen a good use of them in Java.
Finalizers should be pulled from modern releases of the language. You can't guarantee when they'll run, or if they will ever run. So they are nothing more than a function the system may or may not call automatically. And they have the special case that they can resurrect the object, and the system promises not to call the finalizer the next time it collects the object. That's a lot like Javascript (as a dynamic language) sometimes doing type coercion on numbers to make them strings behind your back.
And since finalizers don't do the job for you, yes, another pain point is remembering to write the needed try { ... } finally { ... } blocks.
|
|