On 03/10/2014 08:33 PM, Kurtis Rader wrote:
Please don't use that technique unless it's in the context of something
atypical like a debugger. It's a really bad software pattern. It's spooky
action at a distance. It's a form of monkey-patching. it practically
guarantees hard to debug errors. Plus a large number of other problems.
Don't do it. Be explicit about return values. If you want a caller of
function2 to exit immediately have function2 return non-zero and test for
that. For example,
function2() { print I failed to do my job; return 1 }
function1() { if ! function2; then; print unexpected failure; return 0; fi;
print life is good }
Hmmm, sobering advice. I'm always looking to expand the techniques
available to me,
and Peter's 'trap' idea does/would streamline my code for this one
particular problem,
which is just a very short helper function called in almost all of my
other functions in
a trivial and routine sort of way where there are unlikely to be any
strange issues. Still, this
trap thing violates the rule of least surprise and breaks the basic
rules of code flow, so
I do take your point. I guess if this sort of thing can be considered
'standard zsh practice'
then I'm inclined to keep it, but if not, then out it goes. But all the
'sh's' have so many
abominable and dirty practices anyway that this trap would hardly stand
out ;-)