Live data from Hacker News

Swift Style Guide by GitHub

github.com

11–20 of 52 posts

Re: Swift Style Guide by GitHub

#11
post #2

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

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

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

#12
post #2

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

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

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

#13
post #8

Earlier quoted context omitted.

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

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.

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

#14
post #13

Earlier quoted context omitted.

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.

Sounds to me like you're saying there's no objectively correct answer that works for all languages and situations, which I agree with.

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

#15
post #9
post #5

> Fewer debates about aesthetics Are you kidding? You just added one. De gustibus non est disputandum.

Dictatorial decree is a valid solution to some debates, especially the neverending ones. I actually think it's one of Golang's best features, having a built-in "go fmt" tool that automatically applies an opinionated style guide, which makes it so every single Go repo I find in the wild has code that's formatted in the manner to which I'm most accustomed.

Yes, Swift should do the same thing. Format on save. So much time is wasted on style guides.

Re: Swift Style Guide by GitHub

#16

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

Spaces are more consistent than tabs. https://www.jwz.org/doc/tabs-vs-spaces.html

Someone doesn't like HackerNews.

Re: Swift Style Guide by GitHub

#17
> Not even leading indentation on blank lines.

Ugh. I wonder how is this a real issue?

Non-indented blank lines ARE an issue though - they make code editing more cumbersome, requiring pressing the tab key far more often.

Also, tabs are for bros.

Re: Swift Style Guide by GitHub

#18
post #17

> Not even leading indentation on blank lines. Ugh. I wonder how is this a real issue? Non-indented blank lines ARE an issue though - they make code editing more cumbersome, requiring pressing the tab key far more often. Also, tabs are for bros.

If your editor doesn't do smart tabbing, I'm sorry for you. Not to mention that random trailing whitespace is just annoying.

Re: Swift Style Guide by GitHub

#19
post #15
post #9

Earlier quoted context omitted.

Dictatorial decree is a valid solution to some debates, especially the neverending ones. I actually think it's one of Golang's best features, having a built-in "go fmt" tool that automatically applies an opinionated style guide, which makes it so every single Go repo I find in the wild has code that's formatted in the manner to which I'm most accustomed.

Yes, Swift should do the same thing. Format on save. So much time is wasted on style guides.

If only Apple cared enough in XCode to provide one.

Re: Swift Style Guide by GitHub

#20
post #2

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

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.

Post reply on HN