kodecocodes/swift-style-guide

minimal-imports definition is not clear

songbongkeun opened this issue · 5 comments

https://github.com/raywenderlich/swift-style-guide#minimal-imports

it says

Keep imports minimal. For example, don't import UIKit when importing Foundation will suffice.

should be change

Keep imports minimal. For example, don't import Foundation when importing UIKit will suffice.

Both are correct. I think the style guide currently means that if you don't need UIKit, then don't import it. What you are saying is, if you already import UIKit then don't also import Foundation.

@hollance I didn't understand style guide says if you don't need UIKit, then don't import it. I understand style guide says 'Foundation include UIKit so do not import UIKit althought you need. It will import automatically by UIKit`
If my understand not normal, please ignore or close this issue. Thanks.

@songbongkeun I believe the problem is that minimal is not technical jargon.

For you, it meant:
"Do not import two modules, Module U and Module F, when you're importing Module U, which imports Module F".

To some of the rest of us, it means:
"Do not import Module U, which imports Module F, when only Module F is needed".
I'm saying that the word minimal is not universal for this esoteric concept. But I also don't know if there is more accurate common terminology. Minimal, here, refers to the scope of sets (Module U becomes a superset of Module F), not to the number of import statements.

I do think the existing guideline is useful, but if it could be expressed more clearly for you, please make a suggestion as to what would do that. If it confused you, some other people are going to be confused by it as well, and they might not speak up.

@JessyCatterwaul Right. Word minimal is not clear. I don't know owner consider indirectly import but I think minimal should include that(It can be only my opinion..). How about below change?

Minimal Imports

Keep imports minimal. Principal below

  • Minumal Module Import. Example: Don't import UIKit when importing Foundation will suffice.
  • Consider Indirectly Import.

Preferred:

import UIKit
var view: UIVIew
var deviceModels: Array<String>
import Foundation
var deviceModels: Array<String>

Not Preferred:

import UIKit
import Foundation
var view: UIVIew
var deviceModels: Array<String>
import UIKit
var deviceModels: Array<String>

This is fixed in the upcoming update for Swift 4.2.

I used your examples, correcting the array declarations to comply with the style guide. Array<String> is a "not preferred" incantation.