Submitted by David Van Brink (not verified) on Mon, 12/17/2007 - 06:54.
I like it. I especially of course like the important observation -- too infrequently taught or even known -- that code can and should have a good narrative.
I'd usually solve the above like so (in no particular language):
proc what(a):
d = null;
{
b = null;
c = null;
if(a) b = a.foo();
if(b) c = b.bar();
if(c) d = c.baz();
}
if(d) print("ok!");
It's lengthy, but avoids the Russian Dolls. Nested conditionals do impose more state to think about as you read or step the code. It does have the Baton aroma (nice phrase), alleviated by scoping. And it has a positive side too: it makes stepping with line-oriented debuggers quite pleasant.
Narratively... hmm, there's possibly a lot of entering empty rooms, I guess.
Regardless of that, however, thanks for the clear introduction to the monad concept! And the other morsels in your blog, sir.
Oliver Steele lives in Western Massachusetts and commutes to downtown LA, where he is bringing an operating system from handwaving to reality. He was the architect of OpenLaszlo, the author of PyWordNet and other open source projects. His interests include programming languages, knowledge representation, information visualization, and math education. [more]
I like it. I especially of course like the important observation -- too infrequently taught or even known -- that code can and should have a good narrative.
I'd usually solve the above like so (in no particular language):
proc what(a):
d = null;
{
b = null;
c = null;
if(a) b = a.foo();
if(b) c = b.bar();
if(c) d = c.baz();
}
if(d) print("ok!");
It's lengthy, but avoids the Russian Dolls. Nested conditionals do impose more state to think about as you read or step the code. It does have the Baton aroma (nice phrase), alleviated by scoping. And it has a positive side too: it makes stepping with line-oriented debuggers quite pleasant.
Narratively... hmm, there's possibly a lot of entering empty rooms, I guess.
Regardless of that, however, thanks for the clear introduction to the monad concept! And the other morsels in your blog, sir.