Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

classic Classic list List threaded Threaded
35 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

sur-behoffski
G'day,

Just briefly, one of the places I worked demanded spaces, and no tabs, for
indentation, as well as strictly no trailing whitespace.

The rationale was based around similar grounds to how Git tracks content
via hashes (SHA1, SHA-256, SHA3 or whatever): They wanted to have a
canonical way of representing whitespace within a file, regardless of the
developer, and spaces were chosen simply because they were the lowest
common denominator, and they didn't want to see changes based merely on
how an editor's settings, and/or a developer's typing, affected
whitespace.  The source code control system had hooks to enforce these
rules, and rejected any non-conforming text (written as Perl scripts, so
that it could be smart about exceptions such as Makefiles demanding to
have a tab character, etc.).

cheers,

sur-behoffski
Programmer, Grouse Software

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

GrayFace-2
On Ср 07.06.17 14:35, sur-behoffski wrote:
> Just briefly, one of the places I worked demanded spaces, and no tabs,
> for
> indentation, as well as strictly no trailing whitespace.

For me it's crazy that so many people to this day use spaces instead of
tabs. Using tabs helps avoid all these issues of different preferences
and adds only one: indentation in text from the Internet always has to
be fixed rather than in half the cases, not that it really matters.


Best regards,
Sergey "GrayFace" Rozhenko,                 mailto:[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Enrico Colombini
On 14-Jun-17 17:29, Sergey Rozhenko wrote:
> For me it's crazy that so many people to this day use spaces instead of
> tabs. Using tabs helps avoid all these issues of different preferences
> and adds only one: indentation in text from the Internet always has to
> be fixed rather than in half the cases, not that it really matters.

Many, many years ago I used tabs. I quit when I began to port code among
different editors, environments and people: it was a big, unreadable mess.

Now I only use spaces [1]: what I see is what I see, everywhere.

[1] apart from makefiles, of course.

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Charles Heywood
Project level editorconfig files would help with that. I personally use them with no complaints

On Wed, Jun 14, 2017, 11:57 Enrico Colombini <[hidden email]> wrote:
On 14-Jun-17 17:29, Sergey Rozhenko wrote:
> For me it's crazy that so many people to this day use spaces instead of
> tabs. Using tabs helps avoid all these issues of different preferences
> and adds only one: indentation in text from the Internet always has to
> be fixed rather than in half the cases, not that it really matters.

Many, many years ago I used tabs. I quit when I began to port code among
different editors, environments and people: it was a big, unreadable mess.

Now I only use spaces [1]: what I see is what I see, everywhere.

[1] apart from makefiles, of course.

--
   Enrico

--
--

Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

David Goehrig
I have some code formatting scripts that enforce tab only (and warn if you go over 3 levels of indentation).  The scripts also do some basic heuristics concerning function length, number of static calls, dead code, and generate dot format static call graphs. If I get some time, I'll try to package them up and release them on github.com

I have found going LCD for your solution is always a bad idea, and you need tooling to enforce such policy.  I tend to run these scripts as commit hooks, and it solves the git hash nonsense without wasting developer time.

 As I get older, and my eyes grow weaker, I find the spaces camp to be a major human interface problem.  I can always configure my editor of choice to make tabs legible size (I prefer 8em at 16pt), but can't do the same with spaces. It becomes a serious quality of life issue for some developers. 

Dave

On Jun 14, 2017 12:59 PM, "Charles Heywood" <[hidden email]> wrote:
Project level editorconfig files would help with that. I personally use them with no complaints

On Wed, Jun 14, 2017, 11:57 Enrico Colombini <[hidden email]> wrote:
On 14-Jun-17 17:29, Sergey Rozhenko wrote:
> For me it's crazy that so many people to this day use spaces instead of
> tabs. Using tabs helps avoid all these issues of different preferences
> and adds only one: indentation in text from the Internet always has to
> be fixed rather than in half the cases, not that it really matters.

Many, many years ago I used tabs. I quit when I began to port code among
different editors, environments and people: it was a big, unreadable mess.

Now I only use spaces [1]: what I see is what I see, everywhere.

[1] apart from makefiles, of course.

--
   Enrico

--
--

Software Developer / System Administrator
Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Soni "They/Them" L.


On 2017-06-14 03:54 PM, David Goehrig wrote:
> I have some code formatting scripts that enforce tab only (and warn if
> you go over 3 levels of indentation).  The scripts also do some basic
> heuristics concerning function length, number of static calls, dead
> code, and generate dot format static call graphs. If I get some time,
> I'll try to package them up and release them on github.com
> <http://github.com>.

<tab><tab>local function uh(oops, something, tells, me, this, is, a, giant,
<tab><tab><tab><tab><tab>fail)
<tab><tab>end

Have fun getting that aligned.

(as opposed to mixed tabs+spaces)

>
> I have found going LCD for your solution is always a bad idea, and you
> need tooling to enforce such policy.  I tend to run these scripts as
> commit hooks, and it solves the git hash nonsense without wasting
> developer time.
>
>  As I get older, and my eyes grow weaker, I find the spaces camp to be
> a major human interface problem.  I can always configure my editor of
> choice to make tabs legible size (I prefer 8em at 16pt), but can't do
> the same with spaces. It becomes a serious quality of life issue for
> some developers.
>
> Dave
>
> On Jun 14, 2017 12:59 PM, "Charles Heywood" <[hidden email]
> <mailto:[hidden email]>> wrote:
>
>     Project level editorconfig files would help with that. I
>     personally use them with no complaints
>
>     On Wed, Jun 14, 2017, 11:57 Enrico Colombini <[hidden email]
>     <mailto:[hidden email]>> wrote:
>
>         On 14-Jun-17 17:29, Sergey Rozhenko wrote:
>         > For me it's crazy that so many people to this day use spaces
>         instead of
>         > tabs. Using tabs helps avoid all these issues of different
>         preferences
>         > and adds only one: indentation in text from the Internet
>         always has to
>         > be fixed rather than in half the cases, not that it really
>         matters.
>
>         Many, many years ago I used tabs. I quit when I began to port
>         code among
>         different editors, environments and people: it was a big,
>         unreadable mess.
>
>         Now I only use spaces [1]: what I see is what I see, everywhere.
>
>         [1] apart from makefiles, of course.
>
>         --
>            Enrico
>
>     --
>     --
>     Ryan <[hidden email] <mailto:[hidden email]>>
>     Software Developer / System Administrator
>     https://hashbang.sh
>

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

David Goehrig
On Wed, Jun 14, 2017 at 3:31 PM, Soni L. <[hidden email]> wrote:

<tab><tab>local function uh(oops, something, tells, me, this, is, a, giant,
<tab><tab><tab><tab><tab>fail)
<tab><tab>end

Have fun getting that aligned.

​My scripts won't align that, and they would reject that code for a number of reasons:

1.) too many layers of indentation
2.) too many parameters to  the function
3.) function is a no-op / has no lines of code
etc.

