| Code Better: Booleans instead of Comments |
|
|
| Written by Markus Ewald | |||
| Wednesday, September 15 2010 11:48 | |||
|
There are lots of small tricks a programmer learns over time. With this post, I'm starting a little column called Code Better in which I'll share some of my own tricks! If you want to show off some useful tricks of your own, I'd be happy to publish them here, too :) The first trick is a simple technique to make complicated if statements more readable. Let's take a look at this beast: The code isn't unreadable per se, but it takes more than a glance to understand what's going on. The comments help, but there's a more elegant way that makes those comments entirely redundant:
The beauty in this is that the first thing you see is
The Finally, this level of obviousness eliminates the need for any additional comments in the code!
|


Comments
return (isInsideHeight Field)? heightField[x,y ] : 0.0f;
Using the ternary operator in this case really helps readability :)
I tend to ignore it because in some cases, it can huge the fact that a condition is being checked, but this is clearly not one of those cases.
RSS feed for comments to this post