tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Next steps for /bin/sh

I am a lousy typist, and worse proof reader, ...

  | 	if [ "$1" = x]; then echo found an x; fi

should have a space before the ']' of course, omitting that was
not some intentional slight of hand...

And since I am here, I also neglected to show how a truly good lazy
programmer would write that "build_and_run" function, without the
hassle of -e ...

	cd $( find-source-directory "$1" || echo /not/found ) || return 1
	make install || return 1

Even though it seems like more work, having to go add that "|| return 1"
all over the place (especially if the script (which would use exit instead
of return of course) or function is much bigger than this, it really isn't
when you measure the true laziness returns...

First, now we get to avoid needing to deal with setting and resetting -e
correctly, so we don't change it in the environment -- true, in NetBSD's sh
we could do that by

	local -

	set -e
	cd $( find-source-directory "$1" )
	make install
	set +e

and then the right things happen, but that "local -" is not portable, and
it is going to fail when we try moving it to some other shell - which means
more work to figure out why, and how to fix it, which decreases the
overall laziness factor.

And second, we have to figure out why things start failing when someone
tests the results of our set -e version of the function, much debugging,
as we clearly did not really understand -e or we never would have done it
that way in the first place, so the solution would not be immediately
obvious.  Again, major decrease in the laziness result.  And then we have
to rewrite it the way we should have written it in the first place, which
means all the initial work, and the debugging, was truly wasted - a big
laziness no-no!

That's why a good lazy programmer knows that to maximise the amount
of laziness achievable, it is worth doing a little more work, and doing
things correctly the first time, so you never need to come back and
do it all again later when something fails.


Home | Main Index | Thread Index | Old Index