Click here to Skip to main content
15,889,462 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: Avoid return statement in the middle - horror or not? Pin
Mladen Janković9-Dec-08 5:25
Mladen Janković9-Dec-08 5:25 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult9-Dec-08 6:53
mvePIEBALDconsult9-Dec-08 6:53 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
johannesnestler23-Dec-08 1:56
johannesnestler23-Dec-08 1:56 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
ehuysamer5-Dec-08 22:25
ehuysamer5-Dec-08 22:25 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
Tristan Rhodes5-Dec-08 23:39
Tristan Rhodes5-Dec-08 23:39 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
cokkiy6-Dec-08 1:00
cokkiy6-Dec-08 1:00 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
Robert.C.Cartaino6-Dec-08 6:05
Robert.C.Cartaino6-Dec-08 6:05 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
riced6-Dec-08 8:30
riced6-Dec-08 8:30 
Having been brought up on 'Structured Programming' I used to think that one-entry and one-exit point was the only way to write procedures.
Now I'm in favour of your approach - i.e. use guard conditions and exit early if need be. Oh and keep the procedure small, roughly no more than can fit on an A4 page.
One example of how not to do it that I came across was a C++ function that had around 500 lines of code with about 15 returns scattered throughout. It also had a couple of places where it could throw an exception!

David Rice
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult7-Dec-08 6:15
mvePIEBALDconsult7-Dec-08 6:15 
GeneralRe: Avoid return statement in the middle - horror or not? PinPopular
Michael Dunn7-Dec-08 20:40
sitebuilderMichael Dunn7-Dec-08 20:40 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
Member 16746110-Dec-08 1:13
Member 16746110-Dec-08 1:13 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult10-Dec-08 3:16
mvePIEBALDconsult10-Dec-08 3:16 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
Andrew Torrance8-Dec-08 22:23
Andrew Torrance8-Dec-08 22:23 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
Robert.C.Cartaino9-Dec-08 3:56
Robert.C.Cartaino9-Dec-08 3:56 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult9-Dec-08 4:22
mvePIEBALDconsult9-Dec-08 4:22 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
Ben Fair9-Dec-08 6:54
Ben Fair9-Dec-08 6:54 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
geoffs9-Dec-08 10:05
geoffs9-Dec-08 10:05 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
FatBuddha10-Dec-08 4:11
FatBuddha10-Dec-08 4:11 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult10-Dec-08 8:35
mvePIEBALDconsult10-Dec-08 8:35 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
FatBuddha10-Dec-08 14:48
FatBuddha10-Dec-08 14:48 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult10-Dec-08 15:43
mvePIEBALDconsult10-Dec-08 15:43 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
FatBuddha11-Dec-08 3:04
FatBuddha11-Dec-08 3:04 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
PIEBALDconsult11-Dec-08 6:14
mvePIEBALDconsult11-Dec-08 6:14 
GeneralRe: Avoid return statement in the middle - horror or not? Pin
supercat915-Dec-08 11:57
supercat915-Dec-08 11:57 
GeneralRe: Avoid return statement in the middle - horror or not? [modified] Pin
PIEBALDconsult15-Dec-08 13:33
mvePIEBALDconsult15-Dec-08 13:33 

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.