aspose file tools*
The moose likes Beginning Java and the fly likes boolean constants Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boolean constants" Watch "boolean constants" New topic
Author

boolean constants

Örjan Karlsson
Greenhorn

Joined: Oct 29, 2008
Posts: 2
I have a sort of programming-philosofical-ish question about the use of boolean constants.

This is my example:

This is pretty straight forward class, with some fields, constants and some methods.

So is the use of boolean constants (YES and NO in the example) "good" programming or does one over do things programming like this. In my opinon it makes the code somewhat more readable.

Im interested in other peoples views on this subject.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

These constants already exist in the java.lang.Boolean class. I would just use them, e.g. :


And of course these already exist as literal constatnts, so I'm not sure what extra benefit using other constants provides?




...though in your code I suspect these are redundant. Its probably safer to perform checks like:


rather than:


[ December 08, 2008: Message edited by: Paul Sturrock ]
[ December 08, 2008: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Örjan Karlsson
Greenhorn

Joined: Oct 29, 2008
Posts: 2
How about from a readability standpoint, using YES and NO in the code combined with descriptive field names and methods?

However i dont think anyone who reads code is having problems with true and false.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Up to you really. Personally I reckon they clutter the clas a little. If the constants were for some constant specific to the class I'd use them, otherwise I'd just return the existing constants.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: boolean constants