Code Indentation: Tabs Versus Spaces

Everything not related to Prince of Persia should be discussed here.

Moderator: English Moderator Team

Post Reply
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3176
Joined: April 9th, 2009, 10:58 pm
Contact:

Code Indentation: Tabs Versus Spaces

Post by Norbert » June 18th, 2017, 5:57 pm

Well, I created this document.
Code_Indentation_Tabs_Versus_Spaces.pdf
Took me longer to write than I expected, but I like the result.

David
The Prince of Persia
The Prince of Persia
Posts: 1512
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Code Indentation: Tabs Versus Spaces

Post by David » June 24th, 2017, 12:45 pm

Interesting.
Are you planning similar documents about other aspects of coding style? :)

Btw, in the list of "programming languages that use whitespace to determine functionality" (last page), you should add Python.

I looked through the SDLPoP sources.
Indentation is mostly done using tabs, but there are a few places that use spaces.
I guess I should fix that.

Btw, the forum does something odd with tabs:

Code: Select all

	t
t	t
tt	t
ttt	t
Each tab becomes 3 spaces.
Not a tab-stop at every third character position, but always 3 spaces.

User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 3176
Joined: April 9th, 2009, 10:58 pm
Contact:

Re: Code Indentation: Tabs Versus Spaces

Post by Norbert » June 24th, 2017, 5:29 pm

David wrote:Are you planning similar documents about other aspects of coding style? :)
No, life's too short. :)
David wrote:Btw, the forum does something odd with tabs:

Code: Select all

	t
t	t
tt	t
ttt	t
Each tab becomes 3 spaces.
Not a tab-stop at every third character position, but always 3 spaces.
Not odd. Fixed tab stops are not (yet widely) used on the web. The tab-size CSS property, which does not yet work on mobile phones, also only specifies the "number of spaces in a tab" (source). So, "always [n] spaces" is their only option. (Regardless, they should just leave tabs alone.) Also, what you did will never work anyway. You used hard tabs for (mid-line) alignment. From the software's perspective, what you posted could've come from anywhere. Tab stop widths vary. What you posted only looks correct with tab stop width 4 and up. Paste it in an editor and set the tab stop to 2 or 3; you'll see your formatting breaks.

David
The Prince of Persia
The Prince of Persia
Posts: 1512
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: Code Indentation: Tabs Versus Spaces

Post by David » June 26th, 2017, 6:44 pm

Norbert wrote:Also, what you did will never work anyway. You used hard tabs for (mid-line) alignment.
Ah, yes. So I inadvertently posted another argument against using tabs for alignment. :)

Post Reply