Maintainable code, why bool can be bad as a parameter
Having grown used to using some form of a Boolean as a parameter, it has been nagging me how unreadable this makes the calls to the method using them as parameters. In more expressive languages, which use keywords (or named parameters) such as Bliss, LISP, our CLIPS extensions, etc. it isn't too bad... because you have something like foo(:doSomething) or foo(:doSomething True). However, in C++, it just looks like foo(True). And when you have multiple parameters, it can make remembering what (True) means rather difficult.
I usually just resolve this by grumbling about how stupid C++ is, and why doesn't it have a better way to do this; rather than doing something constructive like thinking about a solution. :-}. Today I ran across an article that had a great explanation of why you should use enums rather than bool for these type of paramters. Great stuff. Sometimes (most the time?) you just have to read someone elses words to realize how obvious something is. ;-)
Friday, October 11, 2002
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment