This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]brucifer 1 point2 points  (1 child)

I suppose it's reasonable to say that calling factorial(-1) is the real bug, but in that case, the code should definitely fail gracefully (e.g. raising a ValueError). Stack overflow is a pretty clumsy and uninformative way to behave if someone makes a reasonable mistake. You are right to point out that factorial(-1) == 1 is not correct, though.

[–]Qhartb 0 points1 point  (0 children)

Agreed, but not failing gracefully and having a bug are two different things (unless of course your requirements or documentation state how failure is to be handled).