Image of the glider from the Game of Life by John Conway
Skip to content

Proposed Alias and Script Standards

I spent the majority of my weekend either working on a few web projects for clients or actually going to work. This means I never really had much time to myself. However, working on web development for 36 hours straight can do some crazy things to your mind. I needed a break, so I headed to the #ubuntu IRC channel.

It wasn't long after I got in that a chap entered and needed help writing an alias. He wanted the alias to process command line arguments for another program. Of course, most of the channel was asking why he just didn't run the program itself. But, he wanted help, so a few of us jumped in.

Basically, he has a command line program that asks the user for input from the keyboard. The program was lengthy, and the input from the keyboard was the same every time he ran the program. He was hoping to simplify the process using an alias. He wanted to run the alias, and have all of his keyboard input processed in the alias itself. After looking at his code, it was clear that although an alias would accomplish his goal, he needed to write a script bar minimum, if not a program. His alias was over 600 characters long! We helped him get it setup, and we advised him strongly against an alias, and to use a Bash script. He complied, and hopefully he worked it out.

After thinking about this for a couple hours, I thought I would set some standards and see what the online community thinks. These standards seem to make sense for me, and I have subconscienciously followed them every time I have approached something in Linux.

Aliases should follow the Two Breath standard. This means that you should be able to say out loud your alias in a maximum of two breaths, inlcuding punctuation. Although aliases can be quite powerful, they aren't designed to replace scripts, and they definitely are not designed to replace programming. The purpose of aliases is to make moving around the system easier by setting environment variables, copying, renaming and moving files, and a few other mundane tasks. In other words, if on a Linux system, you find yourself executing the same programs in the same order, an alias is fitting to simplify the process. If your alias fails the Two Breath standard, your next option should be a script.

Scripts should follow the Two-Fifty standard. Scripts, albeit Bash scripts, C-shell scripts or Perl scripts can be lengthy, but, they should be short overall. The Two-Fifty standard states that your script should fit in no more than 250 lines. Now, with that said, coding as we all know can be productive, but it can also be fun. You could write your entire program on one line saying you met the Two-Fifty standard easily, even though your program has 10,000 characters. Obfuscating code can make a program fit very well inside 250 lines. Part of the Two-Fifty standard also states that each statement belongs on it's own line including braces ({}). This makes code readable and maintainable. Don't forget comments! If your script isn't commented, even if it is only 100 lines long, your breaking the Two-Fifty standard. Yes, this standard includes commenting. Now, if it is clear your script is going to break the Two-Fifty standard, then you need to be looking at a full blown program, whether it be C++, Python, or Perl.

Now, these standards I came up with myself. Like I said, they make a great deal of sense to me. Looking over many of the scripts and aliases I have on my system, all of them fall under these two standards, which was quite surprising. I have seen other scripts and aliases that fail these two standards miserably. Looking at them, it is obvious why a these two standards should be in place. There is no need to write lengthy aliases or thousand-line scripts. There are tools for maximizing efficiency, readability, portability and speed, and I think keeping these standards in mind when coding will help reach these goals.

{ 2 } Comments

  1. Little Money using Firefox 1.5.0.11 on Windows XP | April 4, 2007 at 12:15 am | Permalink

    [...]tools for maximizing efficiency, readability, portability and speed, and I think keeping these standards in mind when coding will help reach these goals.[...]

  2. Little Money using Firefox 1.5.0.11 on Windows XP | April 4, 2007 at 1:27 am | Permalink

    work for development!

Post a Comment

Your email is never published nor shared.

Switch to our mobile site