View mode: basic / threaded / horizontal-split · Log in · Help
January 29, 2012
Re: indent style for D
On 01/29/2012 06:54 AM, Trass3r wrote:
>> Personally, I've never understood how anyone can stand anything other
>> than Allman.
>
> Totally agree.

Well, people adapt and values change. :)

I've always used Allman style (although learning its name just now), 
until I started to work at my current job more than 4 years ago. We use 
a modified 1TBS by adding an extra empty line before the else:

    if (x < 0) {
        puts("Negative");
        negative(x);
                                 // <-- added
    } else {
        puts("Non-negative");
        nonnegative(x);
    }

I know there isn't one perfect style, but to me, that's the most 
recognizable one. Of course I can rationalize it too. :)

Ali
January 29, 2012
Re: indent style for D
On 29/01/2012 15:39, David wrote:
> Am 29.01.2012 16:23, schrieb Trass3r:
>> But people are dumb and many project leaders "take no risks" and require
>> spaces everywhere instead of doing it properly.
>>
>> An ever better solution is elastic tabstops, but unfortunately no major
>> editor supports that.
>
> Where's the problem, you can configure most editors to insert N-spaces when pressing the
> tab-key. Some editors are so smart enough to handle the N-spaces still as tabs but save
> them as spaces.

Some editors (Notepad++ included), when configured to do tabs as spaces, only insert _new_ 
tabs as spaces and leave existing tabs as they are.  And when configured do to tabs as 
tabs, leave existing space indentation alone.  And sometimes even more annoyingly, convert 
spaces to tabs when you block indent/outdent or start a new line.  This leads to files 
that multiple people have worked on being indented with a mishmash of tabs and spaces.

Much better would be to:
- Preserve the sequence of spaces and tabs when you block indent/outdent
- When you insert a line break, copy the sequence of spaces and tabs onto the new line
- When you type a tab preceded by only tabs, insert a tab
- When you type a tab preceded by characters other than tabs, insert spaces
- Attempt to detect the indentation style when opening a file and then follow it
- Provide commands to convert tabs to/from spaces separately from block indent/outdent

Stewart.
January 29, 2012
Re: indent style for D
On Sun, 2012-01-29 at 14:09 +0000, Iain Buclaw wrote:
[...]
> The problem is lines with mixed tabs and spaces, and different users
> set their text editors see tabs differently. ie: is your tab-width set
> to 2, 3, 4, or 8?

Isn't that the whole point:  using spaces causes conflict over
indentation, using tabs, 1 per indent level, allows individuals to
choose their indent level.

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
January 29, 2012
Re: indent style for D
On Sun, 2012-01-29 at 09:17 -0500, bearophile wrote:
> Denis Shelomovskij:
> 
> > Am I mistaken? If no, am I missing some major spaces advantages? If no, 
> > lets use tabs.
> 
> D2 style guide should *require* D2 to be edited using a mono-spaced font, and the D2 front-end should enforce this with a "-ms" compiler switch.

Surely this is a level of fascism too far (*).  Using monospace fonts is
just so 1960s, the era of typewriters and 80x25 terminals.  Personally I
am living in an era where monitors deal with proportional fonts which
every experiment done shows are easier to read. Why do so many
programmers hanker for the 1960s and the necessity of monospace fonts,
it seems irrational.


(*) Go imposes these sorts of rules, well at least brace placement and
indentation levels, and it really irritates.  
-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
January 29, 2012
Re: indent style for D
> Ever heard of any one having such a tool?

http://golang.org/cmd/gofmt/
January 29, 2012
Re: indent style for D
On 1/29/2012 5:36 AM, Trass3r wrote:
>> http://www.d-programming-language.org/dstyle.html in regard to
>> indent-style, can someone shed some light what is recommended practice
>> for it within D community?
>
> Everyone thinks his way is the best.

Thats because it is :)



curley braces on the same line as conditionals is a refactoring landmine IMO

I've never seen an editor that would enforce only leading characters on 
a line as tabs, and until all of them do it, spaces is the only thing 
that makes sense to me, since they are never 'wrong'.

The codebase I use at work is full of tabs and I can tolerate them, but 
not knowing how many times to hit backspace on some chunk of code 
containing whitespace in the middle of it is really annoying.  Yes there 
is undo but it starts infringing on my flow (replacing zen with anger, 
the emperor would be pleased . . .)
January 29, 2012
Re: indent style for D
29.01.2012 20:48, bearophile пишет:
> Stewart Gordon:
>
>> What do you mean by the "D2 front-end"?
>
> It was one of my first attempts at humor :-)
>
> Bye and sorry,
> bearophile

