What's with the five-level shell scripts?

I keep running into people that want to program their shell/perl scripts so that they source other scripts.  Then those scripts call other scripts, and those scripts call other scripts.

At a recent client, we were trying to make sense of their database backup script.  The main script called several other scripts, and those scripts called other scripts, and so on.  It took hours of looking at way too many different scripts to figure out what was going on.

I understand reuse of code, but what's wrong with functions?  At most I can see one giant script that contains common code that gets sourced by other backup scripts.   Or MAYBE several scripts all in one directory that get sourced by other scripts.  Multi-level sourcing, however, is just mean. 😉

Hey, I'm a consultant and I love the billable hours.  Just trying to save you some time.

Can anyone tell me why this is a good idea? 

One thought on “What's with the five-level shell scripts?

  1. hga says:

    Putting on my programmer hat, the key thing here is “Do further sub-levels of scripts implement abstraction levels?”

    Having one include of common for the site stuff is good (“Don’t repeat yourself” (DRY)). Having levels below that can be OK if they represent “black box” abstractions which you shouldn’t worry about unless you have to dive into them for debugging.

    I.e. that one common script could have various system includes (e.g. sockets and above). If it includes some more site specific code where you can’t draw a neat line at the include, you’re in trouble, or, rather, this is the sort of thing that earns you and me money in a hard sort of way (no one likes being told their baby is garbage, however politely or implicitly).

    Note: the Antipatterns book (far more useful than the Gang of Four book if you know high level languages as opposed to C++) comments without citation that only one in five programmers “get” abstraction, and notes that “democratic” development processes mean those who are good at architecture get outvoted.

    In my experience, this seems to be true, and can help explain why so much software is bad all the way through the foundation. Do you think that sysadmins, who generally aren’t serious programmers, to have even fewer who get abstraction?

    – Harold

Leave a Reply

Your email address will not be published. Required fields are marked *