GitHawk icon indicating copy to clipboard operation
GitHawk copied to clipboard

Code structure: Adopt swift best-practices

Open flowinho opened this issue 6 years ago • 1 comments
trafficstars

Hello their contributors!

I've been looking into the code and saw that GitHawk suffers a bit from the MassiveViewController syndrom that many applications do.

If you e.g. have a look at Settings you'll notice that the ViewController declaration itself adopts several protocols. While is perfectly fine it creates some problems:

  • Adopting the protocols inside the viewController declaration decreases the readability of the viewcontroller by bloating up the class itself.
  • It tempts to create a lot of stored properties to handle states of these protocols (which might not be necessary) which can result in too many variables being declared and use -> less testability.
  • Decreasted testability of the viewController itself.

I suggest to move the protocol adoption at least into extension declarations to keep the code more readable and have the Swift compiler detect unnecessary stored variables.

e.g. https://medium.com/swift2go/i-swift-part-1-organize-uiviewcontroller-classes-by-using-extensions-63957e517c65

For more information please have a look at:

  • https://docs.swift.org/swift-book/LanguageGuide/Protocols.html (Adding Protocol Conformance with an Extension)
  • https://docs.swift.org/swift-book/LanguageGuide/Extensions.html

Best wishes from southern germany.

flowinho avatar Jul 11 '19 07:07 flowinho

Nice

Sent with GitHawk

RuthSoledadPlaza12 avatar Aug 08 '19 07:08 RuthSoledadPlaza12