Thanks for explicitly defining that! You just saved a lot of my time. )
January 29, 2012
Re: indent style for D
On 29/01/2012 17:29, Russel Winder wrote:
> On Sun, 2012-01-29 at 14:09 +0000, Iain Buclaw wrote:
> [...]
>> The problem is lines with mixed tabs and spaces, and different users
>> set their text editors see tabs differently. ie: is your tab-width set
>> to 2, 3, 4, or 8?
>
> Isn't that the whole point:  using spaces causes conflict over
> indentation, using tabs, 1 per indent level, allows individuals to
> choose their indent level.

It is.  But mishmashing tab and space indentation causes far worse conflict.

Iain - I take it you meant that mishmashing, combined with users having different tab size 
settings, causes a problem.  Correct?

Stewart.
January 29, 2012
Re: indent style for D
29.01.2012 18:09, Iain Buclaw пишет:
> On 29 January 2012 14:04, Denis Shelomovskij
> <verylonglogin.reg@gmail.com>  wrote:
>> 29.01.2012 15:21, Alex Rønne Petersen пишет:
>>
>>> On 29-01-2012 10:15, Gour wrote:
>>>>
>>>> Hello!
>>>>
>>>> It was mentioned in #D that gdc will probably adapt its code to GNU code
>>>> style and I wonder, seeing no recemmendation in
>>>> http://www.d-programming-language.org/dstyle.html in regard to
>>>> indent-style, can someone shed some light what is recommended practice
>>>> for it within D community?
>>>>
>>>>
>>>> Sincerely,
>>>> Gour
>>>>
>>>
>>> Phobos generally uses 4-space indentation.
>>>
>>
>> I don't think there is the best coding style (personally I like both K&R and
>> Allman styles). IMHO things are different with indention. Why does Phobos
>> use 4-space indentation?
>>
>> The following article (IMHO) completely covers tabs vs spaces problem:
>> http://www.emacswiki.org/cgi-bin/wiki/TabsAreEvil
>>
>> It shows that tabs (in spite of the article title) are really good and
>> should be used always (and only) for indention. Looks like Allman style
>> doesn't prevent this (if it does, what is the reason?). So:
>> * Such tab using shows respect to a programmer allowing him to configure tab
>> size as he prefer.
>> * Sometimes indention should be changed for a particular using.
>> * Worst of all, sometimes same code is used in different places where
>> different indention levels are expected.
>> * Using spaces guarantee that code will look same in every editor but it is
>> the simplest and not the most convenient way, the code should look _good for
>> every editor user_, not _same_, so it tears down our community.
>> * It's less comfortable to use spaces for indention in every editor I use
>> (at least because spaces allows caret position in the middle of indention
>> and pressing<one of delete one char keys>  deletes one space instead of the
>> indention level, so it's easy to accidentally broke indention and use, e.g.
>> 7 instead of 8 spaces).
>>
>> And this isn't only a theory. In practice:
>> * I've never liked 8-chars indention, so I feels myself bad in d-p-l.org
>> sources. Probably I'm not the only one.
>> * I accidentally brake spaces indention sometimes. Probably I'm not the
>> less-trained-in-printing one.
>> * Some time ago a ebook version of d-p-l.org has been created. Walter had to
>> change every 4-spaces indention in examples to 2-spaces indention for
>> convenience reading on small PPC screen.
>> * Now everyone see 2-spaces indented examples in d-p-l.org instead of his,
>> probably, preferred 4-spaces indented.
>>
>> Am I mistaken? If no, am I missing some major spaces advantages? If no, lets
>> use tabs. Perhaps, there is no tool that will convert (convert right, not
>> somehow, see article) tabs<->spaces in D code.
>
> The problem is lines with mixed tabs and spaces, and different users
> set their text editors see tabs differently. ie: is your tab-width set
> to 2, 3, 4, or 8?
>

Example, please.

P.S.
Have you read the article? (I'm asking that just because I can't imagine 
an example or I don't clearly understand what do you mean)
January 29, 2012
Re: indent style for D
On Sun, 2012-01-29 at 18:07 +0000, Stewart Gordon wrote:
[...]
> It is.  But mishmashing tab and space indentation causes far worse conflict.

Agreed -- homogeneity of the character used for spacing, especially
indentation, is critical .  I think this is why Emacs (*) has a way of
converting all leading whitespace to either tabs or spaces.

(*) The only one true editor (and kitchen sink).
-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder@ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel@russel.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder
1 2 3 4 5 6 7
Top | Discussion index | About this forum | D home