Click here to Skip to main content
15,886,757 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.

 
AnswerRe: Which code you suggest? Pin
Stefan_Lang26-Jul-13 0:09
Stefan_Lang26-Jul-13 0:09 
GeneralRe: Which code you suggest? Pin
Renzo Ciafardone27-Jul-13 17:00
Renzo Ciafardone27-Jul-13 17:00 
GeneralRe: Which code you suggest? Pin
Stefan_Lang28-Jul-13 22:00
Stefan_Lang28-Jul-13 22:00 
GeneralRe: Which code you suggest? Pin
Renzo Ciafardone29-Jul-13 14:25
Renzo Ciafardone29-Jul-13 14:25 
GeneralRe: Which code you suggest? Pin
Stefan_Lang29-Jul-13 21:26
Stefan_Lang29-Jul-13 21:26 
GeneralRe: Which code you suggest? Pin
BobJanova29-Jul-13 0:23
BobJanova29-Jul-13 0:23 
GeneralRe: Which code you suggest? Pin
Stefan_Lang29-Jul-13 2:44
Stefan_Lang29-Jul-13 2:44 
AnswerRe: Which code you suggest? Pin
BotReject26-Jul-13 0:47
BotReject26-Jul-13 0:47 
It depends. There are times when it is necessary to exit as soon as a decision is reached, as I expect the performance of foreach to be O(n). For example, if a function is trying to find the first prime number within an array then you need to exit as soon as the condition is true, otherwise much time may be wasted. In the example given it depends how large I expect the string array to be, clearly the function itself can potentially take a string array of any size so method 1 seems preferable to me. However, if you don't like multiple return points then use 'break'. A more complex function is often clearer to read and debug if there is only one return point, and this is preferable if speed is not an issue. For example, if a function decides which way a bug is going to turn - left or right, then it may test many conditions, none of which may involve operations on large collections. In this example, it is probably preferable to have only a single return point.
AnswerRe: Which code you suggest? Pin
Kenworth7126-Jul-13 1:04
professionalKenworth7126-Jul-13 1:04 
AnswerRe: Which code you suggest? Pin
nocturns226-Jul-13 3:29
nocturns226-Jul-13 3:29 
AnswerRe: Which code you suggest? Pin
RafagaX26-Jul-13 4:46
professionalRafagaX26-Jul-13 4:46 
AnswerRe: Which code you suggest? Pin
MarkTJohnson26-Jul-13 5:03
professionalMarkTJohnson26-Jul-13 5:03 
GeneralRe: Which code you suggest? Pin
jibalt26-Jul-13 17:28
jibalt26-Jul-13 17:28 
GeneralRe: Which code you suggest? Pin
MarkTJohnson28-Jul-13 14:41
professionalMarkTJohnson28-Jul-13 14:41 
GeneralRe: Which code you suggest? Pin
BobJanova29-Jul-13 0:17
BobJanova29-Jul-13 0:17 
GeneralRe: Which code you suggest? Pin
jibalt19-Aug-13 23:19
jibalt19-Aug-13 23:19 
GeneralRe: Which code you suggest? Pin
MarkTJohnson20-Aug-13 5:05
professionalMarkTJohnson20-Aug-13 5:05 
GeneralMessage Closed Pin
10-Feb-14 13:17
jibalt10-Feb-14 13:17 
GeneralRe: Which code you suggest? Pin
MarkTJohnson11-Feb-14 4:11
professionalMarkTJohnson11-Feb-14 4:11 
GeneralRe: Which code you suggest? Pin
jibalt26-Jul-13 17:30
jibalt26-Jul-13 17:30 
GeneralRe: Which code you suggest? Pin
PIEBALDconsult30-Jul-13 13:43
mvePIEBALDconsult30-Jul-13 13:43 
GeneralRe: Which code you suggest? Pin
jibalt19-Aug-13 23:25
jibalt19-Aug-13 23:25 
AnswerRe: Which code you suggest? Pin
James Lonero26-Jul-13 13:45
James Lonero26-Jul-13 13:45 
AnswerRe: Which code you suggest? Pin
jibalt26-Jul-13 17:24
jibalt26-Jul-13 17:24 
AnswerRe: Which code you suggest? Pin
jibalt26-Jul-13 17:27
jibalt26-Jul-13 17:27 

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.