I've heard it takes forever to grow a woman from the ground
I've heard it takes forever to grow a woman from the ground
I've heard it takes forever to grow a woman from the ground
I've heard it takes forever to grow a woman from the ground
I've heard it takes forever to grow a woman from the ground
Originally posted by Joseph George:
also, forgive a poor fool's question: what's an anti-pattern?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
42
Originally posted by Joseph George:
I'm a lazy man, and i LIKE not having to type GameCodes.PEON.
SO...
What is wrong with that?
Originally posted by Warren Dew:
You'll spend half an hour tracing through the code figuring out it came from the "GameCodes" interface six steps up the inheritance hierarchy, when if you had just spent the extra 30 seconds typing "GameCodes."
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Joseph George:
No, you would never make an array of GameCodes, the very idea is preposterous.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I've heard it takes forever to grow a woman from the ground
Originally posted by Jeroen Wenting:
A better alternative to putting a load of constants in an interface is putting them all in a class (might even be possible to make it abstract, I'd have to check) as static final members.
I'm Joe, the Programming Jerk. I'm the only one working on this project. I don't make anything private, I'd only be restricting myself. I don't comment my code, because I know what it all does, and if you can't figure it out, maybe you should go read HelloWorld. And as for interfaces, I can tell Joshua Bloch where he can stick his contracts, I'll use them anyway they work. I use the Eclipse editor, it will tell me where PEON came from.
direct me somewhere I may learn about Typesafe Enums?
Unless you use a modern IDE, which will tell you in a matter of seconds.
I also disagree with someone who earlier said constants are allowed in interfaces because they allow you to specify contracts. It's just as easy to stick those constants in a separate final class and refer to them from the interface, and that's a more appropriate place for them even in that case...that is, if you expect anyone to extend your interface.
Originally posted by Warren Dew:
Actually, I use an IDE with that feature, and I still don't use the feature. It doesn't take that long for matters of seconds to add up to half an hour or an entire weekend when you have tons of constants like "PEON" and "LEUCOUS" hanging around.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I'm Joe, the Programming Jerk. I'm the only one working on this project. I don't make anything private, I'd only be restricting myself. I don't comment my code, because I know what it all does, and if you can't figure it out, maybe you should go read HelloWorld. And as for interfaces, I can tell Joshua Bloch where he can stick his contracts, I'll use them anyway they work. I use the Eclipse editor, it will tell me where PEON came from.
I see four options here, regarding Joe's future.
1. He'll forever be a Programming Jerk, that is - as long as he's able to switch jobs every six months or so, when the team-leader discovers that he knows < 0 about Object Oriented programming, and fires him.
Originally posted by Greg Reinl:
Joshua Bloch's Effective Java, Chapter 5, item 21.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Joseph George:
I don't make anything private, I'd only be restricting myself.
I don't comment my code, because I know what it all does, and if you can't figure it out, maybe you should go read HelloWorld.
And as for interfaces, I can tell Joshua Bloch where he can stick his contracts, I'll use them anyway they work. I use the Eclipse editor, it will tell me where PEON came from.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Ilja Preuss:
Which begs another question for me: How often *do* you want to know where a constant comes from, and why?
Just curious...
I've heard it takes forever to grow a woman from the ground
Tony Morris
Java Q&A (FAQ, Trivia)
I've heard it takes forever to grow a woman from the ground
Originally posted by Tony Morris:
This is a flawed approach.
You want the Typesafe Enum Pattern.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Originally posted by Warren Dew:
For me, every time I read one.
I mean, suppose you see "PEON" in a piece of code. What does it mean?
To me, "peon" might be appropriate as a class name, or as a variable name (in a function that deals with one peon at a time), but as a constant?
Is there only one peon in the game, so that it can be a constant rather than a class? Or is it, most likely, an arbitrary constant for use with some class, function, or interface?
If the latter, then I can't know what's going on just by reading the code. Only if it's preceded by a class, interface, or other namespace name am I going to have a clue what it's really there for.
If the "PEON" example doesn't work for you, consider the constant "MAX_VALUE". Is it 3.4E38, or is it 9223372036854775807, or is it 2147483647? If I type "PI", will I get Math.PI, which is a double, or will I get some other PI, which may have a different accuracy? Fortunately, Java's built in constants are set up in a way to discourage this, but if they were defined in interfaces rather than classes, and people implemented those interfaces to 'save typing', that's what would happen.
Not to mention that, from an OO standpoint, what does it mean for, say, a Spaceship class to implement a bag of constants contained in an interface named, say, FloatConstants? I doubt that the class satisfies an "is a" relationship.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I've heard it takes forever to grow a woman from the ground
Originally posted by Joseph George:
However, it seems to me that all this will be a moot issue with the release of 1.5. When is that scheduled for, anyway?
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Originally posted by Ilja Preuss:
For example, if I have a FooToXmlWriter and a FooFromXmlReader, it's likely that I need to use the same tag names in their implementations. Defining them as Typesafe Enums would be strange.
That's a matter of appropriate naming, not of implementing constants from an interface. Constants. MAX_VALUE is much less helpfull than MAX_INT_VALUE.
And I contend that having my class inherit from java.lang.Integer just so I can type 'MAX_VALUE' instead of 'Integer.MAX_VALUE' and save keystrokes - which is cognate to what the original poster is suggesting - is an atrocity, even if I don't violate the Liskov Substitution Principle.
I've heard it takes forever to grow a woman from the ground
Originally posted by Joseph George:
An atrocity, eh?
sort of like what c++ programmers call java, because java does endless extraneous work that used to be done by the programmer?
Originally posted by Roger Chung-Wee:
Why would you wish to pollute your implementation class's namespace and tell the world that you need these constants? Your data should be kept private!
If you failed to do this and you had had your top level class implementing the interface, you are stuck with still having to implement the unwanted interface for fear of breaking something else.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus