• Post Reply Bookmark Topic Watch Topic
  • New Topic

Redundant If Statement Warning  RSS feed

 
Greenhorn
Posts: 23
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Netbeans I'm getting an "if statement is redundant" warning and I'm really not sure why.

It shows up on the if statement testing for dashes, but not slashes.

 
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you click the hint icon and select 'The if statement is redundant' from the context menu that appears, you'll get the answer for yourself.
 
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you find out I'd like to know, because I don't see anything wrong with it. My best guess would be the forward slash in quotes is making the ide think it should be escaped and will always return there.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guillermo Ishi wrote:My best guess would be the forward slash in quotes is making the ide think it should be escaped

A forward slash doesn't ever need to be escaped.
 
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


That can be simplified to a single return statement.
That's all it's telling you.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The whole method can be simplified to s single statement, but you have to be brave with the ?: operator.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:The whole method can be simplified to s single statement, but you have to be brave with the ?: operator.


That's why I don't always listen to the "this can be simplified" suggestions. I don't always agree it is a simplification.
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
Campbell Ritchie wrote:The whole method can be simplified to s single statement, but you have to be brave with the ?: operator.


That's why I don't always listen to the "this can be simplified" suggestions. I don't always agree it is a simplification.

Well, it doesn't seem to hard to simplify ...

Henry

*note: didn't test it, so don't assume that it works correctly
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No ternary is involved, as the OP would discover by letting the IDE show him what it means.
 
Greg Zobel
Greenhorn
Posts: 23
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:
Campbell Ritchie wrote:The whole method can be simplified to s single statement, but you have to be brave with the ?: operator.


That's why I don't always listen to the "this can be simplified" suggestions. I don't always agree it is a simplification.


Using a ternary is an interesting idea. I've not used it enough to think of it when I'm coding though. Besides, the way I've written this I can come back to it in 20 years and instantly know exactly what it does and why.
 
Greg Zobel
Greenhorn
Posts: 23
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Dave Tolls wrote:
Campbell Ritchie wrote:The whole method can be simplified to s single statement, but you have to be brave with the ?: operator.


That's why I don't always listen to the "this can be simplified" suggestions. I don't always agree it is a simplification.

Well, it doesn't seem to hard to simplify ...

Henry

*note: didn't test it, so don't assume that it works correctly


I just plugged it into my project, and it seems to work. Looks nice too. I guess my brain works the long way around.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is better than using ?: If you look in the old Sun style guide (§10.5.2) you will see they recommend ?: as a standard way to return options.
 
Greg Zobel
Greenhorn
Posts: 23
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:No ternary is involved, as the OP would discover by letting the IDE show him what it means.


You're right. I've not use the inspect and transform before, very neat tool. It's like this:



Thanks everyone.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!