Granted you'd fail code review on my team if you submitted something that looked like that :)

Dave​
Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Coda Highland
On Wed, Jun 14, 2017 at 2:45 PM, David Goehrig <[hidden email]> wrote:

> On Wed, Jun 14, 2017 at 3:31 PM, Soni L. <[hidden email]> wrote:
>>
>>
>> <tab><tab>local function uh(oops, something, tells, me, this, is, a,
>> giant,
>> <tab><tab><tab><tab><tab>fail)
>> <tab><tab>end
>>
>> Have fun getting that aligned.
>
>
> My scripts won't align that, and they would reject that code for a number of
> reasons:
>
> 1.) too many layers of indentation
> 2.) too many parameters to  the function
> 3.) function is a no-op / has no lines of code
> etc.
>
> Granted you'd fail code review on my team if you submitted something that
> looked like that :)
>
> Dave

Mine would end up aligning it as:

\t\tlocal function uh(
\t\t\toops,
\t\t\tsomething,
\t\t\ttells,
\t\t\tme,
\t\t\tthis,
\t\t\tis,
\t\t\ta,
\t\t\tgiant,
\t\t\tfail
\t\t)
\t\t\t-- body
\t\tend

It still wouldn't pass code review, but at least it's consistent. ;)

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Soni "They/Them" L.


On 2017-06-14 04:47 PM, Coda Highland wrote:

