Visit Jeremy's Blog.
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 LinuxQuestions.org The 6th ArchToad's Laws of Scripting

Notices

Rate this Entry

# The 6th ArchToad's Laws of Scripting

Posted 11-05-2009 at 10:25 AM by archtoad6

Preface
"Clarity, Brevity, Generality"
Paterned after the "Liberté, égalité, fraternité" of the French Revolution, these are the watch words with which I introduced a presentation on programming I gave to HLUG (H=Houston) about 4 years ago. I quote them here, 1st because they are appropriate, & 2nd because I want my copyright & other intellectual property claim on the public record.

I have strong opinions on programming, especially scripting & this is my attempt to set some of them down.

Background
This blog entry was triggered by this post of mine. I got to end of what I was writing, & realized that I was going off on a tangent/rant that didn't belong in the thread, but deserved to be preserved.
Quote:
I probably would have made "\$LIVECDLABEL" something like "\$LABEL" on the theory that the whole thing is about burning a live CD, so "LIVECD" is redundant. I know the idea of short variables flies in the face of C programmers practice, but I think that it works in a bash scripting environment.
. . .
[formula moved & expanded]
The formula I did not post is now:

The Law of Maximum Variable Length
Variables should be as short as possible -- brevity; w/o becoming confusing -- clarity.

Code:
`l(V) = s(V)^X / f(V)^Y * Z`
where:
l(V) is the minimum allowable length in letters of variable V
s(V) is the span in lines of variable V
f(V) is the frequency of variable V
X, Y, Z are yet-to-be-determined empirical constants

The "math" is tongue in cheek, but the idea is serious. I believe that shorter tokens are easier to understand. I think there a psychological studies that show that this is true. If any reader knows of any, please post a link.

The Law of Capitalization
Unless the scripting language has a specific convention to the contrary, the names of variables should be all UPPERCASE. (It's not shouting because the names are short. )

The Law of Standard Variable Length
All similar variables should have the same number of characters; even if some must be unnaturally lengthened: "INN & OUT" or "IN_ & OUT". This aids in following the Law of Alignment.

The Law of Alignment
Insert extra space to make things line up -- it's easier to read. This kind of "easier to read" is also quicker to read & w/ better comprehension.

The Law of Indenting
All logical blocks should be indented. (Python indenting syntax should be adopted by all remotely similar languages. The ideal indent is 3 spaces. 2 & 4 are acceptable. 1 space indenting can be used in an extreme case (HTML examples come to mind.) 5 or more spaces are unnecessary. Tabs are an abomination because they cause eyesores, & because they mess block mode in some text editors. Fortunately pr -t -e (RTM pr) can fix this. See the section "Code block 4" in http://www.linuxquestions.org/questi...23#post3745723

Enough for now, maybe more later ...
Posted in Uncategorized
« Prev     Main     Next »

All times are GMT -5. The time now is 03:11 AM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -