I'm looking through some code and I found some strange conditionals, namely:
if (NULL != buf) {...}
I was wondering if there was a particular reason for writing the conditional like this, instead of
if(buf != NULL){...}
I can't see any reason to do it the first way off the top of my head, but I don't think it was a mistake. To me, it seems like they accomplish the same thing, but the second way is way more intuitive. Is there some specific reason to use the first conditional?
Yes, it's called "Yoda conditions". The idea is to not accidentally assign a value when you mean to be doing a check. Most modern compilers should catch it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With