[clean-list] toInt badness for Clean newbie
erik.zuurbier@tiscali.nl
erik.zuurbier@tiscali.nl
Mon, 26 Jul 2004 17:02:12 +0200
Jenda wrote:
>Any reason why toInt() can't mean "skip the whitespace if any, read
>the digits and convert them to an integer, ignore the rest of the
>string" ?
If you are trying to make toInt a total function, you still have to explain
what to do if there
are no digits after the initial whitespace and what to do if there are far
too many to
store in an Int.
If you succeed in doing that, you have an interface that always works...
technically:
The user types something in, for instance "EUR 345.00" or "0.99" and on
goes the
program, probably using zero in both cases. Only to find out later, if at
all, that the program worked
with the wrong input. Good programmers will not allow that to happen, so
they will
code checks on the input before turning toInt loose on it. If they do so,
it was a waste of
time making toInt a total function in the first place. Moreover: making
toInt a total function
encourages bad programming habits: just leaving out the checks I mentioned.
Hope this helps
Regards Erik Zuurbier
_____________________________________________________________________
Bent u toe aan sneller en goedkoper internet?
Ga dan naar http://adsl.tiscali.nl