Click here to Skip to main content
15,886,199 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: What was I thinking Pin
Chris Maunder16-Jan-13 18:14
cofounderChris Maunder16-Jan-13 18:14 
GeneralRe: What was I thinking Pin
James Lonero19-Jan-13 11:08
James Lonero19-Jan-13 11:08 
JokeRe: What was I thinking Pin
Andrew Rissing17-Jan-13 5:48
Andrew Rissing17-Jan-13 5:48 
GeneralRe: What was I thinking Pin
Chris Maunder17-Jan-13 9:43
cofounderChris Maunder17-Jan-13 9:43 
GeneralRe: What was I thinking Pin
Andrew Rissing17-Jan-13 9:55
Andrew Rissing17-Jan-13 9:55 
JokeRe: What was I thinking Pin
Jecc22-Jan-13 23:56
Jecc22-Jan-13 23:56 
GeneralRe: What was I thinking Pin
Nagy Vilmos23-Jan-13 0:33
professionalNagy Vilmos23-Jan-13 0:33 
GeneralRe: What was I thinking Pin
Jonathan C Dickinson16-Jan-13 21:21
Jonathan C Dickinson16-Jan-13 21:21 
G James wrote:
Later they refactored it to this thinking it was an improvement. Smile | :)

C#
return someBooleanVariable == true ? true : false;

That's pretty poor refactoring, it should have been:
C#
interface IBooleanConverter {
 bool BooleanToBoolean(bool value);
}

class BooleanConverter : IBooleanConverter {
 public BooleanToBoolean(bool value) {
  return value == true ? true : false;
 }
}

interface IBooleanConverterFactory {
 IBooleanConverter CreateBooleanConverterFactory();
}

class ConfigurationBooleanConverterFactory : IBooleanConverter {
 public IBooleanConverter CreateBooleanConverter() {
  return (IBooleanConverter)
         Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverter"]);
 }
}

static class BooleanConverterFactoryFactory {
 public IBooleanConverterFactory CreateBooleanConverterFactory() {
  return (IBooleanConverterFactory)
         Activator.CreateInstance(ConfigurationManager.AppSettings["Types.BooleanConverterFactory"]);
 }
}

// ...

return BooleanConverterFactoryFactory.CreateBooleanConverterFactory().CreateBooleanConverter().BooleanToBoolean(someBooleanVariable == true ? true : false);

It is clear that this is more maintainable. There is currently this method in our code-base because some [one] of our developers is so bad that we need to hold his hand through everything:
C#
public static T As<T>(this object obj) {
 return obj as T;
}

Yes guys, an extension method that replicates a keyword.
He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chinese Proverb]

Jonathan C Dickinson (C# Software Engineer)

GeneralRe: What was I thinking Pin
Sentenryu16-Jan-13 22:23
Sentenryu16-Jan-13 22:23 
GeneralRe: What was I thinking Pin
Jonathan C Dickinson16-Jan-13 22:26
Jonathan C Dickinson16-Jan-13 22:26 
GeneralRe: What was I thinking Pin
Ranjan.D17-Jan-13 11:32
professionalRanjan.D17-Jan-13 11:32 
GeneralRe: What was I thinking Pin
Rob Grainger1-Feb-13 3:21
Rob Grainger1-Feb-13 3:21 
GeneralRe: What was I thinking Pin
Tomz_KV17-Jan-13 2:58
Tomz_KV17-Jan-13 2:58 
RantHappy new year... kind of... Pin
hoernchenmeister15-Jan-13 22:03
hoernchenmeister15-Jan-13 22:03 
GeneralRe: Happy new year... kind of... Pin
PIEBALDconsult16-Jan-13 3:50
mvePIEBALDconsult16-Jan-13 3:50 
GeneralRe: Happy new year... kind of... Pin
hoernchenmeister16-Jan-13 5:06
hoernchenmeister16-Jan-13 5:06 
GeneralRe: Happy new year... kind of... Pin
Matthys Terblanche16-Jan-13 21:08
Matthys Terblanche16-Jan-13 21:08 
GeneralRe: Happy new year... kind of... Pin
Gary Huck17-Jan-13 3:41
Gary Huck17-Jan-13 3:41 
GeneralRe: Happy new year... kind of... Pin
Dave Kreskowiak17-Jan-13 5:26
mveDave Kreskowiak17-Jan-13 5:26 
GeneralRe: Happy new year... kind of... Pin
Jörgen Andersson17-Jan-13 9:04
professionalJörgen Andersson17-Jan-13 9:04 
GeneralRe: Happy new year... kind of... Pin
peterchen28-Jan-13 22:05
peterchen28-Jan-13 22:05 
GeneralRe: Happy new year... kind of... Pin
hoernchenmeister28-Jan-13 22:49
hoernchenmeister28-Jan-13 22:49 
JokeRe: Happy new year... kind of... Pin
Vladimir Svyatski8-Feb-13 10:27
professionalVladimir Svyatski8-Feb-13 10:27 
GeneralJust got an error from VS2012 Pin
Brisingr Aerowing15-Jan-13 8:48
professionalBrisingr Aerowing15-Jan-13 8:48 
GeneralGetting it wrong badly Pin
PIEBALDconsult9-Jan-13 14:12
mvePIEBALDconsult9-Jan-13 14:12 

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.