Live data from Hacker News

Swift Style Guide by GitHub

github.com

41–50 of 52 posts

Re: Swift Style Guide by GitHub

#41

What does Github write that uses Swift? I thought they didn't have an iOS app and I figured their desktop app was some node-webkit or electron based thing based on it being 27mb download.

They may also have internal apps written using Swift which are not public. However it's also nice to have a public style guide.

Re: Swift Style Guide by GitHub

#42

What does Github write that uses Swift? I thought they didn't have an iOS app and I figured their desktop app was some node-webkit or electron based thing based on it being 27mb download.

My feeling is that they want a guide up now from the beginning before they proceed with creating Swift apps.

With Swift now open source and is an increasingly popular language to write brand new apps on Apple's platforms which consistent of iOS, OS X, watchOS, and tvOS.

Re: Swift Style Guide by GitHub

#44
I'm not so sure about "Make liberal use of vertical whitespace to divide code into logical chunks." — it's my tendency to add a lot of vertical whitespace as I write code, but the more I go back and remove it, the more I'm convinced that it wasn't really helpful and that whatever little help it did provide was far outweighed by how much less context could be seen on the screen at one time.

I think of it kind of like prose: we organize related sentences into paragraphs and then have little or no extra vertical whitespace between paragraphs. If you ever find yourself thinking you need some extra level of hierarchy division within a paragraph, you're likely really just needing a new paragraph.

Re: Swift Style Guide by GitHub

#45

Earlier quoted context omitted.

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

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.

Assuming monospaced font.

Re: Swift Style Guide by GitHub

#46

Earlier quoted context omitted.

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

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

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

#47

Earlier quoted context omitted.

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

My editor aligns things for me - no effort at all.

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

#48
post #2

Lost me at "Tabs, not spaces." :p

It is correct. Only fools presenting flawed arguments opine for spaces rather than tabs for indentation.

That's right, indentation, NOT alignment. Spaces are for alignment, tabs for indentation. Not tabs for indentation and alignment, not spaces for indentation and alignment, but rather tabs for indentation and spaces for alignment.

Re: Swift Style Guide by GitHub

#50
post #20

Earlier quoted context omitted.

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

"- only press a single key instead of tapping 2 or 4 times." I use spaces and I still only hit a single key.

[deleted]
Post reply on HN