Click here to Skip to main content
15,887,746 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Performance Genius Pin
Steve Caine27-Dec-10 10:52
Steve Caine27-Dec-10 10:52 
GeneralRe: Performance Genius Pin
BillW3329-Dec-10 4:23
professionalBillW3329-Dec-10 4:23 
GeneralRe: Performance Genius Pin
ghle29-Dec-10 11:17
ghle29-Dec-10 11:17 
GeneralRe: Performance Genius Pin
Steve Caine29-Dec-10 20:02
Steve Caine29-Dec-10 20:02 
GeneralRe: Performance Genius Pin
ely_bob29-Dec-10 7:06
professionalely_bob29-Dec-10 7:06 
GeneralRe: Performance Genius [modified] Pin
#realJSOP2-Jan-11 1:33
mve#realJSOP2-Jan-11 1:33 
GeneralRe: Performance Genius Pin
fjdiewornncalwe2-Jan-11 4:25
professionalfjdiewornncalwe2-Jan-11 4:25 
GeneralRe: Performance Genius Pin
Steve Caine3-Jan-11 10:35
Steve Caine3-Jan-11 10:35 
John Simmons / outlaw programmer wrote: "Is there some subtle sarcasm going on here? I've never seen "++i" used (in a for loop) - ever."

Somewhat subtle. The increment operator is slightly more efficient in its prefix version (++i) because it just increments 'i' and returns its value. The postfix version has to do more work because it returns the *previous* version of 'i', so it has to store that value somewhere before incrementing i.

If you're just incrementing 'i', it makes more sense to use the more efficient prefix version. It's just better form, and encourages good habits. (For example, applying it to something more complex than an integer, say an iterator to an STL container class, might produce a more significant performance hit than the miniscule one your test found.)

Yet you're right, most of the instances of '++' or' --' I've seen in code, particularly in 'for' loops, is the postfix version. There's no reason for it, yet somehow that has become a near-universal meme in programming. Perhaps because the most common example beginning programmers encounter is the classic C-string copy code snippet, where you really *do* want to use the postfix version:

  while (*dst++ = *src++)
    ;

So I was making a joke that the real coding outrage in the original poster's message was using 'i++' instead of '++i', as if I had completely missed the real outrage of sleeping the thread in each pass through the 'for' loop.

(Getting off my soapbox now.)
GeneralRe: Performance Genius Pin
Sander Rossel27-Dec-10 19:47
professionalSander Rossel27-Dec-10 19:47 
GeneralRe: Performance Genius Pin
Ravi Sant27-Dec-10 22:37
Ravi Sant27-Dec-10 22:37 
GeneralRe: Performance Genius Pin
yxhu5-Jan-11 13:10
yxhu5-Jan-11 13:10 
GeneralRe: Performance Genius Pin
Adrian020-Jan-11 1:48
Adrian020-Jan-11 1:48 
GeneralRe: Performance Genius Pin
yxhu23-Jan-11 11:50
yxhu23-Jan-11 11:50 
GeneralRe: Performance Genius Pin
Adrian023-Jan-11 12:44
Adrian023-Jan-11 12:44 
GeneralRe: Performance Genius Pin
yxhu23-Jan-11 13:14
yxhu23-Jan-11 13:14 
GeneralUseless function Pin
musefan23-Dec-10 3:39
musefan23-Dec-10 3:39 
GeneralRe: Useless function Pin
OriginalGriff23-Dec-10 5:46
mveOriginalGriff23-Dec-10 5:46 
GeneralRe: Useless function Pin
musefan27-Dec-10 6:25
musefan27-Dec-10 6:25 
GeneralRe: Useless function Pin
RobCroll24-Dec-10 4:29
RobCroll24-Dec-10 4:29 
GeneralRe: Useless function Pin
musefan27-Dec-10 6:27
musefan27-Dec-10 6:27 
GeneralRe: Useless function Pin
fjdiewornncalwe27-Dec-10 5:45
professionalfjdiewornncalwe27-Dec-10 5:45 
GeneralRecursive methods. [modified] Pin
Sander Rossel22-Dec-10 9:28
professionalSander Rossel22-Dec-10 9:28 
GeneralRe: Recursive methods. Pin
_Erik_23-Dec-10 3:58
_Erik_23-Dec-10 3:58 
GeneralRe: Recursive methods. Pin
Sander Rossel23-Dec-10 5:15
professionalSander Rossel23-Dec-10 5:15 
GeneralRe: Recursive methods. Pin
RobCroll24-Dec-10 4:46
RobCroll24-Dec-10 4:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.