NYCPHP Meetup

NYPHP.org

[nycphp-talk] Using greater than zero or multiplication?

David Krings ramons at gmx.net
Wed Jun 27 07:06:45 EDT 2012


On 6/27/2012 4:45 AM, Leam Hall wrote:
> Morning all!
>
> I'm working on my Tech Dive Planner and wanted to get a best practice idea
> from you. There are some calculations that need 3-5 variables set or the
> calculation isn't done. Since all the inputs are numeric and set to a default
> of zero, is it better to test each input to see if it's greater than zero or
> just multiply them once and see if the result is greater than zero?
>
> In the grand scheme of things there's no serious performance hit either way,
> the app is pretty small. I am trying to build my skills and good habits though.
>
> Thanks!
>
> Leam

Not that I am an expert in best practices, but I'd test each to be larger than 
zero. If you multiply them all you will only know that one of them is zero, 
but you do not know which one. How do you then report that to the user for 
corrections? OK, with five variables it should be somewhat easy for the user 
to figure out which one is 0 or missing, but what happens when your user is 
visually impaired? It will be a much bigger burden for them as they need to 
traverse each field. In short, test each of them and then craft a summary 
response that indicates wich entry / entries are zero and need correction.

David



More information about the talk mailing list