|
When I first started learning Linux and programming, I found that solving my own problems was difficult. I had no background in operating systems other than Windows, and I had never programmed before. Without some sort of base knowledge – concepts to live and learn by, you could say – I would never fulfill my yearn for computer mastery. I consider myself lucky. The man who originally introduced me to advanced computer use, also forced me to read a book called The Unix Philosophy, by Mike Gancarz. He made sure I had a tight grasp of the concepts because he knew, as I do now, that I would be using them often. I strongly urge everyone, even Linux guru's, to pick this book up at Amazon.com or your local bookstore.
The following will be your guide, for those of you without the excellent mentor-like figure I had, to the Unix Philosophy.
The book is broken up into two major groups. On one hand, you're given the nine major tenets of the Unix Philosophy. Much time has passed since these were originally written, but they can still be applied to nearly everything we do today. The second part, and what I will be discussing later, consists of the ten lesser tenets. These are, as the name implies, smaller and more specific cases in the philosophy. These ten are not the be-all, end-all as I might suggest the major nine to be, but they are no less useful in completing programming tasks.
The Nine Major Tenets
I. Small is Beautiful
II. Make Each Program Do One Thing Well
I've grouped these first two tenets together because they compliment each other well. To say that a small program is better than a larger one seems like a hasty generalization, and such a quick assumption could surely not hold true for all instances. This is where the tenets have their flexibility, and must be reapplied to more modern computing. The most obvious instance of this is object oriented programming. The two most popular programming languages, and the ones taught at most major universities, are C++ and Java. Both of these languages rely on the idea of reusing smaller classes, like building blocks, to create a larger, more complex program. In this case, when the complex program is completely necessary (such as in the OpenOffice word processor I am using to write this), these first two tenets are still very important because rather than applying to the program itself, they refer to the classes and methods used to make the word processor function as a whole. Having individual classes and methods take care of only what is necessary at the given moment saves necessary resources for other tasks (which is especially important when the user is running certain bloated operating systems). Also, these small, monolithic code blocks can be easily understood and changed for future versions of the software.
{
III. Build a Prototype as Soon as Possible
Many argue (and lecture in class) that the first weeks or months of program development should be spent in design. This is what I've recently been taught, and although the Unix Philosophy says “Prototype ASAP,” I don't think the two oppose one another. Programming, as a whole, is still a relatively new process to us. Humans have been building automobiles for over one hundred years and we've still not perfected it – so I would definitely not expect great programming to come purely from abstract ideas alone. We can really have no sure idea exactly how our functions will react with one another without actually putting them to use. Prototyping dispels so many flaws in design that could have led to weeks of agonizing bug-hunting. No matter what I'm told, I will never spend the first weeks or even days of program design with only a paper and pencil. A blend of deliberation with trial and error will almost always yield the best results.
IV. Choose Portability Over Efficiency
Despite the computer industry's push for faster more efficient programs (especially in video games), portability of software is actually far more efficient a method of distributing faster programs than the common idea of efficient code. How can this be? It's very simple actually. Moore's law states that processor speed will increase exponentially every year. So far, this has proved to be true considering that today I am using a 2.6GHz computer and just 2 years ago I was using a 1.6GHz processor. The idea then, is that the efficiency of software is irrelevant because as time goes on, hardware speed will continue increasing so quickly that last year's slow software will run as fast as last years fast software. What last year's fast software won't be able to do, however, is be easily ported to this year's hardware, which is often very different (take for instance, the coming of the supposed switch from AGP graphics cards to PCI Express). Moreover, portability prevents the extinction of the software that you've worked very hard on – that's right, Darwin's theory of evolution and natural selection applies to programmers too.
V. Store Data in Flat ASCII Files
ASCII – American Standard Code for Information Interchange, simply means plain text. No special formatting, no fancy algorithm's for reading it, no proprietary method of reading or writing it. Not very much can be said about this tenet because it speaks for itself. To put it in terms a businessman can understand: Time is money. It takes time to convert methods of data storage to another form. If the data is openly available for others to review, then why should time and money be wasted deciding and converting between formats. Standards are important for software development, especially in the open source world where the project is coded by a vast community, sometimes without a specific leader. Software doesn't care what format the data is written in. ASCII data storage is the perfect compliment to other eight tenets.
VI. Use Software Leverage to Your Advantage
A phrase taken directly from the book reads: “Good programmers write good code; great programmers borrow good code.” This very concept is exemplified again through Java and C++. Both programming languages make use of previously written classes for things like standard in/out, certain math functions, and GUI interfaces. Open source is such an amazing example of software leverage. Millions upon millions of lines of well-written code are openly available for people to use as they please. The goal of software programmers is said to be the use of computers to solve problems. If your goal is to solve a problem, or find a better solution to a problem, then it is much to your advantage to not waste time rewriting a function that has been written a hundred times over.
VII. Use Shell Scripts to Increase Leverage and Portability
Shell scripts make use of time tested software that work. This is coupled with the sixth and fourth tenets in that the shell commands already exist and are efficient on most, if not all machines. If it can be done quickly with a shell script, then more time can be spent on other problems. This is why I'm such a big fan of Perl – I find it easy to combine Perl and shell scripts to find one solution.
VIII. Avoid Captive User Interfaces
A captive user interface (CUI) is a programmer's method of making software easier to use for people who haven't mastered it yet. An example of this is Fdisk. When you run Fdisk, you are brought to a prompt, giving you specific options for manipulating your disks. This prompt assumes that it is a person running Fdisk, and not a script. This makes programs like Fdisk very challenging to use in automated scripts and with other programs, without some sort of non-CUI parameter being passed. CUI's are also very resource intensive. The most obvious example is the fact that your entire screen is dedicated to making a few changes that could have been made with command line switches. There are some instances where a CUI is completely necessary, and Fdisk may be one of them, but avoiding them when possible is always a safe bet.
IX. Make Every Program a Filter
The title of this tenet is misleading. Every program is already a filter because it takes some sort of input and produces some sort of output. The problem is that most don't take advantage of the obvious benefits available in being a filter. The portability of software, and its ability to interact easily with other programs, is directly related to how well it accepts incoming data and what it does with outgoing data. In order for software leverage to reach its full effect, all software you write should easily work with other software in order to solve problems beyond either program's original intention.
These original nine tenets have been followed closely by some of the best software designers in our industry. The following lesser ten can be taken with a grain of salt, but their importance shouldn't be forgotten.
The Ten Lesser Tenets
I. Allow the User to Tailor the Environment – This allows users complete control over software and adds portability. The ability to customize software allows for change and prevents software extinction.
II. Make Operating System Kernels Small and Lightweight – I'm sure you can see plenty of examples where this has not been respected, and the obvious consequences that have followed have been detrimental. Keeping the kernel small isolates it from features that could potentially freeze the system and cause major problems later.
III. Use Lower Case and Keep it Short – Any avid user of Unix and Linux has noticed that most things are written in lower case letters and are shortened (sometimes unnecessarily, like /usr). I suppose this contributes to the “Small is Beautiful” tenet, and just helps to simplify things.
IV. Save Trees – Despite the existence of 200 GB hard drives, people still insist on printing things out. This is fine, because computer's still aren't reliable, but remember that it's still not possible (or at least easy) to reenter data from paper in order to manipulate it.
V. Silence is Golden – Another common complaint of those new to Unix is that when a command is run, there is often no output. If this is the case, then this is a good sign you're doing something right. If everything has been done as it should, or there is nothing to report (such as when you 'ls' an empty directory), then nothing needs to be said. The often added -v (for verbose) switch can change this when necessary, but saying nothing is usually a good indication of success in the *nix world..
VI. Think Parallel – The idea of this is to keep the CPU busy with tasks when possible, because it often ends up with nothing to do. I don't know how relevant this is today, or even what its intentions were, but I suppose that if something needs done, it might as well be done during idle time.
VII. The Sum of the Parts is Greater Than the Whole – I've expressed this time and again with examples of object oriented programming. Programs can be used for so much more than their original intent, when designed properly.
VIII. Look for the Ninety Percent Solution – I didn't use to believe this, until I found that it continually happened to me. Most of a project can go just as you would expect it to, until the final ten percent needs to be done, and the project must be refined for special cases. It is much more cost and time worthy to simply ignore the last ten percent. When the time comes for those parts to be taken care of, your original ninety percent will play a crucial role in doing so, but for now the project has reached its goal and the problem has been solved.
IX. Worse is Better The main idea of “Worse is Better,” is that simplicity in interface and implementation is much more important than anything else, including correctness, consistency, and completeness (as it has been shown throughout every other tenet). This concept again protects from software extinction and provides the “down and dirty” means of solving a problem.
X. Think Hierarchically – A hierarchy is a rank or order to things. The Unix directory structure is a perfect example of this, but it should also be applied to naming conventions, or whenever order is necessary.
The Unix Philosophy is a guide to the successful use of Unix and some interested techniques in programming. Use what you can from this to improve your work, but what's most important is that you find what fits you best.
Visit the Author's Website here Add as favourites (200)
|
- Please keep the topic of messages relevant to the subject of the article.
- Personal verbal attacks will be deleted.
- Please don't use comments to plug your web site. Such material will be removed.
- Just ensure to *Refresh* your browser for a new security code to be displayed prior to clicking on the 'Send' button.
- Keep in mind that the above process only applies if you simply entered the wrong security code.
| |