Indenting

TAIT's Organization

T8s.Org: Tait's; TAIT's; and Taits!

 
 
 
 

Archives

Categories

Indenting

Most people do not realize it today, but 40 years ago a “tab” was virtually hard coded to eight spaces!

Think about indenting your program with eight spaces, on a 24 or 40 character monitor! It is easy to see why people started using the “half tab” or “quarter tab” (4 spaces or 2 spaces respectively!). In that day, there was good reason not to use the tab key, and little opposition to using spaces.

Then a new group of programmers grew up. Like everyone, someone taught them something, and they thought it was right… 4 spaces, 2 spaces, or indent with tabs. Today, every program I know of, and use, you can set for yourself if your tab is equal to 4 spaces, 2 spaces or even 3 or 1 space. Truthfully I know of no one that uses 8 spaces anymore, that was actually for the very old teletypes! I know, I worked on them!

Today, conversion from tabs to spaces and spaces to tabs is a trivial thing. So here is the Logical Standard…

Tabs should be used at the beginning of the line,
and spaces should be used mid-line for alignment and readability.

TAIT Style Indenting

if ( 'the good stuff' != $good ) {
[tab]exit; // Stop this script!
} else {
[tab]$go = 'full speed';
[tab]if ( 'good' == $test[ 'too' ] ) {
[tab][tab]$foo    = 'somevalue';
[tab][tab]$foo21  = 'somevalue2';
[tab][tab]$foo987 = 'somevalue3';
[tab][tab]$foo5   = 'somevalue4';
[tab]}
}

For associative arrays, values should start on a new line and tab indented:

$my_array = array(
[tab]'foo'    => 'somevalue',
[tab]'foo2'   => 'somevalue2',
[tab]'foo345' => 'somevalue3',
[tab]'foo7'   => 'somevalue3',
);

TAIT Style Indenting
Your source would look something like this in your editor…

if ( 'the good stuff' != $good ) {
     exit; // Stop this script!
} else {
    $go = 'full speed';
    if ( 'good' == $test[ 'too' ] ) {
        $foo    = 'somevalue';
        $foo21  = 'somevalue2';
        $foo987 = 'somevalue3';
        $foo5   = 'somevalue4';
    }
}

For associative arrays, values should start on a new line and tab indented:

$my_array = array(
    'foo'    => 'somevalue',
    'foo2'   => 'somevalue2',
    'foo345' => 'somevalue3',
    'foo7'   => 'somevalue3',
);

Logical Conclusion

I am sure people will emotionally argue this point, but the truth is that in the 21st Century…

Hard tab indentation at the beginning of lines increase cross-platform functionality and readability.

Spaces used mid-line for alignment, likewise increase cross-platform functionality and readability.

If you do not believe this, try it for a few months until you get used to it and you will likely not go back to what you are doing now.

Style Conventions

Due to the limitations of CSS2 and CSS3 in regard to tab length, we will be using four spaces on the website to more closely approximate the visual effect of using tabs while writing code. With the release and use of CSS4 we will be updating our pages to use real hard tabs.

The above visual effects would look like this…

Tabs should be used at the beginning of the line,
and spaces should be used mid-line for alignment and readability.

TAIT Style Indenting

if ( 'the good stuff' != $good ) {
    exit; // Stop this script!
} else {
    $go = 'full speed';
    if ( 'good' == $test[ 'too' ] ) {
        $foo    = 'somevalue';
        $foo21  = 'somevalue2';
        $foo987 = 'somevalue3';
        $foo5   = 'somevalue4';
    }
}

For associative arrays, values should start on a new line:

$my_array = array(
    'foo'    => 'somevalue',
    'foo2'   => 'somevalue2',
    'foo345' => 'somevalue3',
    'foo7'   => 'somevalue3',
);