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
|

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

Dirk Laurie-2
Oh, this sort of thing I code as:

local _ = coroutine
local cocreate, coresume, costatus
    = _.create, _.resume, _.status


2017-06-15 17:25 GMT+02:00 Soni L. <[hidden email]>:


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.



Reply | Threaded
Open this post in threaded view
|

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

Roberto Ierusalimschy
This may help end the discussion :-)

  "Developers who use spaces make more money than those who use tabs"

  https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/


-- Roberto

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 Thu, Jun 15, 2017 at 10:39 AM, Roberto Ierusalimschy
<[hidden email]> wrote:
> This may help end the discussion :-)
>
>   "Developers who use spaces make more money than those who use tabs"
>
>   https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/
>
>
> -- Roberto
>

Oh wow, that's a fascinating read, and it's amusing that this came out today.

I suspect the arrow of causation is that companies that pay more money
tend to have style guides that demand spaces, and I suspect that's
because very large companies settle on style guides that produce
consistent results across heterogeneous environments (and "no \t
characters" is easy to enforce) and smaller companies like recruiting
talent that worked at the bigger ones.

I know Google's style guide is strictly spaces-only for every language
I ever touched while working there.

/s/ Adam

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
On 15 June 2017 at 16:51, Coda Highland <[hidden email]> wrote:
>
> I know Google's style guide is strictly spaces-only for every language
> I ever touched while working there.


if that's true, it's even more heroic that "go fmt" correctly enforces tabs-only

--
Javier

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 Thu, Jun 15, 2017 at 10:54 AM, Javier Guerra Giraldez
<[hidden email]> wrote:
> On 15 June 2017 at 16:51, Coda Highland <[hidden email]> wrote:
>>
>> I know Google's style guide is strictly spaces-only for every language
>> I ever touched while working there.
>
>
> if that's true, it's even more heroic that "go fmt" correctly enforces tabs-only

I never wrote any Go code. I wrote JS, C++, Java, and Python.

/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 Coda Highland


On 2017-06-15 11:34 AM, Coda Highland wrote:

> 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
>

ಠ_ಠ

FINE...

Spaces are superior because you can instantly tell who wrote what, since
different ppl use different indentation levels. (/s)

(At the end of the day, it all comes down to personal preference. I have
used logarithmic indentation before.)

--
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?)

Thomas Jericke
In reply to this post by Soni "They/Them" L.
On 14.06.2017 21:31, Soni L. wrote:

<tab><tab>local function uh(oops, something, tells, me, this, is, a, giant,
<tab><tab><tab><tab><tab>fail)
<tab><tab>end
I used to align the second parameter line on the opening bracket as well.
They day I stopped to do that made my life a little bit easier.

I came to the conclusion the indentation of parameters should not depend on the length of the function name.
--
Thomas
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
In reply to this post by Soni "They/Them" L.
2017-06-16 2:22 GMT+02:00 Soni L. <[hidden email]>:

> Spaces are superior because you can instantly tell who wrote what, since
> different ppl use different indentation levels. (/s)
>
> (At the end of the day, it all comes down to personal preference. I have
> used logarithmic indentation before.)

Another possibility is Fibonacci indentation, 1,2,3,5,8,13,.... You can think
of it as a generalization of the standard tab stop of 8 spaces, since 8 is
a Fibonacci number.

It has the theoretical advantage of being unbounded, although in practice
it becomes hard for the human eye to distinguish between a line-wrapped
89-space indentation and an empty line followed by an 8-space indentation.
If this bothers you, use reverse Fibonacci indentation, e.g. 8,5,3,2,1.

Most sophisticated of all is bidirectional indentation: reverse Fibonacci for
comments, forward Fibonacci for code. This has an attractive "wavy"
appearance.

             --- First  line of a standalone comment block (13 spaces)
        -- Major heading inside a comment block (8)
     -- Minor heading (5)
   -- Actual comment (3)
  -- allowing three (2)
 -- levels (1)
