Page 2 of 2

Posted: Mon Feb 12, 2007 1:20 pm
by RobertGonzalez
I usually do something like this:

Code: Select all

<?php
/** 
 * Lets get the time... in seconds... because for some reason 
 * PHP needs to do everything in seconds from January 1, 1970
 */
$timestamp = time();

// Now check to see if now less reset time is greater than one day 
// (in seconds, thanks again to PHP's wonderful handling of dates
if ($timestamp - $profitreset->reset >= 86400 )
{
  //
}
?>
Comments don't scare me so much, so I use them to allow me to come back and easily distinguish what I was doing. Even though

Code: Select all

<?php
$one_day = 60 * 60 * 24;
?>
Seems self explanatory, there is nothing really saying that the units you are using is seconds. It could be 24 parcels per worker, 60 workers per station, 60 stations per region and one days output is 86400 parcels in a region. I know that's a stretch, but a simple comment speaks more to me that making an assumption as to what was intended simply by looking at the values used in a math routine (which to me still does not make sense to have PHP do).

Posted: Mon Feb 12, 2007 1:29 pm
by Luke
yes I suppose that is true... I am not afraid of comments either, but that for some reason always made sense to me. My code is heavily commented anyway.

Posted: Mon Feb 12, 2007 1:33 pm
by RobertGonzalez
I feel you. I tend to let things that make sense permeate my code. But simple math just makes sense to me.

I hope I don't come off as argumentative. That is not my intent. I am merely trying to share my opinion on the use of numeric values that I feel should not necessarily be calculated by PHP since most often I have a calculator (or pen and paper) handy to do it.

Posted: Mon Feb 12, 2007 1:35 pm
by Luke
I hope I don't come off as argumentative.
not at all... no love lost :wink: