Formatting of bootscripts

that weasel weasel at beyondnormal.org
Tue Jan 4 14:06:00 PST 2005


On Tue, 2005-01-04 at 10:20 -0600, Bruce Dubbs wrote:
> In basic research on program readability, indentation of 2-4 characters 
> has been found to be optimal.  Eight space indenting was evaluated to be 
> as bad as no indenting at all.

I think that is highly dependant on the medium in which your viewing the
text.  On a 72dpi monitor with a 12pt font 2-4 spaces looks great.  On
my laptop with the (~140 dpi) and a 12pt font, 4 spaces is less than a
quarter of an inch.  It also dependant on the person reading the text,
and what is comfortable for them.

The same applies to column width.  Most people are comfortable with 80,
and if it grows much past that find it difficult to find the beginning
of the next line of text.  Others have not problem with it.

Using tabs and line wrapping lets the end user decide how they want to
view the material.  Using spaces and hard breaks for formatting forces
the end user to see things how you want them to be seen.

> I teach students NOT to use tabs by inserting the following in .vimrc:
> set expandtab  "convert new tabs to spaces
> set tabstop=4  "Number of spaces that a <Tab> in the file counts for.
> set shiftwidth=4  "Number of spaces to use for each step of (auto)indent.
> 
> Tabs can be converted to spaces with :expandtab or spaces converted to 
> tabs with :retab

Careful :retab can easily screw up all of your strings, for example a C
program.


> Similar things can be dome with emacs.  less can be adjusted with export 
> LESS='-x4 -M'
> 
> Sometimes a conscientious programmer puts some effort into making their 
> code readable.  Changing the tabstops can ruin that when a tab inserts 
> the equivalent of (say) 6 spaces for a 8 character tabstop.  (Or 2 
> spaces for a 4 character tabstop).  For that reason, I instruct my 
> students to use the entries in .vimrc above and it eliminates the 
> problem.  Remember that programs/scripts are read many more times than 
> they are modified. 
>
> I realize that most of the responses above requested that tabs be left 
> in the file.  That is personal preference (habit) based on learning how 
> to handle what is considerered by many programming methodology 
> researchers a poor practice started long ago when programming tools 
> (editors, line terminals, etc) were much more primitive.
> 
> All that said, I can live with either because my .vimrc and LESS 
> settings can handle it, but for the reasons above prefer spaces.
> 
>   -- Bruce
> 

Tabs can be properly handled by every text editor I can think of and if
you are a real stickler for spaces, then tabs can easily and properly be
converted to spaces.  Spaces on the other hand cannot be eaisly and
properly be converted back to spaces.  i.e. Using something like :retab
on source code is very dangerous as you may endup converting tab within
strings.

In short: Leave it as tabs and everyone can be happy.




More information about the lfs-dev mailing list