purplecat: Hand Drawn picture of a Toy Cat (Default)
purplecat ([personal profile] purplecat) wrote in [site community profile] dw_dev_training2012-05-01 07:32 pm

Can a journal entry id be 0?

For Bug 2152 I've found I need to create a subroutine that checks whether a form element refers to a valid entry in the user's journal separately from the various subroutines for actually saving it as a sticky.

If a journal entry id can never be zero then this subroutine could return the id number if it is valid and 0 otherwise. In that case the subroutine can replace duplicate code in at least two places, but obviously if an entry can be 0 then the subroutine had better just return 0 or 1.
mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)

[staff profile] mark 2012-05-01 07:06 pm (UTC)(link)
Every sub should check its inputs. While you may be the only person calling it and it may be extraneous, in six months someone else might decide to call your function and if they pass bad inputs, you're in trouble.

The only exception to this is if you have a locally scoped closure (i.e., my $x = sub { ... };) then, since nobody else can call it except you, validating inputs is not something to worry about.