Swift-style-guide: Two versus four spaces in indent

Created on 21 Jul 2015  路  5Comments  路  Source: raywenderlich/swift-style-guide

Hello everyone!

I would love to discuss two versus four spaces in indent. I know that some Obj-C base methods are simply too long in swift and so every indent space can become handy in legibility. However all Swift templates in Xcode contains four spaces indent which leads me to question. If two spaces are better why Apple didn't come with it in templates?

Is there other reason for two spaces instead of four than length of Obj-C methods?

Cheers!

Most helpful comment

@gregheo Yeah I know. It is spaces versus tabs. It give sense but two spaces are really tight makes it little bit harder to read in my opinion. I just wonder if there is something more behind decision using two spaces instead of four which is Xcode standard.

All 5 comments

It's right there in the guide:

Indent using 2 spaces rather than tabs to conserve space and help prevent line wrapping.

Especially for our books, horizontal space is at a premium. We're not saying two spaces are "better" and than Apple should change it 鈥撀爄t's just best for us.

gah, sorry about accidental close and reopen! stupid github.

@gregheo Yeah I know. It is spaces versus tabs. It give sense but two spaces are really tight makes it little bit harder to read in my opinion. I just wonder if there is something more behind decision using two spaces instead of four which is Xcode standard.

Oh I got it! So this repo is not general recommendation for Swift programmers. It's internal guide for your publications? Then I'm sorry. However I like the idea. I think style guide for languages are very useful.

Well the primary reason for the guide is for our publications. I like to think that nothing we recommend is _poor_ style that would be unsuitable for production use, and I've heard some other style guides use ours as a starting point or just for inspiration.

Personally, I use two-space tabs in "regular" life too, so I might be a bit biased. ;]

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hollance picture hollance  路  28Comments

samkim102 picture samkim102  路  6Comments

luki picture luki  路  3Comments

ghost picture ghost  路  26Comments

gokselkoksal picture gokselkoksal  路  9Comments