Click here to Skip to main content

Welcome to the Lounge

   

For lazing about and discussing anything in a software developer's life that takes your fancy.
The Lounge is rated PG. If you're about to post something you wouldn't want your kid sister to read then don't post it. No flame wars, no abusive conduct and please don't post ads.

Technical discussions are welcome, but if you need specific help please use the programming forums.


 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
GeneralRe: Job Offer!memberColin Mullikin10 Jan '13 - 5:45 
GeneralRe: Job Offer!mvpCPallini10 Jan '13 - 5:52 
GeneralRe: Job Offer!memberjeron110 Jan '13 - 6:23 
GeneralRe: Job Offer!memberMathlab10 Jan '13 - 6:21 
GeneralRe: Job Offer!memberPHS24110 Jan '13 - 6:22 
GeneralRe: Job Offer!mentorDaveAuld10 Jan '13 - 6:45 
GeneralRe: Job Offer!memberWjousts10 Jan '13 - 7:05 
GeneralRe: Job Offer!memberVasudevan Deepak Kumar10 Jan '13 - 7:11 
GeneralRe: Job Offer!memberDeyan Georgiev10 Jan '13 - 8:07 
GeneralRe: Job Offer!memberJörgen Andersson10 Jan '13 - 8:26 
GeneralRe: Job Offer!memberMike Hankey10 Jan '13 - 9:14 
GeneralRe: Job Offer!memberloctrice10 Jan '13 - 9:42 
GeneralMethod chaining with short-circuit parameter evaluation [modified]adminChris Maunder10 Jan '13 - 3:53 
I am testing several depths of properties in an object to make sure they are safe before I call them:
Test.NotNull(myObject);
if (myObject != null)
{
    Test.NotNull(myObject.MyProperty);
    if (myObject.MyProperty != null)
        Test.IsPositive(myObject.MyProperty.Id);
        ...
}
I was thinking it would be really cool to be able to do
Test.NotNull(myObject).NotNull(myObject.MyProperty).IsPositive(myObject.MyProperty.Id);
but obviously if myObject == null then we have a runtime null ref error because, regardless of what the NotNull method returns as part of the chaining, myObject is still null.
 
So this got me thinking: You can do
if (myObject != null && myObject.MyProperty != null)
because of short circuit boolean evaluation in C#, but I was wondering, with my fairly mainstream experience in languages, if there are languages out there that would allow chaining of methods with short circuit evaluation.
 
Essentially you'd have to have the input parameter be resolved after the method was called in order to have the method be able to say "I don't need the input parameter, please just ignore it".
 
Has anyone heard of this? Would it open up a World Of Pain when it comes to debugging? Would it be useful? Am I procrastinating?
 
---
Update: and it turns out this leads into a great discussion of extension methods. See
The Maybe Monad[^] and Chained null checks and the Maybe monad[^] for two ways of achieving this. Once you've done that, debate the correctness of extension methods that are able by design to operate on a null references.
 
I will be over there looking for new, shiny, distracting things.
cheers,
Chris Maunder
 
The Code Project | Co-founder
Microsoft C++ MVP


modified 10 Jan '13 - 16:48.

GeneralRe: Method chaining with short-circuit parameter evaluationmemberDalek Dave10 Jan '13 - 4:00 
GeneralRe: Method chaining with short-circuit parameter evaluationadminChris Maunder10 Jan '13 - 4:07 
GeneralRe: Method chaining with short-circuit parameter evaluationgroupNorm .net10 Jan '13 - 4:14 
GeneralRe: Method chaining with short-circuit parameter evaluationmember Shelby Robertson 10 Jan '13 - 4:41 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberPaul Conrad10 Jan '13 - 6:06 
GeneralRe: Method chaining with short-circuit parameter evaluationgroupNorm .net10 Jan '13 - 20:20 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberDalek Dave10 Jan '13 - 4:18 
JokeRe: Method chaining with short-circuit parameter evaluationmemberdjj5510 Jan '13 - 4:34 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberPIEBALDconsult10 Jan '13 - 4:01 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberMaximilien10 Jan '13 - 4:03 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberpeterchen10 Jan '13 - 4:06 
GeneralRe: Method chaining with short-circuit parameter evaluationadminChris Maunder10 Jan '13 - 4:08 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberpeterchen10 Jan '13 - 4:20 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberDalek Dave10 Jan '13 - 4:26 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberNagy Vilmos10 Jan '13 - 4:34 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberDalek Dave10 Jan '13 - 4:37 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberNagy Vilmos10 Jan '13 - 4:40 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberjibesh10 Jan '13 - 5:03 
GeneralRe: Method chaining with short-circuit parameter evaluationmembergavindon10 Jan '13 - 4:08 
GeneralRe: Method chaining with short-circuit parameter evaluationmvpEspen Harlinn10 Jan '13 - 4:11 
GeneralRe: Method chaining with short-circuit parameter evaluationmvpEddy Vluggen10 Jan '13 - 4:53 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberJörgen Andersson10 Jan '13 - 8:42 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberRanjan.D10 Jan '13 - 5:01 
GeneralRe: Method chaining with short-circuit parameter evaluationmvpDave Kreskowiak10 Jan '13 - 4:13 
GeneralThere is a cool patternmemberEnnis Ray Lynch, Jr.10 Jan '13 - 4:22 
GeneralRe: Method chaining with short-circuit parameter evaluationprotectorPete O'Hanlon10 Jan '13 - 4:43 
GeneralRe: Method chaining with short-circuit parameter evaluationadminChris Maunder10 Jan '13 - 10:53 
GeneralRe: Method chaining with short-circuit parameter evaluationprotectorPete O'Hanlon10 Jan '13 - 10:58 
GeneralRe: Method chaining with short-circuit parameter evaluationmembermark merrens10 Jan '13 - 4:54 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberRoger Wright10 Jan '13 - 5:02 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberNemanja Trifunovic10 Jan '13 - 5:11 
GeneralRe: Method chaining with short-circuit parameter evaluationadminChris Maunder10 Jan '13 - 10:54 
GeneralRe: Method chaining with short-circuit parameter evaluationprotectorAspDotNetDev10 Jan '13 - 5:15 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberszukuro10 Jan '13 - 5:21 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberszukuro10 Jan '13 - 5:18 
GeneralRe: Method chaining with short-circuit parameter evaluationmemberZac Greve10 Jan '13 - 5:41 
GeneralRe: Method chaining with short-circuit parameter evaluationmvpOriginalGriff10 Jan '13 - 5:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 26 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid