Click here to Skip to main content
12,696,920 members (29,031 online)

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
Andrew Rissing17-Jan-13 10:55
memberAndrew Rissing17-Jan-13 10:55 
JokeRe: What was I thinking Pin
Jecc23-Jan-13 0:56
memberJecc23-Jan-13 0:56 
GeneralRe: What was I thinking Pin
Nagy Vilmos23-Jan-13 1:33
memberNagy Vilmos23-Jan-13 1:33 
GeneralRe: What was I thinking Pin
Jonathan C Dickinson16-Jan-13 22:21
memberJonathan C Dickinson16-Jan-13 22:21 
G James wrote:
Later they refactored it to this thinking it was an improvement. Smile | :)

return someBooleanVariable == true ? true : false;

That's pretty poor refactoring, it should have been:
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:
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 23:23
memberSentenryu16-Jan-13 23:23 
GeneralRe: What was I thinking Pin
Jonathan C Dickinson16-Jan-13 23:26
memberJonathan C Dickinson16-Jan-13 23:26 
GeneralRe: What was I thinking Pin
Ranjan.D17-Jan-13 12:32
memberRanjan.D17-Jan-13 12:32 
GeneralRe: What was I thinking Pin
Rob Grainger1-Feb-13 4:21
memberRob Grainger1-Feb-13 4:21 
GeneralRe: What was I thinking Pin
Tomz_KV17-Jan-13 3:58
memberTomz_KV17-Jan-13 3:58 
RantHappy new year... kind of... Pin
hoernchenmeister15-Jan-13 23:03
memberhoernchenmeister15-Jan-13 23:03 

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.


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 20 Jan 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid