Click here to Skip to main content
15,916,030 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
PIEBALDconsult6-Jun-17 10:21
mvePIEBALDconsult6-Jun-17 10:21 
GeneralRe: If it fails, try again Pin
Rob Grainger6-Jul-17 2:09
Rob Grainger6-Jul-17 2:09 
GeneralRe: If it fails, try again Pin
Sander Rossel5-Jun-17 1:14
professionalSander Rossel5-Jun-17 1:14 
GeneralRe: If it fails, try again Pin
the Kris5-Jun-17 0:30
the Kris5-Jun-17 0:30 
GeneralRe: If it fails, try again Pin
Sander Rossel5-Jun-17 1:10
professionalSander Rossel5-Jun-17 1:10 
JokeRe: If it fails, try again Pin
Jim_Snyder5-Jun-17 3:05
professionalJim_Snyder5-Jun-17 3:05 
GeneralRe: If it fails, try again Pin
Sander Rossel5-Jun-17 5:30
professionalSander Rossel5-Jun-17 5:30 
GeneralRe: If it fails, try again Pin
Jim_Snyder5-Jun-17 6:04
professionalJim_Snyder5-Jun-17 6:04 
PraiseRe: If it fails, try again Pin
Jim_Snyder5-Jun-17 6:05
professionalJim_Snyder5-Jun-17 6:05 
GeneralRe: If it fails, try again Pin
kalberts5-Jun-17 22:06
kalberts5-Jun-17 22:06 
GeneralRe: If it fails, try again Pin
Sander Rossel6-Jun-17 5:58
professionalSander Rossel6-Jun-17 5:58 
GeneralRe: If it fails, try again Pin
Nelek6-Jun-17 6:53
protectorNelek6-Jun-17 6:53 
GeneralRe: If it fails, try again Pin
Sander Rossel6-Jun-17 11:06
professionalSander Rossel6-Jun-17 11:06 
GeneralRe: If it fails, try again Pin
Nelek6-Jun-17 19:19
protectorNelek6-Jun-17 19:19 
GeneralRe: If it fails, try again Pin
Sander Rossel6-Jun-17 21:10
professionalSander Rossel6-Jun-17 21:10 
GeneralRe: If it fails, try again Pin
kalberts7-Jun-17 1:34
kalberts7-Jun-17 1:34 
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 Pin
kmoorevs5-Jun-17 4:15
kmoorevs5-Jun-17 4:15 
GeneralRe: If it fails, try again Pin
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 

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.