Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Needless casts?

Reply
Thread Tools

Needless casts?

 
 
Timo Kinnunen
Guest
Posts: n/a
 
      04-24-2004
On Sat, 24 Apr 2004 11:20:45 +0100, VisionSet wrote:

> I can sort of understand someone uneccesarily writing:
>
> if ( ( a = true) == true )
>
> but what possible excuse is there for:
>
> if ( ( a == true) == true )


Multiple small changes could result in that. From if(!b) to if(!b==true) to
if((b==false)==true) to if((a==true)==true).

Sometimes if(someLongCondition==false) is more readable than
if(!someLongCondition), IMHO.
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      04-25-2004
VisionSet <(E-Mail Removed)> scribbled the following:
> "Roedy Green" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Yucch! That drives me almost as nuts as
>>
>> String error_notInitialized = (String) new String("Not initialized.");
>>
>> or
>>
>> if ( ( a == true) == true )


> I can sort of understand someone uneccesarily writing:


> if ( ( a = true) == true )


> but what possible excuse is there for:


> if ( ( a == true) == true )


As I mentioned in another thread, some of my colleagues actually prefer
to write:

boolean v = false;
if (value >= minimum) {
if (value <= maximum) {
v = true;
}
}
return v;

to writing:

return value >= minimum && value <= maximum;

I of course prefer the latter to the former, and even the Sun Java
code conventions agree with me.

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"The trouble with the French is they don't have a word for entrepreneur."
- George Bush
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      04-25-2004
On Sat, 24 Apr 2004 11:20:45 +0100, "VisionSet" <(E-Mail Removed)>
wrote or quoted :

>> if ( ( a == true) == true )


by the way, since "a" is a boolean expression already the way you
should write that is:

if ( a )


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      04-25-2004
On 25 Apr 2004 08:15:03 GMT, Joona I Palaste <(E-Mail Removed)>
wrote or quoted :

>return value >= minimum && value <= maximum;


In mathematics that expression would be written

minimum <= value <= maximum

So I mirror that as closely as possible in java with:

if ( minimum <= value && value <= maximum )


If you are consistent about that it is always clear which is the lower
and upper bound.


--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
 
Reply With Quote
 
Filip Larsen
Guest
Posts: n/a
 
      04-25-2004
Joona I Palaste wrote

> return value >= minimum && value <= maximum;
>
> I of course prefer the latter to the former, and even the Sun Java
> code conventions agree with me.


Range tests also look good when you do them like

return minimum <= value && value <= maximum;

which can be read like "minimum <= value <= maximum" and that makes for
good proofreading.


Regards,
--
Filip Larsen


 
Reply With Quote
 
Icemerth
Guest
Posts: n/a
 
      04-25-2004
"Filip Larsen" <(E-Mail Removed)> wrote in message news:<c6g7pq$289c$(E-Mail Removed)>...
> Joona I Palaste wrote
>
> > return value >= minimum && value <= maximum;
> >
> > I of course prefer the latter to the former, and even the Sun Java
> > code conventions agree with me.

>
> Range tests also look good when you do them like
>
> return minimum <= value && value <= maximum;
>
> which can be read like "minimum <= value <= maximum" and that makes for
> good proofreading.
>
>
> Regards,


y
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Maven generates needless javadocs for generated classes Jukka Lahtinen Java 1 02-24-2011 07:27 AM
Needless copying in iterations? James Stroud Python 22 09-17-2007 04:44 AM
optparse, needless argument, mac os x intel Aaron Smith Ruby 2 03-12-2007 06:39 AM
More Needless single-user start-up choice Paul Hoberg Computer Support 1 08-14-2003 03:42 PM
Needless single-user start-up choice Paul Hoberg Computer Support 1 08-13-2003 09:22 PM



Advertisments