5 ms·
Damn, this is fantastic. One big syntactical thing I should really put in a proposal for is null-conditional returns. Turning if(foo != null) return foo;
by daeken 6y ago
Damn, this is fantastic. One big syntactical thing I should really put in a proposal for is null-conditional returns. Turning
if(foo != null) return foo;
Into
return? foo;
It fits perfectly with the existing null coalescing operators and such, while really cleaning up a lot of code.
- mgamache 6y agoI am surprised that hasn't been done already.
- u7u7h 6y agoBetter not.
- dullgiulio 6y agoPerl# basically.
- kungato 6y agoThis look so very prone to cause bugs. Why would you even "return if not null"? I don't think I've been in this situation before. What I do see is if x is null then return something else, but this never
- bradford 6y agoI'm confused. In the first code block, what value is returned if foo is equal to null? If it returns null, what's the difference between: >return foo; and >return? foo; ?
- topkai22 6y agoI think return is too important a keyword to make optional like that. However, I could totally get behind a shortening like if(?foo){return null}
- Koshkin 6y agoAn interesting idea; it could be extended to other constructs - assignments, method calls... Also, imagine having something like this: while (!return? foo) { foo = get_foo(); }
- oaiey 6y agoOh please not. Hiding complexity is dangerous.