Click here to Skip to main content
15,867,756 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 this 'null' check doing here... Pin
Richard Deeming9-Jul-13 5:54
mveRichard Deeming9-Jul-13 5:54 
GeneralRe: What this 'null' check doing here... Pin
David C. Thompson10-Jul-13 3:05
David C. Thompson10-Jul-13 3:05 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed10-Jul-13 19:39
professionalMohammed Hameed10-Jul-13 19:39 
GeneralRe: What this 'null' check doing here... Pin
David C. Thompson10-Jul-13 20:51
David C. Thompson10-Jul-13 20:51 
GeneralRe: What this 'null' check doing here... Pin
Mark Starr10-Jul-13 4:25
professionalMark Starr10-Jul-13 4:25 
GeneralRe: What this 'null' check doing here... Pin
KP Lee10-Jul-13 20:19
KP Lee10-Jul-13 20:19 
GeneralRe: What this 'null' check doing here... Pin
Mark Starr11-Jul-13 5:18
professionalMark Starr11-Jul-13 5:18 
GeneralRe: What this 'null' check doing here... Pin
KP Lee15-Jul-13 20:32
KP Lee15-Jul-13 20:32 
This thread started with:
C#
List<Employee> employees = new List<Employee>();
if (employees != null){
   employees = GetEmployees();
There are layers of things wrong with just this bit of code. "employees = new ..." created a new object, it is impossible for "if (employees != null)" to return false. (Others have said memory critical operations might have problems, but that can't happen because if it did happen, the behavior of C# is to throw an error. In which case, "if" would never execute. THEN it executes "employees = GetEmployees()" which threw the "=..." part of "employees = new ..." into the trash. NOW employees may or may not be null and no if checking if it is null or not is done, it just assumes that since it wasn't null it still isn't null. It is incredible how much bad code can be compressed into so little space, so it is worth posting in the weird and wonderful. The following code has exactly the same amount of effective error checking as the first bit of code:
C#
List<Employee> employees = GetEmployees();
Sorry, I wasn't trying to bash you about your knowledge. (I was teasing you about your mistyping, thinking you wrote it while tired and made an easy mistake to make when you are tired.) The SQL part of what I said was just trying to teach you a little bit of the difference between the two languages. Everyone is ignorant in some things in their lives. Nothing wrong with that. There is something wrong with wanting to be ignorant and I didn't think that was happening with you.
GeneralRe: What this 'null' check doing here... Pin
Mark Starr16-Jul-13 5:20
professionalMark Starr16-Jul-13 5:20 
GeneralRe: What this 'null' check doing here... Pin
GrumpyPants10-Jul-13 5:33
GrumpyPants10-Jul-13 5:33 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed10-Jul-13 19:35
professionalMohammed Hameed10-Jul-13 19:35 
GeneralRe: What this 'null' check doing here... Pin
RafagaX10-Jul-13 5:43
professionalRafagaX10-Jul-13 5:43 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed10-Jul-13 19:43
professionalMohammed Hameed10-Jul-13 19:43 
GeneralRe: What this 'null' check doing here... Pin
Michael Losinski10-Jul-13 5:59
Michael Losinski10-Jul-13 5:59 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed10-Jul-13 19:45
professionalMohammed Hameed10-Jul-13 19:45 
GeneralRe: What this 'null' check doing here... Pin
KP Lee10-Jul-13 21:01
KP Lee10-Jul-13 21:01 
GeneralRe: What this 'null' check doing here... Pin
Michael Losinski11-Jul-13 3:40
Michael Losinski11-Jul-13 3:40 
GeneralRe: What this 'null' check doing here... Pin
Nilesh Shahane10-Jul-13 8:07
Nilesh Shahane10-Jul-13 8:07 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed10-Jul-13 19:47
professionalMohammed Hameed10-Jul-13 19:47 
GeneralRe: What this 'null' check doing here... Pin
MainFrameMan_ALIVE_AND_WELL$$10-Jul-13 10:03
MainFrameMan_ALIVE_AND_WELL$$10-Jul-13 10:03 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed10-Jul-13 19:48
professionalMohammed Hameed10-Jul-13 19:48 
GeneralRe: What this 'null' check doing here... Pin
KP Lee10-Jul-13 21:13
KP Lee10-Jul-13 21:13 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed10-Jul-13 21:15
professionalMohammed Hameed10-Jul-13 21:15 
GeneralRe: What this 'null' check doing here... Pin
DarkChuky CR12-Jul-13 12:56
DarkChuky CR12-Jul-13 12:56 
GeneralRe: What this 'null' check doing here... Pin
Mohammed Hameed14-Jul-13 19:46
professionalMohammed Hameed14-Jul-13 19:46 

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.