Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Get DoB Bounds from Age Range

by wrog (Friar)
on May 10, 2015 at 17:43 UTC ( [id://1126256]=note: print w/replies, xml ) Need Help??


in reply to Get DoB Bounds from Age Range

Oh right, one other thing:
Do not call now() at all.
Make the caller pass in a date; have it be the first argument.

It's bad enough that you're calling now() twice, which could introduce really subtle bugs that only get triggered very intermittently (imagine someone using this function right at midnight).

Also, consulting the system clock is a system call and all system calls are potentially expensive in certain contexts; perhaps not this one, but you still want to get into the habit of thinking of the system clock as something you don't look at unless you need to.

And whoever is calling your function will need to be thinking about which "now()" they actually want to be using. E.g., in a webserver context there's a request time and, chances are, the framework has already made the system call for you, and life gets simpler if you take the position that everything w.r.t. processing that request is happening in a single instant.

Replies are listed 'Best First'.
Re^2: Get DoB Bounds from Age Range
by over2sd (Beadle) on May 11, 2015 at 19:18 UTC

    That is a good point. Forcing^H^H^H^H^H^H^H Allowing the user to pass a reference date in also makes the function more flexible, letting them calculate ages at an arbitrary point in time.

    Thank you.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1126256]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2026-02-09 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.