Hacker News new | ask | show | jobs
by JnRouvignac 4035 days ago
Which ones?
2 comments

You've got a change under "// should not be touched"

http://imgur.com/CSHnOuP

Thanks for reporting.

Actually the comment is wrong in that case using BigDecimal.valueOf() is better since it could reuse the immutable object, so that is better for memory. I'll rework the samples to make it more explicit.

Fixed.
The IfElseIfSample.java converts a clear if-else to a if-elseif without else. As if the programmer had forgotten the else.
I am trying to understand your point but I fail.

Why should there always be a else to an if-elseif?

Secondly, in the original if-else, the if in the else clause does not have a else. Why is it not a problem for you? It seems contradictory...

> Why should there always be a else to an if-elseif?

Because that's good style!

> in the original if-else, the if in the else clause does not have a else

An if can live without an else. BTW, there are many books and online resources about programing style.

Thanks, I am reading many things about good code and I have never seen such advice.

"Good style", "best practice", all of this comes from an observation made by somebody who can justify it is good practice by some real evidence. If you were using if-elseif like a switch statement, then maybe there should be an else. If the if conditions are not related, then I don't see why there should necessarily be one.

Please enlighten me by pointing to the relevant online resources.

What should go in the else? A comment saying "// Do nothing here"?
> What should go in the else?

What's left. What else should go in else?

BTW, the original example not disimproved by AutoRefactor was okay.