Monday, June 20, 2011

Hiding behind #debug

I saw code like this today...

_for a_key,a_pred _over preds.fast_keys_and_elements()
_loop
#debug write(a_key, ": ", a_pred)
_endloop


... clearly the developer had wanted to only have the output write while in #debug mode. That seems like a good idea to me. But what would make the code even more efficient is to put the entire _loop structure behind a #debug tag like this...

#debug _for a_key,a_pred _over preds.fast_keys_and_elements()
#debug _loop
#debug write(a_key, ": ", a_pred)
#debug _endloop


... that way you don't have to worry about the expense of running an iterator at all when not in debug mode.

No comments: