Thread: Tabs or Spaces?
View Single Post
Old 18th June 2008
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

Well, this is something I am only mildly opinionated on believe it or not !!!

When it comes to things like tabs or spaces, where to put the brace, etc of coding style. I don't really care what _other_ people do as long as they _do_ it consistently.


I'm accustomed to writing code in a manor that I could write rule-sets based on my formating style to modify things if necessary, and where possible in a style that can hold up to my changing tastes.


When it comes to tabs or spaces for indentation, I use both but in different ways.


I prefer tabs when individual indentation levels are 'thick', for example I typically use an 8-space tabstop setting for C or C++ code. For that I find tabs easier to work with then spaces.


But when the indents are smaller (e.g. 2-4 spaces) I'll normally use spaces, if it's a moderate level (4sp) I'll pick either tabs or spaces for a given language and stick with it.

For example, I use a 4 space tabstop for Perl but 4 spaces for Python.



The thing that makes me some what different, is when I use tabs for indents -- I use spaces for whitespacing.

Code:
void
foo_funct() {
        char *src, *dst;
        int reallylong;
        long int arglist;
        size_t size;

        ...

        while ((var = bar_func(src, dst, size,
tab     |  spaces              reallylong, arglist)) != whatever) {
                if (var == something) {
                        do_whatever(var);
                }
        }
}
The idea is, the tab per indent level can be any thing but in order to align things, such as the the second line of bar_func()'s arguments. Tabs to indent to the same level as the above, then spaces to align the remainder.


That way I can change the tabstop from being 2, 4, 6, 8, 10, 12, whatever is desired and the code will still be 'logically' aligned rather then out of order.


The way I write changes from time over the years, I do however take sometime when using a language a lot. To sit down and play with formating and find "what works for me". Some of my idiosyncrasies in style are connected to my ways of thinking but most have a solid reason behind it, that I feel is worth while if ones going to do it consistently.


Note:

where logically aligned is defined as how I feel it is logical to align it.

I also have an 80-90x25-35 cols by lines editor to use most times and I limit lines to < 70-80char by nature.


Generally I do find spaces easier to work with when using most editors 'autoindent' capabilities.
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote