Formatting of bootscripts

Bruce Dubbs bdubbs at swbell.net
Tue Jan 4 19:36:39 PST 2005


Ian Molton wrote:

> 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.
>
>
> which is interesting, or perhaps misleading, I cant tell based on my 
> own experiences. 


Ian, I respect your opinions, but you make my case.  You say below that 
when you first started, you found 8 character indents nearly 
unreadable.  The fact that you now find them natural only shows that you 
can adapt to a less than optimal presentation.  I note that 8 character 
tabstops reduce the available line length quite a bit.  That leads to 
line wrapping which is really ugly and difficult to read.

> I started off like most programmers of my age on BASIC, and used no 
> indentation whatsoever (by the way, that would be Acorn BASIC, not the 
> crappy basics available on the PCs of the era).
>
> later I moved to one, then 2 spaces for indentation.
>
> when I started learning other languages (including, but not limited 
> to, C) I moved to 4 spaces, but of my own volition as I was teaching 
> myself, and had NO net conectivity at that time. I wrote my own 
> windowing library for RISC OS at about this time, and it was the only 
> library I used in my applications (beyond C-lib), so my choice was, 
> truely my own.
>
> later, I got on the net and found that 8 character indents were 
> common, yet I found them nearly unreadable. however I persevered, 
> hooked by the diversity of code available, and nowadays find 8 
> character indentation 100% natural and anything else (7 even) to be 
> uncomfortable.
>
> of course, there are a number of variables I coudlnt control here, not 
> least of which my age, which may very well have impacted my 
> preferences, and my growing exposure to other peoples code since I got 
> 'online'.
>
>> I teach students NOT to use tabs by inserting the following in .vimrc:
>>
>> 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.
>
>
> My take on this is that its easier to teach students to use spaces 
> universally because then alignment AND indentation is easy - simply 
> add/remove spaces to taste.
>
> My take, however, is that this is doing them as much a disservice as 
> teaching them to use tabs universally.
>
> if one uses tabs for indentation (indicating depth of nesting) then 
> spaces may be used for the distinct task of aligning related 
> information on the same indentation level. (see my eg. in my other post)


I guess I don't see the visual difference between spaces and tabs in 
this situation.  I agree that if you take the care explained in the 
earlier post, then another experienced programmer can adjust the 
tabstops without harming the indentation level.  The problem I have is 
just getting students to think about formatting at all. 

> I urge you to reconsider the way you teach this to your students. 
> Using spaces may be the quick (easy) fix, but it teaches no discopline 
> regarding keeping track of the indentation / nesting. I find that 
> people who understand this early on tend to become the better 
> programmers.

I'll think about it, but in some cases it's difficult.  In some of my 
classes (e.g. html), the students have the option to use any operating 
system.  Notepad doesn't have the option to set tab stops.

I also teach that different organizations have different coding 
standards and they have to adapt to that.  Open source, of course, has 
its own standards, but not every project uses the same standards. 

For instance, many projects use:

if ( some condition) {
   code;
}

but others use

if ( some condition)
{
   code;
}

To create visually balanced braces.

Also, the classic (K&R) pointer declaration is 'int *var', but the type 
is really a pointer and other projects (Strostrup) use 'int* var' or 
even 'int * var'.
 
There are some coding standards I personally like better than others, 
but to get along, participants have to adapt to the standards, not the 
project. 

  -- Bruce





More information about the lfs-dev mailing list