Hacker News new | ask | show | jobs
by BadThink6655321 2766 days ago
The problem is trying to understand that it’s not a loop. The first line of the block says “this is a loop”. The last line of the block says “this isnt’t a loop.”

The code is, if not outright lying, at least misdirecting.

1 comments

You could always add a comment "this is not a loop" if you find it puzzling that the language allows you to loop zero times.
This is wrong in so many ways. First, I know the language. I’ve been doing this for almost 50 years. This isn’t a question of what the language allows but what the coder is trying to do.

Second, experience has taught me that code and comments often don’t agree. Too, if you have to comment that a loop really isn’t a loop then this is an indication that something is wrong.

Third, it isn’t a loop: while(false) never loops. That’s the point. Having to use a forward reference to understand the beginning of something is bad practice.

Fourth, this construct is almost always a sloppy way to prevent if-else creep. The code is invariably improved by a) not lying about the loop and b) refactoring.