> On Wed, Jun 14, 2017 at 2:45 PM, David Goehrig <[hidden email]> wrote:
>> On Wed, Jun 14, 2017 at 3:31 PM, Soni L. <[hidden email]> wrote:
>>>
>>> <tab><tab>local function uh(oops, something, tells, me, this, is, a,
>>> giant,
>>> <tab><tab><tab><tab><tab>fail)
>>> <tab><tab>end
>>>
>>> Have fun getting that aligned.
>>
>> My scripts won't align that, and they would reject that code for a number of
>> reasons:
>>
>> 1.) too many layers of indentation
>> 2.) too many parameters to  the function
>> 3.) function is a no-op / has no lines of code
>> etc.
>>
>> Granted you'd fail code review on my team if you submitted something that
>> looked like that :)
>>
>> Dave
> Mine would end up aligning it as:
>
> \t\tlocal function uh(
> \t\t\toops,
> \t\t\tsomething,
> \t\t\ttells,
> \t\t\tme,
> \t\t\tthis,
> \t\t\tis,
> \t\t\ta,
> \t\t\tgiant,
> \t\t\tfail
> \t\t)
> \t\t\t-- body
> \t\tend
>
> It still wouldn't pass code review, but at least it's consistent. ;)
>
> /s/ Adam
>

\tlocal function f(u)
\t\tlocal v = u:match('^([^/]+)/') ..
\t\t\t\t\t\t\tu:match('^[^/]+/[^:]+(:.*)$')
\t\tif v:match("^nope:") then
\t\t\treturn nil, v:match("^nope:(.*)$")
\t\tend
\t\treturn v
\tend

Have fun getting line 3 to align with line 2 when you're not using tab
width = 2.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Daurnimator
On 15 June 2017 at 14:15, Soni L. <[hidden email]> wrote:

> \tlocal function f(u)
> \t\tlocal v = u:match('^([^/]+)/') ..
> \t\t\t\t\t\t\tu:match('^[^/]+/[^:]+(:.*)$')
> \t\tif v:match("^nope:") then
> \t\t\treturn nil, v:match("^nope:(.*)$")
> \t\tend
> \t\treturn v
> \tend
>
> Have fun getting line 3 to align with line 2 when you're not using tab width
> = 2.

"Tabs for indentation, spaces for alignment"
https://www.emacswiki.org/emacs/SmartTabs
http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_spaces

But also: I don't (nor do I see other people regularly) align lua code.

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Sean Conner
It was thus said that the Great Daurnimator once stated:

> On 15 June 2017 at 14:15, Soni L. <[hidden email]> wrote:
> > \tlocal function f(u)
> > \t\tlocal v = u:match('^([^/]+)/') ..
> > \t\t\t\t\t\t\tu:match('^[^/]+/[^:]+(:.*)$')
> > \t\tif v:match("^nope:") then
> > \t\t\treturn nil, v:match("^nope:(.*)$")
> > \t\tend
> > \t\treturn v
> > \tend
> >
> > Have fun getting line 3 to align with line 2 when you're not using tab width
> > = 2.
>
> "Tabs for indentation, spaces for alignment"
> https://www.emacswiki.org/emacs/SmartTabs
> http://vim.wikia.com/wiki/Indent_with_tabs,_align_with_spaces
>
> But also: I don't (nor do I see other people regularly) align lua code.

  <raises hand> I do.

  https://github.com/spc476/lua-conmanorg/blob/master/lua/string.lua

  -spc (The only rational is that it looks nicer to me)

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Daurnimator
On 15 June 2017 at 15:36, Sean Conner <[hidden email]> wrote:
>   <raises hand> I do.
>
>   https://github.com/spc476/lua-conmanorg/blob/master/lua/string.lua
>
>   -spc (The only rational is that it looks nicer to me)

I used to, but I don't like that it causes diffs to include unrelated
changes (which are my main form of code review).

e.g. say your string.lua file needed the coroutine library: you'd have
make 3 non-functional line edits to keep alignment. consistent.

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Sean Conner
It was thus said that the Great Daurnimator once stated:

> On 15 June 2017 at 15:36, Sean Conner <[hidden email]> wrote:
> >   <raises hand> I do.
> >
> >   https://github.com/spc476/lua-conmanorg/blob/master/lua/string.lua
> >
> >   -spc (The only rational is that it looks nicer to me)
>
> I used to, but I don't like that it causes diffs to include unrelated
> changes (which are my main form of code review).
>
> e.g. say your string.lua file needed the coroutine library: you'd have
> make 3 non-functional line edits to keep alignment. consistent.

  Yes, and for me, that's fine.  Because otherwise the code becomes too
