[Swift-devel] Code style

Mihael Hategan hategan at mcs.anl.gov
Tue May 14 15:13:16 CDT 2013


On Tue, 2013-05-14 at 19:47 +0000, Ben Clifford wrote:
> 
> > > both of those at the same time is often terrible because of the ambiguity 
> > > in how long a tab is.
> > 
> > There is an option for that, and there you can say 1 tab = 4 spaces.
> 
> But a tab isn't 4 spaces.

A tab is an indentation unit. How big you want to see that on your
screen is another issue.

> 
> If someone wrote some code with tab = 4, and committed it, and someone 
> else wrote code with tab = 8, maybe even in the same file, there is no 
> consistent value to use.

A tab is a tab. You can't write a file with both 8 space tabs and 4
space tabs. You can however write a file with 8 space indentations vs. 4
space indentations if you don't use tabs exclusively.

> 
> The only thing you can consistently do is copy the byte sequence that was 
> used for the block you're adding to. (and even that only works if the 
> indentation in that block is already self-consistent...)

That's what eclipse does I believe. But that obviously doesn't apply for
things with no existing indentation, like new files, or when you hit
enter, delete all leading whitespace, and then start a new method.

> 
> Or ban tabs and reformat them away and dock 1 beer point from each person 
> who committed the tabs in the first place...

I did, and you are not getting beer from me. Tabs are clearly superior.
I should get the beer!

:)

Anyway, I think we should drop this. The mess goes away if you set your
tab size appropriately. This was never a serious issue for me
(regardless what files I looked at - if they mix tab and spaces, you can
infer the tab size and adjust accordingly). It's certainly easier than
having this discussion, and it's a one-time operation if you use any
decent IDE/editor that can save per-project settings. And if you don't
use a decent IDE it probably means you are not spending much time on
this, so you could be nice and follow the existing conventions when
making a change. And if you are not nice, that's ok too. We'll probably
re-format your code when we see it, but please don't complain that the
whole project should be changed because your patch uses a different
indentation scheme.

As for new files, I don't care, but if you use spaces, please use 4 of
them for indentation. 2 is too little visually, and 8 is a waste of
horizontal space. I won't go into the odd numbers.

Mihael





More information about the Swift-devel mailing list