Likewise with continue and break. I think this advice is very bad. All the other recommendations seemed fine.
Likewise with continue and break. I think this advice is very bad. All the other recommendations seemed fine.
Take this contrived example:
function foo(bar)
{
var result, error;
if(bar is null)
{
error = "{NameOf(bar)} is required";
result = null;
}
if(bar is not null)
{
... Main function logic ...
}
return Tuple(result, error);
}
If you can return multiple times instead you'd be able to write: function foo(bar)
{
var result, error;
if(bar is null)
{
return Tuple(null, "{NameOf(bar)} is required");
}
... Main function logic ...
return Tuple(result, error);
}
Assume "Main function logic" has several of nest of its own (branching, loops, etc) it quickly gets difficult to read. success = doOneThing()
&& doSecondThing()
&& doThirdThing()
...
&& doLastThing();
and the more common "traditional" way: success = doOneThing();
if(success)
{
success = doSecondThing();
}
if(success)
{
success = doThirdThing();
}
...
if(success)
{
success = doLastThing();
} Promise.start()
.then(doOnething)
.then(doSecondThing)
.then(doThirdThing)
.then(doLastThing)
.catch(handlesomeerrors)Instead of loading up every language with stupid keywords that are meant to simplify monadic code (but only for one domain), language designers should really take a page out of Haskell or Scala's book and think seriously about unifying on a do notation/for comprehension type construct.
That way regardless of if you're working with promises or not, you don't have to worry about hacking it with && or nesting 10 layers deep with if/else.
Having said that, I'm with the "guard statements" crowd, too, but it would probably be better if that were handled by other parts of the language syntax. Contracts, for example.