Sign in to follow this  
DanLatimer

[java] Java is my friend

Recommended Posts

tebriel    904
Disclaimer: I'm not a C++ bigot, I am Java-friendly...buuuuut...

Where's the part about Java's memory usage bringing your machine to a halt? :)

Share this post


Link to post
Share on other sites
Darragh    308
Quote:
Where's the part about Java's memory usage bringing your machine to a halt? :)


I think even Shakespear would be hard pressed to make peotry out of that![smile]

To garbage collect or not to garbage collect, that is the question...

Hmmm....

Share this post


Link to post
Share on other sites
CaptainJester    523
Quote:
Original post by johnhattan
I like Java.
I'd never uninstall.
Its programs won't destroy my computer,
Because they barely run at all.


It's pretty sad when a staff member trolls.

Share this post


Link to post
Share on other sites
jsgcdude    250
Quote:
Original post by CaptainJester
Quote:
Original post by johnhattan
I like Java.
I'd never uninstall.
Its programs won't destroy my computer,
Because they barely run at all.


It's pretty sad when a staff member trolls.


In this case, How can you argue it's allowable? See 3/16/2004 entry. John's earned the right to say wtf ever he wants about java... imho of course.

Share this post


Link to post
Share on other sites
DanLatimer    139
Quote:
Original post by johnhattan
I like Java.
I'd never uninstall.
Its programs won't destroy my computer,
Because they barely run at all.


lmao your poem works too heheh

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Quote:
Original post by jsgcdude
Quote:
Original post by CaptainJester
Quote:
Original post by johnhattan
I like Java.
I'd never uninstall.
Its programs won't destroy my computer,
Because they barely run at all.


It's pretty sad when a staff member trolls.


In this case, How can you argue it's allowable? See 3/16/2004 entry. John's earned the right to say wtf ever he wants about java... imho of course.



Ah...you mean, because he doesn't know how to read documentation plain and clear he has the right to troll? Um, OK. Shrug.

Share this post


Link to post
Share on other sites
tebriel    904
Well the argument he's making is that Java's "libraries" are a mess. And really, I think most people would agree with that statement.

How about:

I don't want to cause any drama,
I but I really can't stand Java,
Because to play a first-person-shooter,
I'd need a super-computer!


Ok, so it's not entirely true, lighten up, it's funny!
[lol]

Share this post


Link to post
Share on other sites
tebriel    904
Java is the best,
To meet your deadline unstressed,
Because your project would go slowly,
If you had to use C only!


Ok, not as good, but I tried.

Share this post


Link to post
Share on other sites
johnhattan    2346
Quote:
Original post by Anonymous Poster
Quote:
Original post by jsgcdude
Quote:
Original post by CaptainJester
Quote:
Original post by johnhattan
I like Java.
I'd never uninstall.
Its programs won't destroy my computer,
Because they barely run at all.


It's pretty sad when a staff member trolls.


In this case, How can you argue it's allowable? See 3/16/2004 entry. John's earned the right to say wtf ever he wants about java... imho of course.



Ah...you mean, because he doesn't know how to read documentation plain and clear he has the right to troll?
Exactly. Trolling is a right that I've justly earned.

That being said. . .

I really do like Java.
Please don't think me a jerk.
Everything's got eight function calls.
And one of them will work.

Share this post


Link to post
Share on other sites
Aldacron    4544
Quote:
Original post by johnhattan
Trolling is a right that I've justly earned.


But code like this (taken from the referenced blog entry) earns you nothing but the Common Noob Mistake award: Answers.addElement(new String("")); [embarrass]

I know you're not a noob coder and this is not a flame, but that's as big a noob mistake in Java as there is. Two cookies to the first who can explain why!

Share this post


Link to post
Share on other sites
averisk    146
Quote:
Original post by Aldacron
Quote:
Original post by johnhattan
Trolling is a right that I've justly earned.


But code like this (taken from the referenced blog entry) earns you nothing but the Common Noob Mistake award: Answers.addElement(new String("")); [embarrass]

I know you're not a noob coder and this is not a flame, but that's as big a noob mistake in Java as there is. Two cookies to the first who can explain why!


This has the same effect and is more clear:
Answers.addElement("");

Though I'm not sure that's what you were getting at

Share this post


Link to post
Share on other sites
Aldacron    4544
Quote:
Original post by averisk
This has the same effect and is more clear:
Answers.addElement("");

Though I'm not sure that's what you were getting at


Well, you've got the code right, but not the reasoning behind it. It isn't the same at all. Only one cookie for you.

Share this post


