Bug in string.erl

Peter-Henry Mander erlang@REDACTED
Wed Nov 5 08:22:39 CET 2003


Hi Joe,

I beg to differ: static type systems *might* have helped find the bug, but the bug was introduced by someone "being nice" (sarcasm?), and the fact that they explicitly added a catch-all would also have defeated static typing. The programmer's _intent_ was utterly wrong, so don't mark yourself down (-:

Moral: Don't be nice, especially in libraries!

I've been bitten by assuming that "being nice" in my support/library modules would help me later on, but I've found that having libraries that are "awkward bastards" actually prevents my code from running quietly mad until an 'EXIT' of some sort pops up miles from the real scene of action!

Pete.

On Tue, 4 Nov 2003 20:02:01 +0100 (CET)
Joe Armstrong <joe@REDACTED> wrote:

> 
>  Bug in string.erl
> 
>  This took me 45 mins to find 
> 
>  I had some variable X which I *thought* contained a list
> 
>  > string:substr(X, 1, 20).
>  []
> 
>  But is was an atom ... did I get an exit - No for
> 
>  > string:substr(aa, 1, 20). 
>  []
> 
>  Wow (Static type systems 1, Joe 0)
> 
>  The code in string.erl says 
> 
>  --- quote ---
> 
>  substr1([C|String], L) when L > 0 -> [C|substr1(String, L-1)];
>  substr1(String, L) -> [].			%Be nice!
> 
>  --- end quote ---
> 
>  I rather like the "%Be nice!" comment.
> 
>  IMHO all the functions in string should exit when the "string" argument
> is not a list - I'm not asking that you "deep check" the list but a little
> help might be nice
> 
>  /Joe
> 
> 
> 
> 
> 


-- 
"The Tao of Programming
 flows far away 
 and returns 
 on the wind of morning."




More information about the erlang-questions mailing list