unreadble for *me* when it's not aligned.

  -spc


Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Javier Guerra Giraldez
In reply to this post by Daurnimator
On 15 June 2017 at 05:32, Daurnimator <[hidden email]> wrote:
> "Tabs for indentation, spaces for alignment"


tabs for indentation, no further alignment needed (or wanted)


--
Javier

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

steve donovan
On Thu, Jun 15, 2017 at 10:09 AM, Javier Guerra Giraldez
<[hidden email]> wrote:
> tabs for indentation, no further alignment needed (or wanted)

As a spaces man myself, this is where I definitely agree with you.
Those mixed space/tab files that Vim seems to prefer are a major
irritation. Not the best of both worlds!

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Dirk Laurie-2
2017-06-15 10:42 GMT+02:00 steve donovan <[hidden email]>:

> On Thu, Jun 15, 2017 at 10:09 AM, Javier Guerra Giraldez
> <[hidden email]> wrote:
>> tabs for indentation, no further alignment needed (or wanted)
>
> As a spaces man myself, this is where I definitely agree with you.
> Those mixed space/tab files that Vim seems to prefer are a major
> irritation. Not the best of both worlds!

You can't blame Vim for those, it is merely an editor which supports
syntax highlighting for inter alia Makefiles and Python code. Blame
the designers of those file formats instead.

In fact, Vim offers you the option of translating your tabs into spaces
permanently.

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

steve donovan
On Thu, Jun 15, 2017 at 1:39 PM, Dirk Laurie <[hidden email]> wrote:
> In fact, Vim offers you the option of translating your tabs into spaces
> permanently.

This I know, but whenever I come across a space/tab mix it's usually vim.

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Dirk Laurie-2
2017-06-15 13:56 GMT+02:00 steve donovan <[hidden email]>:
> On Thu, Jun 15, 2017 at 1:39 PM, Dirk Laurie <[hidden email]> wrote:
>> In fact, Vim offers you the option of translating your tabs into spaces
>> permanently.
>
> This I know, but whenever I come across a space/tab mix it's usually vim.

Who typed those tabs in the first place?

Do you have ":set et!" in your .vimrc?

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Coda Highland
In reply to this post by Soni "They/Them" L.
On Wed, Jun 14, 2017 at 11:15 PM, Soni L. <[hidden email]> wrote:

> \tlocal function f(u)
> \t\tlocal v = u:match('^([^/]+)/') ..
> \t\t\t\t\t\t\tu:match('^[^/]+/[^:]+(:.*)$')
> \t\tif v:match("^nope:") then
> \t\t\treturn nil, v:match("^nope:(.*)$")
> \t\tend
> \t\treturn v
> \tend
>
> Have fun getting line 3 to align with line 2 when you're not using tab width
> = 2.

\t\tlocal v =
\t\t\tu:match('^([^/]+)/') ..
\t\t\tu:match('^[^/]+/[^:]+(:.*)$')

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: Tab versus space indentation, and source code control systems... (was: Re: Style guide?)

Soni "They/Them" L.
In reply to this post by Sean Conner


On 2017-06-15 04:00 AM, Sean Conner wrote:

> It was thus said that the Great Daurnimator once stated:
>> On 15 June 2017 at 15:36, Sean Conner <[hidden email]> wrote:
>>>    <raises hand> I do.
>>>
>>>    https://github.com/spc476/lua-conmanorg/blob/master/lua/string.lua
>>>
>>>    -spc (The only rational is that it looks nicer to me)
>> I used to, but I don't like that it causes diffs to include unrelated
>> changes (which are my main form of code review).
>>
>> e.g. say your string.lua file needed the coroutine library: you'd have
>> make 3 non-functional line edits to keep alignment. consistent.
>    Yes, and for me, that's fine.  Because otherwise the code becomes too
> unreadble for *me* when it's not aligned.
>
>    -spc
>
>

I don't align across unrelated variables.

local cocreate = coroutine.create
local coresume = coroutine.resume
local costatus = coroutine.status
local smatch = string.match
local sgsub  = string.gsub
local tsort = table.sort
local tmove = table.move
-- etc

Works fine for me. The different alignment might even be helpful.

--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.


12