• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reg:Inline conditions

 
praveen oruganti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Avoid using inline conditions like conditional operators in java code".

It is predicting by checkstyle plugin. Whether there is any performance affects related to the above quote
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checkstyle doesn't suggest changes for performance, it suggests changes to aid the readability of the code. If there is any performance difference it will be negligable.
 
Tim Holloway
Bartender
Posts: 18415
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At one time, an inline conditional was probably MORE likely to compile to efficient code, but that's back when compilers weren't as smart. The primary reason for the inlines was that they're faster to type.

I ran into a very good reason for NOT using inlines the other day - the same reason why I always code conditional statements with blocks, even if only one statement depends on the condition.

I use blocks because if maintenance requires adding an additional statement, inserting an extra statement in a block "just works", but you have to remember to not only add the new statement itself, you have to go back and wrap the multiple statements in a block or the software will break.

Actually, I'm usually paying attention when I'm making code changes, but when I add temporary code (such as a println), that's when I've gotten burned. So for my own protection, I make all condition targets be blocks and not single statements.

Inlines are the same, except worse, since - unless you like really ugly code, adding an additional item to an inline statement is going to force you to convert it to a non-inline dependency anyway.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!