-- of subdivision (0)
function abc(...)
 local a,b,c = ...
 if type(a)=='string' then
  for pos,char in a:gmatch"()(.)" do
   -- inline comments come at the level where the code would be
   if char:match"%u" then
     while true do
        local p = io.read(1)
        if p:upper():match"Q" then
             os.exit(pos)
        end
     end
   end
  end
 end
end

Such a systems requires some mental arithmetic from the user. It is easy
to say that if such an effort is beyond you, then computer programming
is not a sound career option, but no matter how good you are, some of
your biological CPU gets diverted.

It is therefore nicer to have an editor that allows you to set custom
tab stops (of course, filling it in with spaces; no need to risk your
cushy salary). In the 1980s I used a truly marvellous editor called
PC-Write which allowed that. It is still available (now free, in fact)
but you need a DOS emulator to run it.

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 16-Jun-17 08:03, Dirk Laurie wrote:
> Another possibility is Fibonacci indentation, 1,2,3,5,8,13,.... You can think
> of it as a generalization of the standard tab stop of 8 spaces, since 8 is
> a Fibonacci number.

:-)

Most of my users (gameplay scripters) showed a marked preference for
stochastic indentation.

--
   Enrico

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 Fri, Jun 16, 2017 at 9:06 AM, Enrico Colombini <[hidden email]> wrote:
> Most of my users (gameplay scripters) showed a marked preference for
> stochastic indentation.

Heh, well I've seen a lot of LUA written like that!  So there's
something to be said for auto-indentation. (van Rossum really was onto
something when he made indentation meaningful). tab/space always seems
like such a tiny detail in such a context; people should be encouraged
to _use_ the tab key, whether it produces physical tabs or not.

Reply | Threaded
Open this post in threaded view
|

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

Tony Papadimitriou
But he failed when he left out the exact number of spaces to use for each
level. :)

-----Original Message-----
From: steve donovan

van Rossum really was onto something when he made indentation meaningful


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 Fri, Jun 16, 2017 at 1:14 PM, Tony Papadimitriou <[hidden email]> wrote:
> But he failed when he left out the exact number of spaces to use for each
> level. :)
>
> -----Original Message----- From: steve donovan
>
>
> van Rossum really was onto something when he made indentation meaningful
>

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 Fri, Jun 16, 2017 at 1:53 PM, steve donovan
<[hidden email]> wrote:
> On Fri, Jun 16, 2017 at 1:14 PM, Tony Papadimitriou <[hidden email]> wrote:
>> But he failed when he left out the exact number of spaces to use for each
>> level. :)

Sorry, try again! Yes, indeed! He should have got Biblical "Thou shalt
indent by smiting thy tab key, and indenting with the space bar is an
Abomination"

I'm a space person, and whenever I smite my space bar I feel a little guilty...

As for the LUA kidz, editors that smite the tab key for them is the only way...

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
In reply to this post by steve donovan
2017-06-16 12:57 GMT+02:00 steve donovan <[hidden email]>:

> So there's something to be said for auto-indentation. (van Rossum really
> was onto something when he made indentation meaningful).

It was the feature that charmed me into adopting Python, but also the
feature that a few years later p*issed me off so much that I chucked
Python in favour of Lua.

> tab/space always seems like such a tiny detail in such a context;
> people should be encouraged to _use_ the tab key, whether it
> produces physical tabs or not.

In CSV files, I'll agree with this. In all other files, especially Lua code,
not.

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 Fri, Jun 16, 2017 at 1:58 PM, Dirk Laurie <[hidden email]> wrote:
> In CSV files, I'll agree with this. In all other files, especially Lua code,
> not.

All I mean is this: when indenting, whack the tab key. Keep the space
bar for non-indenting (not at start of line).  The actual character
sequence emitted by that whack is configurable, of course (3 spaces
for Lua, 4 for work, etc)

(Makefiles are always going to be the special case, but configuration...)

12