Hacker News new | past | comments | ask | show | jobs | submit login
Boolean operation "trick" (stackoverflow.com)
3 points by SandB0x on Sept 10, 2010 | hide | past | favorite | 2 comments



A classmate of mine wrote something similar in C++ a while ago:

if ( Foo( ) == true ) { return false; } else { return true; }

The comparison to true is what really had me laughing.


I would laugh, but I know I've written similar clunky code while thinking about the more complicated problem at hand (especially if in a rush).

Also, this is a neat example to show how novices/beginners learn how to program. They don't think about conditionals operating on booleans, the result of an expression like (1 == 2). And, they overall just seem to treat booleans differently. Seems silly once you've internalized it, but I'm sure we all make this realization while we're learning.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: