Click here to Skip to main content
15,887,027 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: If it fails, try again Pin
Rob Grainger6-Jul-17 2:12
Rob Grainger6-Jul-17 2:12 
GeneralRe: If it fails, try again PinPopular
kmoorevs5-Jun-17 4:15
kmoorevs5-Jun-17 4:15 
GeneralRe: If it fails, try again PinPopular
Sander Rossel5-Jun-17 5:29
professionalSander Rossel5-Jun-17 5:29 
GeneralRe: If it fails, try again Pin
Daniel Wilianto5-Jun-17 16:04
Daniel Wilianto5-Jun-17 16:04 
GeneralRe: If it fails, try again Pin
Rob Grainger6-Jul-17 2:20
Rob Grainger6-Jul-17 2:20 
GeneralRe: If it fails, try again Pin
DerekT-P6-Jun-17 8:37
professionalDerekT-P6-Jun-17 8:37 
GeneralRe: If it fails, try again Pin
theoldfool5-Jun-17 13:20
professionaltheoldfool5-Jun-17 13:20 
GeneralRe: If it fails, try again Pin
kalberts5-Jun-17 21:51
kalberts5-Jun-17 21:51 
If "try again!" always was silly coding practice, the the concept of "busy waiting" would not be known. Busy waiting does have its place, especially in embedded systems where the processor has nothing else to do.

Another situation is where several activities are competing for the same resource, but they hold the resource comparatively briefly. As long as you can modify all the competitors, you could program the queueing mechanism, where a process trying to access a busy resource is sent to sleep in a queue and woken up when it gets its turn. Often you can only modify some of the competitors. The effort of implementing a queue mechanism may be high. If the risk of collision is small, it simply doesn't pay.

I have fairly recently programmed a couple "try again" cases: On a quite heavily loaded file system, the number of exceptions due to confliciting accesses was higher than desired. So, when making modifications to a set of files, I make one try for each. Those failing are put into a list for retrying, and a second attempt is made once the first round was completed. Only after a second try, the user is notified. We went from too many access collisions to almost none. Sometimes, the second try came too fast, and the file was still busy. So I added a 5 ms sleep before starting a second round, and after that I haven't seen a single collision.

This "try again" code is next to trivial, and it does solve a real problem. So I cannot agree that the strategy is silly in every case. Sometimes it makes perfect sense.
GeneralRe: If it fails, try again Pin
kmoorevs6-Jun-17 4:53
kmoorevs6-Jun-17 4:53 
GeneralRe: If it fails, try again Pin
Rob Grainger6-Jul-17 2:24
Rob Grainger6-Jul-17 2:24 
GeneralRe: If it fails, try again Pin
Richard Deeming6-Jun-17 0:20
mveRichard Deeming6-Jun-17 0:20 
GeneralRe: If it fails, try again Pin
abmv23-Jun-17 9:14
professionalabmv23-Jun-17 9:14 
GeneralPetrovich Pin
Brisingr Aerowing15-May-17 11:54
professionalBrisingr Aerowing15-May-17 11:54 
PraiseRe: Petrovich Pin
Marco Bertschi15-May-17 12:30
protectorMarco Bertschi15-May-17 12:30 
PraiseRe: Petrovich Pin
enhzflep25-May-17 23:23
enhzflep25-May-17 23:23 
GeneralVery WTF worthy Mass Effect bug Pin
Brisingr Aerowing6-May-17 14:02
professionalBrisingr Aerowing6-May-17 14:02 
GeneralRe: Very WTF worthy Mass Effect bug Pin
Nathan Minier8-May-17 2:08
professionalNathan Minier8-May-17 2:08 
JokeComments Can Hurt PinPopular
Brady Kelly14-Apr-17 7:57
Brady Kelly14-Apr-17 7:57 
GeneralRe: Comments Can Hurt Pin
ZurdoDev14-Apr-17 8:18
professionalZurdoDev14-Apr-17 8:18 
GeneralRe: Comments Can Hurt Pin
Brisingr Aerowing14-Apr-17 11:31
professionalBrisingr Aerowing14-Apr-17 11:31 
GeneralRe: Comments Can Hurt PinPopular
Marc Clifton14-Apr-17 13:29
mvaMarc Clifton14-Apr-17 13:29 
GeneralRe: Comments Can Hurt Pin
Brady Kelly14-Apr-17 18:11
Brady Kelly14-Apr-17 18:11 
GeneralRe: Comments Can Hurt Pin
Gary Wheeler3-May-17 7:13
Gary Wheeler3-May-17 7:13 
GeneralRe: Comments Can Hurt Pin
RedDk15-Apr-17 7:25
RedDk15-Apr-17 7:25 
GeneralRe: Comments Can Hurt Pin
Yusuf18-Apr-17 10:30
Yusuf18-Apr-17 10:30 

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.