Thread overview | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
September 09, 2006 The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
http://www.digitalmars.com/d/dstyle.html "Adhering to the D Style, however, will make it easier for others to work with your D code and easier for you to work with others' D code." "# Hardware tabs are at 8 column increments. # Each indentation level will be four columns." Firstly, what is a "hardware tab"? Secondly, these two quotations seem contradictory. Making your code come out a mess in any editor that isn't configured with a tab size of 8 is certainly not going to make it easier for others to work with your D code. On the contrary, it is much easier if people can read your code regardless of how their editors are configured. Most programmers, at least AFAIK, will decide on an indentation size that they feel comfortable with and configure their editors to use this as the tab size. Of course, there will be some who indent with spaces, not tabs, and some whose editors (either by user pref or by being hard-coded to) automatically convert all tabs to spaces, but that's an aside. 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. Stewart. -- -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y ------END GEEK CODE BLOCK------ My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit. |
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Stewart Gordon wrote: > http://www.digitalmars.com/d/dstyle.html > > "Adhering to the D Style, however, will make it easier for others to work with your D code and easier for you to work with others' D code." > > "# Hardware tabs are at 8 column increments. > # Each indentation level will be four columns." > > Firstly, what is a "hardware tab"? The \t character. > Secondly, these two quotations seem contradictory. Soft tabs and hard tabs aren't the same, although they are often confused. > Making your code come out a mess in any editor that isn't configured with a tab size of 8 is certainly not going to make it easier for others to work with your D code. On the contrary, it is much easier if people can read your code regardless of how their editors are configured. > > Most programmers, at least AFAIK, will decide on an indentation size that they feel comfortable with and configure their editors to use this as the tab size. Of course, there will be some who indent with spaces, not tabs, and some whose editors (either by user pref or by being hard-coded to) automatically convert all tabs to spaces, but that's an aside. > > 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. |
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright Attachments: | Walter Bright schrieb am 2006-09-10: > Stewart Gordon wrote: [snip] >> 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". Thomas |
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | On Sun, 10 Sep 2006 00:47:21 +0100, Stewart Gordon <smjg_1998@yahoo.com> wrote: >"# Hardware tabs are at 8 column increments. ># Each indentation level will be four columns." > >Firstly, what is a "hardware tab"? Secondly, these two quotations seem contradictory. "Soft tab" usually means indent levels done in spaces. Any decent text editors will insert spaces when you press the tab key these days. "Hard tab" means the ASCII tab character, which is evil. -- Remove 'wants' and 'nospam' from e-mail. |
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | On Sun, 10 Sep 2006 11:36:18 +0200, Thomas Kuehne <thomas-dloop@kuehne.cn> wrote: >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. The problem is when you have some indents made of tabs and some made of spaces and some mixed. And then you give the file to some other guy who uses a different tab width. Spaces are always the same width. Indents using spaces will make sense no matter who reads your code or how they configure their editor. Any decent editor can be configured to insert spaces when you hit the tab key. Trust me - this is a good thing. -- Remove 'wants' and 'nospam' from e-mail. |
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Kuehne | 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. There is no way to have them stay lined up if the strides of \t's change.
I started with teletypes (ASR-33's). Moved on to Decwriters, Hazeltine terminals, ADDs terminals, Diablo 630's, FX-80s, IBM PCs, DOS, Windows, CPM-86, OS/2, HP laserprinters, Linux, NT, XP, HTML rendering, Thunderbird email, etc.
One thing they *all* had in common was 8 character hard tabs. Sure, in any particular editor or environment, you can change the hard tab to be 3, 4, or whatever, but as soon as your source leaves that environment, it's screwed up.
If you have a closed source project, that's no problem. But if it's part of the D open source world, it'll be distributed to every type of device, and the only thing in common will be 8 character hard tabs.
Furthermore, if you're working with D and source that has had many different hands working on it, do you want to change your environment's hard tab settings every time you switch files? I don't.
|
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | Many programmer's text editors or IDEs I've worked with use a default tab size of 4. For example, Microsoft Visual Studio and Macromedia Dreamweaver use 4.
In web development, Dreamweaver is pretty much the standard, on Windows. In C++, Visual Studio is.
In these editors, by default, the code looks entirely and completely unreadable. However, code I write always looks readable and understandable in all editors, including nano, kate, etc. which use 8 as a default tab size.
This is because I conform to the following standards:
- never line things up with tabs, except from the gutter.
- never line things up with tabs against non-tab characters.
- always use exactly one tab character per indentation level.
Honestly, when actual tab characters appear in the source, the above style is the prevailing style. People who like otherwise typically use spaces only.
Saying that 8 is common and everywhere is simply incorrect. Even with the editors that use 8 as a default, a large portion of programmers set it to 4, or even 3.
Whether I'm using a screen width of 1024, 1152, 1280, or 640... I should be able to choose how much screen real-estate is eaten by indentation. In D's current style, you are forcing a width on them: you believe that indentation must be 4 spaces, and so everyone must conform to that. If someone prefers 8 spaces, 3 spaces, or 6 spaces... too bad. Sucks to be them. They have to live with YOUR style.
Very nice. I'm glad the D compiler and language was not written the same way. No one would use it. At least with it, I can program in the style I wish to. I'm not forced to follow some uncommon convention.
-[Unknown]
> 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. There is no way to have them stay lined up if the strides of \t's change.
>
> I started with teletypes (ASR-33's). Moved on to Decwriters, Hazeltine terminals, ADDs terminals, Diablo 630's, FX-80s, IBM PCs, DOS, Windows, CPM-86, OS/2, HP laserprinters, Linux, NT, XP, HTML rendering, Thunderbird email, etc.
>
> One thing they *all* had in common was 8 character hard tabs. Sure, in any particular editor or environment, you can change the hard tab to be 3, 4, or whatever, but as soon as your source leaves that environment, it's screwed up.
>
> If you have a closed source project, that's no problem. But if it's part of the D open source world, it'll be distributed to every type of device, and the only thing in common will be 8 character hard tabs.
>
> Furthermore, if you're working with D and source that has had many different hands working on it, do you want to change your environment's hard tab settings every time you switch files? I don't.
|
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Unknown W. Brackets | On Sun, 10 Sep 2006 12:38:42 -0700, "Unknown W. Brackets" <unknown@simplemachines.org> wrote: >In D's current style, you are forcing a width on them: you believe that indentation must be 4 spaces, and so everyone must conform to that. If someone prefers 8 spaces, 3 spaces, or 6 spaces... too bad. Sucks to be them. They have to live with YOUR style. That would be true if the compiler enforced the style rules. But Walter can only enforce his rules within his project - his right, common sense, and I'm sure his main intent. My habit is to indent two spaces at a time. I've posted some snippets in that style. No-one has complained. But if I was contributing to the compiler or library, I'd expect to follow the rules. -- Remove 'wants' and 'nospam' from e-mail. |
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Sun, 10 Sep 2006 11:13:11 -0700, Walter Bright <newshound@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.
Regan
|
September 10, 2006 Re: The D Style and tab sizes | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Come on people, please stop this... With all respect, I believe this is dead end. Walter's opinion here is well known. Not all agree with him (including me - to be honest I completely disagree). BUT! We really can't change anything.
The only wrong thing I see here is heading itself - 'The D Style'. Its too much responsibility to have 'the style' for a language... It could be 'The Phobos Style' or 'Walter's Style'. Or perhaps 'Martian Style' =)
PS. Don't get me wrong - I have nothing against an off-topic discussions, But this time we are just waisting valuable time. Our time, and most importantly, Walter's.
--
serg.
|
Copyright © 1999-2021 by the D Language Foundation