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

 
GeneralReturn the correct null Pin
Bernhard Hiller25-Jan-17 22:55
Bernhard Hiller25-Jan-17 22:55 
GeneralRe: Return the correct null Pin
User 1013254625-Jan-17 23:14
User 1013254625-Jan-17 23:14 
GeneralRe: Return the correct null Pin
Sander Rossel26-Jan-17 1:40
professionalSander Rossel26-Jan-17 1:40 
GeneralRe: Return the correct null Pin
User 1013254626-Jan-17 2:18
User 1013254626-Jan-17 2:18 
GeneralRe: Return the correct null Pin
Richard Deeming26-Jan-17 1:48
mveRichard Deeming26-Jan-17 1:48 
GeneralRe: Return the correct null Pin
Lutosław25-Jan-17 23:24
Lutosław25-Jan-17 23:24 
GeneralRe: Return the correct null Pin
KarstenK26-Jan-17 0:32
mveKarstenK26-Jan-17 0:32 
GeneralRe: Return the correct null Pin
F-ES Sitecore26-Jan-17 0:58
professionalF-ES Sitecore26-Jan-17 0:58 
Actually they are different things, kind of. The FirstOrDefault is going to return

default(ISomething)

Your assertion that "something" is going to be null is actually an assumption. The code would indeed be redundant if it was this

ISomething something = listOfSomethings.Where(...).OrderBy(...).FirstOrDefault();
if (something != null)
{
    return something;
}
else
{
    return default(ISomething);
}


however we're getting into new levels of pedantry here Big Grin | :-D I sometimes write things like in the OP if I want to make it explicitly clear that it is expected that the function can return a null value.
GeneralRe: Return the correct null Pin
Richard Deeming26-Jan-17 1:59
mveRichard Deeming26-Jan-17 1:59 
GeneralTales from J.S. Crypt, Day 3 Pin
Marc Clifton13-Jan-17 3:31
mvaMarc Clifton13-Jan-17 3:31 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Wastedtalent13-Jan-17 3:38
professionalWastedtalent13-Jan-17 3:38 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Marc Clifton13-Jan-17 4:01
mvaMarc Clifton13-Jan-17 4:01 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Wastedtalent13-Jan-17 4:23
professionalWastedtalent13-Jan-17 4:23 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
OriginalGriff13-Jan-17 4:40
mveOriginalGriff13-Jan-17 4:40 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Marc Clifton14-Jan-17 10:40
mvaMarc Clifton14-Jan-17 10:40 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Nagy Vilmos13-Jan-17 4:39
professionalNagy Vilmos13-Jan-17 4:39 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Jon McKee14-Jan-17 11:02
professionalJon McKee14-Jan-17 11:02 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Bernhard Hiller15-Jan-17 20:57
Bernhard Hiller15-Jan-17 20:57 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Harrison Pratt16-Jan-17 2:40
professionalHarrison Pratt16-Jan-17 2:40 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Greg Lovekamp17-Jan-17 4:19
professionalGreg Lovekamp17-Jan-17 4:19 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Harrison Pratt17-Jan-17 12:10
professionalHarrison Pratt17-Jan-17 12:10 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Sander Rossel22-Jan-17 0:25
professionalSander Rossel22-Jan-17 0:25 
GeneralRe: Tales from J.S. Crypt, Day 3 Pin
Jörgen Andersson22-Jan-17 8:10
professionalJörgen Andersson22-Jan-17 8:10 
GeneralTales from the Crypt Pin
Marc Clifton12-Jan-17 3:38
mvaMarc Clifton12-Jan-17 3:38 
GeneralRe: Tales from the Crypt Pin
MarkTJohnson12-Jan-17 4:08
professionalMarkTJohnson12-Jan-17 4:08 

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.