Re: Avoiding Booleans & Danny Thorpe
- From: "Brett Watters" <blwatters@xxxxxxx>
- Date: Sun, 30 Oct 2005 09:36:37 -0800
Andre,
> I think that
>
> CreateFile(cmCreateNew);
>
> is much more readable than
>
> CreateFile(true);
>
1. NON-CONSTANT PARAMETERS
If the values aren't constants, the function is still unreadable.
CreateFile(MyVariable,MyFunctionCall)
and you still can't tell what the parameter are without:
CreateFile({New File} MyVariable, {Logging} MyFunctionCall)
Variables, properties, function calls, etc. all negate any advantage
for readability if the enumerated constant isn't visibile.
2. PARAMETERS BASED ON CONDITIONS
Compare
CreateFile( {New File} FileExists(MyFile), {Logging} not
(FileDate(MyFile) > Date) )
and have to code it like:
if FileExists(MyFile)
then
begin
if not (FileDate(MyFile) > Date)
then CreateFile(cfaNewFile,cfaLogging)
else CreateFile(cfaNewFile,cfaNoLogging)
end
else
if not (FileDate(MyFile) > Date)
then CreateFile(cfaExistingFile,cfaLogging)
else CreateFile(cfaExistingFile,cfaNoLogging);
One line is always more readable than 6+. It is also far
less error prone.
3. BOOLEAN UNROLLING
As in above, if you have a complex boolean statements, you
force the programmer to un-roll the statements to get cases
for the call with only enumerators. Boolean logic is tricky and
error prone already. Unrolling (possibly multiple) boolean
statements to reform them into If ... Then's is asking for trouble.
4. ENUMERATED TYPES AREN'T TRUE/FALSE
Authorization("foo", AuthorizationCompletion.Pending)
Authorization("foo", AuthorizationCompletion.Finished)
Are both wordy and deceiving. Is there some state other
than Pending or Finished? Why not Pending and NotPending
which is more accurate? Why would everyone assume that
..Pending means Not .Finished? If I only see:
Authorization("foo", AuthorizationCompletion.Pending)
why would I assume that if I didn't want pending that
Authorization("foo", AuthorizationCompletion.Finished)
would be the alternative? Why not .Stopped or .DoLater,
or .Paused, etc.
5. ENUMERATED TYPES AREN'T CLEAR EITHER
What does AuthorizationCompletion.Pending mean anyway?
How does Authorization use it anyway?
6. OTHER TYPES AREN'T SPELLED OUT FOR YOU
ANYWAY
If you use:
Authorization("foo",AuthorizationCompletion.Pending)
then what is the "foo" parameter anyway? How about:
Authorization("foo", 5, 0.245, AuthorizationCompletion.Finished)
i.e. you are going to have to look at Authorization to figure out
what it does or include:
Authorization( {Caption} "foo", {Record No} 5, {Discount %} 0.245,
{Completion} AuthorizationCompletion.Finished )
Thanks,
Brett
.
- Follow-Ups:
- Re: Avoiding Booleans & Danny Thorpe
- From: Andre Kaufmann
- Re: Avoiding Booleans & Danny Thorpe
- References:
- Avoiding Booleans & Danny Thorpe
- From: Kyle A. Miller
- Avoiding Booleans & Danny Thorpe
- Prev by Date: Re: Avoiding Booleans & Danny Thorpe
- Next by Date: Re: Avoiding Booleans & Danny Thorpe
- Previous by thread: Re: Avoiding Booleans & Danny Thorpe
- Next by thread: Re: Avoiding Booleans & Danny Thorpe
- Index(es):
Relevant Pages
|