E
Eric Sosman
But with crashing software *nobody* would get paid. And if an application
used "", then the field would be blank anyway.
Consider the consequences. If the program crashes, there's a
panic page in the middle of the night and a team of sleepy programmers
get rousted out of bed to fix the bug and get the checks out. Too bad
for the programmers who'd rather have slept, but they shouldn't have
written the bug that caused the pointer to be NULL in the first place.
Or, the alternative: The program runs, no alarms ring, the checks
print and are distributed. And the first five recipients to notice
their opportunity drain the entire payroll account and vanish to
Vanuatu. Nobody else gets paid because all the checks bounce.
If a blank field is an error, it will be obvious when the field appears
'blank'. Not so obvious when there's a seg fault or whatever.
A crashed program is about a jillion times more "obvious" than a
program that runs silently and produces bad output.
If. Usually a string is a string, you might not do anything different
with a
0-length string compared with an N-length one.
What is the temperature in your home's underwater bowling alley?
You seem unable to distinguish between "My home has no underwater
bowling alley" and "Zero Kelvin." Others see a difference.
But it is a pain then to have to check for NULLs (which I tend to do with
functions taking string arguments).
If a function is *supposed* to behave differently with NULL than
it does with "", or differently with "" than with "purple", the tests
are a necessary part of its ordinary operation. How could it be
otherwise?
At the moment I might write:
if (s==NULL) return NULL;
slen = strlen(s);
if (slen==0) return NULL;
And mention in the specs that NULL is an acceptable argument equivalent to
an empty string.
But wouldn't it be useful to be able to omit that first check?
Impossible to say. What is the function's purpose? What should
it return for "purple", and why? Fragments don't define interfaces.