FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » 500. Turbo Sort
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: 500. Turbo Sort [message #172626 is a reply to message #172622] Tue, 22 February 2011 12:16 Go to previous messageGo to previous message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma:
Senior Member
On 2/22/2011 4:47 AM, The Natural Philosopher wrote:
> Álvaro G. Vicario wrote:
>> El 22/02/2011 6:00, n00m escribió/wrote:
>>> Actually I sort (in usual sense) nothing.But my output is sorted, of
>>> course.
>>>
>>>> Shouldn't it be $i++ not ++$i on the for loop?
>>>
>>> And what's the difference (I refer only to my code above)?
>>> It's because my fingers like a bit more to press "++" first, then the
>>> rest.
>>> A kind of mechanical habit.
>>
>> It's documented here:
>>
>> http://es2.php.net/manual/en/language.operators.increment.php
>>
>>
> But since the value of $i is not tested in that statement, it makes no
> difference.
>
> It does in the sort of statement like while($i++<10); versus while(++$i<10)
>
> I think. I NEVER EVER use an increment operator in a test statement
> because if I can't remember, chances are the next person to read the
> code wont, either.
>
> Always ask yourself, 'how stupid, lazy & forgetful can I be on a Bad
> Monday morning in February, double it, and assume the guy who has to
> maintain your code is worse'
>
> THEN when you come back to your code on that morning after a row with
> your other half, ha raging hangover and you crashed the car on the way
> in, you stand some chance of being able to find the bug as well;-)

This illustrates the problem I had with C programmers back in the days.
They tended to have a "Name That Tune" philosophy. "I can write that
code in five lines". "I can write that code in three lines". I can
write that code in one line." "Write that code".

Debugging that one line multi-multi conditions for loop was a nightmare.
I could not set a break point inside the loop because everything was
done inside the definition of the loop. I would have to rewrite it so
that I could set some break points and examine values in the debugger.
For the the example above, it would then become either

if (i < 10) ....
i++

or

i++
if (i < 10)

and I knew then exactly what I wanted. So, I agree, NEVER include an
increment inside a test.


--
Shelly
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to read/to download attachment on an URI?
Next Topic: Proxy to open blocked sites
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 03:30:17 GMT 2024

Total time taken to generate the page: 0.04275 seconds