I've been developing a huge plugin for wordpress recently. well over 200000 lines of code so far. so much for holidays...
this is a post that may help others. For the last day I have been debugging a MATHS problem. Yes, simply adding up various invoices, calculating some interest etc. I thought i had it cracked and started a batch job to print 400 legal letters (i am a lawyer). i was bundling them into envelopes when i thought to check the output for a random sample.
not cracked at all - the maths was wrong. very wrong, the invoices were not being totalled correctly leading to requests for x rather than many times x....
another day of footprinting and tracking through the code and genuinely getting very grumpy indeed. It turns out that the error was the difference between
both are perfectly valid code, neither throw errors.
the difference is this
whereas
the reason is because in the second code i was simply assigning the value of +8 to the variable.
A simple transposition of an otherwise commutative operator has a huge effect.
In hindsight the long form I feel is always better
a salutary lesson that the littlest thing can have an enormous influence.
this is a post that may help others. For the last day I have been debugging a MATHS problem. Yes, simply adding up various invoices, calculating some interest etc. I thought i had it cracked and started a batch job to print 400 legal letters (i am a lawyer). i was bundling them into envelopes when i thought to check the output for a random sample.
not cracked at all - the maths was wrong. very wrong, the invoices were not being totalled correctly leading to requests for x rather than many times x....
another day of footprinting and tracking through the code and genuinely getting very grumpy indeed. It turns out that the error was the difference between
Code:
+=
//and
=+
both are perfectly valid code, neither throw errors.
the difference is this
Code:
$a = 5;
$a += 3;
//$a is 8
Code:
$a = 5;
$a =+ 3;
//$a is 3.
the reason is because in the second code i was simply assigning the value of +8 to the variable.
A simple transposition of an otherwise commutative operator has a huge effect.
In hindsight the long form I feel is always better
Code:
$a=3;
$a = $a + 5;
a salutary lesson that the littlest thing can have an enormous influence.