Link to post
Share on other sites
averisk    146
Quote:
Original post by Aldacron
Quote:
Original post by averisk
This has the same effect and is more clear:
Answers.addElement("");

Though I'm not sure that's what you were getting at


Well, you've got the code right, but not the reasoning behind it. It isn't the same at all. Only one cookie for you.


Well it's more efficient too, but I don't think by much

Strings are immutable, so there's no reason the String copy constructor can't use the same memory given to it by the passed String
So you'd be saving a function call and a pointer assignment

Please correct me if this is incorrect

Share this post


Link to post
Share on other sites
johnhattan    2346
Quote:
Original post by Aldacron
Quote:
Original post by johnhattan
Trolling is a right that I've justly earned.


But code like this (taken from the referenced blog entry) earns you nothing but the Common Noob Mistake award: Answers.addElement(new String("")); [embarrass]

I know you're not a noob coder and this is not a flame, but that's as big a noob mistake in Java as there is. Two cookies to the first who can explain why!
Yep, that's the price I pay moving from a language where the parser doesn't consider some variable types to be more equal than others (i.e. C++). Although given that any space taken by the extra string (assuming that Java's string class is smart enough not to split until written to, which I have no idea) will eventually be garbage collected out of existence, the upshot is that there'll be the storage taken up by an empty string in the variable table until the garbage collector's next sweep.

And in the case of the applet I was writing, it makes not one whit of difference.

The point of the code was not to illustrate how to properly avoid calling the copy constructor an extra time but that someone on the Java team showed up one morning and said "Hey, I've got a terrific idea. Let's write a second add-to-vector function that's exactly like the one that's already there, but won't work on earlier VM's" and wasn't immediately fired for the suggestion.

And no, documenting it doesn't solve the problem. If you bought a new car and found that the functions of the gas and brake pedal are reversed on alternate Wednesdays, would you consider that an acceptible behavior if it was documented in the owner's manual?

Share this post


Link to post
Share on other sites
Aldacron    4544
Quote:
Original post by johnhattan
The point of the code was not to illustrate how to properly avoid calling the copy constructor an extra time but that someone on the Java team showed up one morning and said "Hey, I've got a terrific idea. Let's write a second add-to-vector function that's exactly like the one that's already there, but won't work on earlier VM's" and wasn't immediately fired for the suggestion.


Yeah, that's understood. But the point I'm getting at is that sometimes, seasoned programmers, when moving from one language to another, are not quick to learn the intricacies of the new language before dismissing it. Most often people try to fit a common solution learned in the old language to the problem at hand, but fail to take into account that it might not be the best approach in the current language.

As to the Vector bit, sorry but that's weak. The Collections framework was an improvement over the earlier Java containers, and the decision was made to retrofit Vector into the new framework (via the List interface) while maintaining compatibility with existing code. It's called refactoring, and every project goes through it at one time or another. I know many a Java developer who would love nothing more than for Sun to remove deprecated code from the library. It's anyone's guess when that will be, if ever.

Quote:

And no, documenting it doesn't solve the problem. If you bought a new car and found that the functions of the gas and brake pedal are reversed on alternate Wednesdays, would you consider that an acceptible behavior if it was documented in the owner's manual?


What's that got to do with the price of beans in Japan? Software evolves. Sometimes we have the luxury of breaking backwards compatibility, sometimes we don't - particularly when the software is used in critical systems. And when the software does change, we document it clearly so that clients can understand what's new, what's different, and what's recommended. Does anyone complain that each new release of DX is backwards compatible with older versions? It's supposed to be a good thing.

Share this post


Link to post
Share on other sites
Aldacron    4544
Quote:
Original post by averisk
Strings are immutable, so there's no reason the String copy constructor can't use the same memory given to it by the passed String
So you'd be saving a function call and a pointer assignment

Please correct me if this is incorrect


It's in the spec (3.10.5 String Literals). Instances of literals are created only once. When another identical literal is declared anywhere in the projram, it references the same instance. However, String objects created with new are created at runtime, which means each time the code is called a new instance is created.


String s = "";
String t = "";
String u = new String("");

// s, t, and the argument to the constructor all reference the same instance,
// but u itself is a new instance.

Vector v = new Vector(250);

// this code creates 250 string instances and adds them to the vector
for(int i=0; i<250; ++i)
v.add(new String(""));

// this code adds to the vector 250 references to the same instance
for(int i=0; i<250; ++i)
v.add("");



So there's a big difference between the two - the first case uses 251 object instances (the literal + the 250 new Strings) whereas the latter only uses 1. That's why you should get into the habit of avoiding the use of new String("something"). If not, you might unknowingly do something silly with it one day that costs you hours of debugging.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this