News for hackers. Stuff that matters.
Re:Swift Style Guide by GitHub by tjallingt on Monday January 25, 2016 @07:16AM (#10966731)
Tabs beat spaces in every single way;

- only press a single key instead of tapping 2 or 4 times.

- alter their width within your IDE to suit your preferences.

- they are "designed" to intent a piece of text with unlike spaces which are "designed" to break words.

But use whatever you like as long as it's consistent :)

Re:Swift Style Guide by GitHub by krisdol on Monday January 25, 2016 @08:46AM (#10967097)
"- only press a single key instead of tapping 2 or 4 times."

I use spaces and I still only hit a single key.

Re:Swift Style Guide by GitHub by MrScruff on Monday January 25, 2016 @08:52AM (#10967129)
Tabs beat spaces in every single way;

Spaces look the same in whatever application you might be using to view a source file, be it any number of random command line tools, or fully fledged IDEs.

Re:Swift Style Guide by GitHub by nielsbot on Monday January 25, 2016 @03:28PM (#10969713)
Assuming monospaced font.
Re:Swift Style Guide by GitHub by jahewson on Monday January 25, 2016 @11:35AM (#10968091)
Ah, tabs are bad, because if you let people choose their own tab widths then it becomes impossible to align anything anymore. It makes it impossible to align anything which is != a tab width.

Tabs aren't "designed" for indenting text: they're a hangover from typewriters, where they were literally metal tabs used for creating tables. Tabs don't carry semantics - that's the job of the language's syntax. Tabs as a concept should be confined to history IMHO, especially their implementation in modern word processors, where they just give you ad-hoc semantic-less tables.

The tab key on the otherhand is great for indenting - in most sensible editors it will insert a configurable number of spaces. Perfect.

Re:Swift Style Guide by GitHub by masukomi on Monday January 25, 2016 @04:18PM (#10970021)
This is so very wrong....

> tabs are bad, because if you let people choose their own tab widths then it becomes impossible to align anything anymore.

In what world is that true. If you indent your code with tabs, and I indent your code with tabs and I show my tabs as 4 chars wide and you show yours and 8 EVERYTHING IS STILL ALIGNED. It's just greater or lesser levels of indentation. You only have problems when you MIX tabs and spaces. Be consistent in your use and you won't have problems.

> It makes it impossible to align anything which is != a tab width.

Yes. So? Don't mix tabs and spaces.

> Tabs aren't "designed" for indenting text: they're a hangover from typewriters, where they were literally metal tabs used for creating tables.

What is a table? It's a tool FOR ALIGNING MULTIPLE COLUMNS OF TEXT... so yes, they ARE designed for indenting text.

For a more fully thought out argument on why it's a dick move to use spaces as pretend tabs: http://weblog.masukomi.org/2010/07/26/why-you-should-never-i...

Re:Swift Style Guide by GitHub by Stratoscope on Monday January 25, 2016 @12:17PM (#10968413)
There is an easy solution to the alignment problem: don't align stuff.

I haven't used column alignment in at least 20 years. I don't miss it at all, and I'll never go back to aligning things.

Column alignment causes far too many problems. Once you give it up, any advantage of spaces over tabs disappears. Code written without alignment reads the same whatever you use for indentation, and it is even perfectly readable in a proportional font!

I've written a few comments on HN about the problems with column alignment and the advantages of an alignment-free style. Here are a couple of previous discussions with specific examples:

https://news.ycombinator.com/item?id=10206860

https://news.ycombinator.com/item?id=9469713

Re:Swift Style Guide by GitHub by Zikes on Monday January 25, 2016 @07:23AM (#10966764)
We really shouldn't get into this, but I can't help myself.

- Every single text editor that's come after notepad.exe has had automatic tab/space conversion. Pressing tab inserts N spaces, pressing backspace un-indents N spaces, etc.

- In some languages, this is not a feature. 2-character tabs, using two tabs to indent for alignment:

    var myVar = 1,
        otherVar = 2,
        anotherVar = 3;
Opened later in an editor using 4-character tabs:

    var myVar = 1;
            otherVar = 2,
            anotherVar = 3;
- {}[]<> and more aren't used for anything close to their original literary intent.
Re:Swift Style Guide by GitHub by oneeyedpigeon on Monday January 25, 2016 @07:27AM (#10966777)
Tabs should never be used for lining things up, for that very reason. In your example, you've stopped 'indenting' and started 'aligning'. And it's only 'working' because "var " % 2 == 0; other language keywords will screw that up.
Re:Swift Style Guide by GitHub by Zikes on Monday January 25, 2016 @07:32AM (#10966801)
Sounds to me like you're saying there's no objectively correct answer that works for all languages and situations, which I agree with.
Re:Swift Style Guide by GitHub by scrollaway on Monday January 25, 2016 @07:39AM (#10966827)
There... is, actually. If you don't actually attempt to align the variable names, then what you're doing is "indenting items in a list", essentially.

In general, you should avoid aligning unless the readability gains are significant. Aligning things means that you end up re-aligning when you add or remove longer items. This increases maintenance and pollutes diffs (which also means code reviews and git logs).

Re:Swift Style Guide by GitHub by jahewson on Monday January 25, 2016 @11:56AM (#10968252)
My editor aligns things for me - no effort at all.
Re:Swift Style Guide by GitHub by scrollaway on Monday January 25, 2016 @10:49PM (#10971718)
You are creating effort for the people who review your code. On their behalf, please stop, it's tedious.
Re:Swift Style Guide by GitHub by luso_brazilian on Monday January 25, 2016 @07:21AM (#10966756)
> But use whatever you like as long as it's consistent

I would add "as long it's consistent with the codebase and the practices of the project"

Mixing tabs and spaces in a project is very unpleasant and changing one for the other wreaks havoc in the blame functionality

Re:Swift Style Guide by GitHub by jonhohle on Monday January 25, 2016 @11:01AM (#10967861)

    git blame -w …
Re:Swift Style Guide by GitHub by insulanian on Monday January 25, 2016 @10:32AM (#10967682)
> only press a single key instead of tapping 2 or 4 times.

Consider changing your editor.

Re:Swift Style Guide by GitHub by scrollaway on Monday January 25, 2016 @07:30AM (#10966787)
Well said. I see tabs as an accessibility feature.

https://leclan.ch/tabs

But like you said, consistency matters a lot more.

Re:Swift Style Guide by GitHub by oneeyedpigeon on Monday January 25, 2016 @07:28AM (#10966781)
I prefer tabs BUT ... don't you have to throw out any line-length requirements if you use them?
Re:Swift Style Guide by GitHub by krisdol on Monday January 25, 2016 @08:48AM (#10967104)
Nah just hard wrap at the line length.

Imagine everyone setting their preferred tab width and hard wrapping.

That'll be fun for looking at VCS diffs...

Re:Swift Style Guide by GitHub by overcast on Monday January 25, 2016 @10:29AM (#10967663)
So setup your tab to insert four spaces, like every editor on the planet.
Re:Swift Style Guide by GitHub by rsendv on Monday January 25, 2016 @07:20AM (#10966752)
Yeah, consistency trumps preference.
Re:Swift Style Guide by GitHub by aubergene on Monday January 25, 2016 @12:10PM (#10968358)
I agree, particularly with Elastic Tabstops

http://nickgravgaard.com/elastic-tabstops/

[dead]
Re:Swift Style Guide by GitHub by tychuz on Monday January 25, 2016 @08:08AM (#10966938)
Someone doesn't like HackerNews.
Re:Swift Style Guide by GitHub by napperjabber on Tuesday January 26, 2016 @03:54AM (#10972485)
Hah, news to me.