Re:New IDE: code bubbles
by Retric on Wednesday March 10, 2010 @05:59PM
(#1182269)
Try catching a block that does that is actually less code than a long set of conditionals. Granted it's basically saying:
But, staying on the happy path until you can demo something is often useful. I think the problem is how you transition from demo to production worthy code.
[ Parent
| on HN ]
if (foo!=null && (a = foo.bar()) && a != null && ...
a = foo.bar() will always evaluate to true as the assignment shouldn't ever fail. Of course, in compiled languages I'm sure there will need to be a declaration of 'a' but if there is a possibility to reuse temp variables then could work.
However, if you are coding in C/C++ (and to a similar extent Java, there really is no way around it.
This could be an example of why hybrid functional, imperative, and object oriented languages are becoming popular because the programmer can pick the paradigm that most suits the problem.
That's not the same since you are executing the bar method multiple times.
If you really want to get picky,
return foo.bar().baz().qux() * 2;
Could become:
Bar bar = foo.bar();
if(bar == null) handleBarNull();
else {
Baz baz = bar.baz();
if(baz == null) handleBazNull();
else {
//(assuming qux is a value)
return baz.qux() * 2;
}
}