The D Style and tab sizes

Regan Heath regan at netwin.co.nz
Sun Sep 10 15:31:29 PDT 2006


On Sun, 10 Sep 2006 15:22:21 -0700, Sean Kelly <sean at f4.ca> wrote:
> Regan Heath wrote:
>> On Sun, 10 Sep 2006 11:13:11 -0700, Walter Bright  
>> <newshound at digitalmars.com> wrote:
>>> Thomas Kuehne wrote:
>>>> Walter Bright schrieb am 2006-09-10:
>>>>> Stewart Gordon wrote:
>>>>>> AFAIC, people who use tabs but indent by half a tab at a time are  
>>>>>> painting themselves into a corner.  We should aim to write code  
>>>>>> that'll be readable in any editor, whatever its tab size setting.
>>>>> There's no way to do that and have hard tabs. The only way to  
>>>>> achieve that is by using spaces only. Using spaces only is one way  
>>>>> to conform to the D style guide.
>>>>  What editor/IDE are you using?
>>>>  gedit(GNOME), kedit(KDE) and vi/nano(shell) are all basic editors and
>>>> all have a way to set the display with of "\t" characters. Microsoft's
>>>> Notepad is probably the only default editor incapable of changing the
>>>> display with of "\t".
>>>
>>> That's true, but is not the problem. Consider:
>>>
>>>     foo();             // comment
>>>     bar + 4 *18 - foo();    // comment
>>>
>>> Suppose \t's are used to line up the comments.
>>  That's where the mistake/error has been made, NEVER use \t to line  
>> text up, ALWAYS use space.
>>  Tabs are for indentation only, or in other words, indenting the text  
>> essentially defining your left hand margin, nothing else!
>>  As long as you only use tabs to indent the left hand margin, and  
>> spaces to align text people can use any tab size they like and it will  
>> always work perfectly.
>
> Try viewing Walter's code with a tab width of less than 8. Since his  
> indentation depth (4 chars) is less than the hard tab width, functions  
> typically look like this:
>
> void fn()
> {
> int x;
> for(;;)
> {
>      blah blah;
> }
> }
>
> I thought this was actually a deliberate indenting style until I changed  
> my tab width to 8 and suddenly most of the code became properly indented  
> (I say most because some places are indented with all spaces instead of  
> tabs--probably from submitted patches).

I know all about Walters code, he's mixing tabs and spaces for  
indentation, that's the problem. If he only used tab for indenting his  
left hand margin, and only use spaces when he wanted to line text up (from  
the tabbed margin onward) then there would be no problems, ever, with any  
tab width.

In other words, it should go: Any number of \t followed by any number of  
spaces, but never tab, space, space, space, space, tab, etc

Regan



More information about the Digitalmars-d mailing list