I’m a verbose guy when it comes to code. The compiler doesn’t care and it’s easier for me to read later on down the road. I’ve changed my style over the past few months, it started at Pelco because I was confusing folks with a particular syntax. I must admit, it even confused me on occasion.
When checking pointers I used to do this.
if (NULL != ptr)
That was confusing. I’ve since switched my tune back to a tried and true method of removing the NULL !=, like this
if (ptr)
Much easier for most to understand. I do, however, still check for explicit FALSE and NULL as the case may be, because I believe it to be a bit more clear. Here’s what that looks like.
if (NULL == ptr)
or
if (FALSE == value)
There is a statement some don’t like, that I love, and probably won’t switch away from. The ternary operator.
something = (value) ? value1 : value2;
My brain just likes it.
It’s the little things that can drive a developer to jumping out a window. You plan a solution, code the solution, build the solution, run it, and… it doesn’t work. Most of the time you spot the problem right away, some times you’re left scratching your head, repeating over and over “this looks like it should work?” Of course you know better. It didn’t work, you just can’t see why. I had this problem last night so I thought I’d share with the world, ok not the world, just my electronic brain, so I can look it up later if necessary.