Click here to Skip to main content
15,900,110 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 one Should do if Program warns you about one's uninitialized variable? Pin
Nagy Vilmos12-Jan-12 1:00
professionalNagy Vilmos12-Jan-12 1:00 
QuestionRe: What one Should do if Program warns you about one's uninitialized variable? Pin
Julien Villers12-Jan-12 4:32
professionalJulien Villers12-Jan-12 4:32 
AnswerRe: What one Should do if Program warns you about one's uninitialized variable? Pin
Nagy Vilmos12-Jan-12 4:47
professionalNagy Vilmos12-Jan-12 4:47 
GeneralRe: What one Should do if Program warns you about one's uninitialized variable? Pin
Julien Villers12-Jan-12 4:54
professionalJulien Villers12-Jan-12 4:54 
GeneralThe result was that people learnt to check for warnings before they checked in their code. Pin
jsc4216-Jan-12 23:01
professionaljsc4216-Jan-12 23:01 
GeneralRe: The result was that people learnt to check for warnings before they checked in their code. Pin
Nagy Vilmos16-Jan-12 23:54
professionalNagy Vilmos16-Jan-12 23:54 
GeneralRe: The result was that people learnt to check for warnings before they checked in their code. Pin
User 274316217-Jan-12 0:55
User 274316217-Jan-12 0:55 
GeneralRe: The result was that people learnt to check for warnings before they checked in their code. Pin
BobJanova17-Jan-12 0:51
BobJanova17-Jan-12 0:51 
I've not seen this with locals too often (the code walker is quite good at checking them), but it is possible to set up conditions such that the code really, honestly, has to assign to x before reading it, but the compiler can't work it out. I think you can do it with

int x;
if(a) x = 5;
// ... some other processing
if(a){
 // something with x, e.g.
 return x;
}


What seems to be more common is the 'member X is declared but never used', if you're implementing an interface but not actually using it. For example let's say we have a collection of objects that we're listening to notifications on, but some of the classes don't actually need to notify:

class DontBother : INotifyPropertyChanged {
 public event PropertyChangedEventHandler PropertyChanged;
}

class MainClass {
 List<INotifyPropertyChanged> sources;

 void SomeMethod(){
  sources.Add(new DontBother());
  // Along with some meaningful classes, obviously
 }
}


The declaration in DontBother will, I think, give you a compiler warning. Maybe it's not exactly this scenario, I forget, but it's similar. Sometimes the only way to get a clean compile is to use #pragma warning disable Sniff | :^) .
GeneralRe: The result was that people learnt to check for warnings before they checked in their code. Pin
YvesDaoust30-Jan-12 0:47
YvesDaoust30-Jan-12 0:47 
GeneralRe: What one Should do if Program warns you about one's uninitialized variable? Pin
OriginalGriff12-Jan-12 21:31
mveOriginalGriff12-Jan-12 21:31 
GeneralRe: What one Should do if Program warns you about one's uninitialized variable? Pin
Mohibur Rashid13-Jan-12 5:12
professionalMohibur Rashid13-Jan-12 5:12 
GeneralCode Repeating Pin
Mohibur Rashid11-Jan-12 19:17
professionalMohibur Rashid11-Jan-12 19:17 
GeneralRe: Code Repeating Pin
RobCroll12-Jan-12 0:26
RobCroll12-Jan-12 0:26 
GeneralRe: Code Repeating Pin
Mohibur Rashid12-Jan-12 2:30
professionalMohibur Rashid12-Jan-12 2:30 
GeneralRe: Code Repeating Pin
fjdiewornncalwe12-Jan-12 3:02
professionalfjdiewornncalwe12-Jan-12 3:02 
GeneralRe: Code Repeating Pin
BobJanova12-Jan-12 23:40
BobJanova12-Jan-12 23:40 
GeneralRe: Code Repeating Pin
Nagy Vilmos12-Jan-12 0:58
professionalNagy Vilmos12-Jan-12 0:58 
GeneralRe: Code Repeating Pin
CDP180212-Jan-12 1:46
CDP180212-Jan-12 1:46 
GeneralRe: Code Repeating Pin
Mohibur Rashid12-Jan-12 2:31
professionalMohibur Rashid12-Jan-12 2:31 
GeneralGem... As time goes by.. PinPopular
virang_218-Jan-12 22:29
virang_218-Jan-12 22:29 
GeneralRe: Gem... As time goes by.. PinPopular
CDP18028-Jan-12 22:48
CDP18028-Jan-12 22:48 
GeneralRe: Gem... As time goes by.. PinPopular
Estys8-Jan-12 22:57
Estys8-Jan-12 22:57 
GeneralRe: Gem... As time goes by.. PinPopular
CDP18028-Jan-12 23:02
CDP18028-Jan-12 23:02 
GeneralRe: Gem... As time goes by.. Pin
virang_218-Jan-12 23:08
virang_218-Jan-12 23:08 
GeneralRe: Gem... As time goes by.. Pin
Estys8-Jan-12 23:15
Estys8-Jan-12 23:15 

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.