Kimlic / iOS

0 stars 0 forks source link

Code style #5

Open dmytronasyrov opened 6 years ago

dmytronasyrov commented 6 years ago

To make code more clean I propose:

  1. Move protocols from the class definitions to extensions. For example: ScanCodeVC conforms to protocol AVCaptureMetadataOutputObjectsDelegate. Instead of place protocol functions into the same class, let's move it to extension. Reasons: easier to find methods of the protocol; huge protocols with many methods can be cutout into a separate file. An example - AllPermissionsVC.
  2. Add access control modifiers to variables and classes - public, private etc. It's better to avoid pubic in favor of internal to reduce linking time of the binary. Internal class should not have higher access control methods - public. Ex: UIUtils.
  3. Model entities that are not related to Core Data should be structs rather than classes.
  4. All classes that are not going to become parent classes should be marked with a final modifier.
  5. Let's use lazy initializations whenever we can.
  6. Let's move all initializations into static facades. Ex.: presentVerificationCodeVC in UIUtils - it's better to move all initialization into a static function inside VerificationCodeVC and make all required dependency injections as function attributes.
  7. Asynchronous pyramids like saveUser in UserBasicProfileInfo should be moved in separate functions to make it easier to read and validate the code.
  8. Remove objective-c legacy self for every property of the class.
  9. Use guard one-linears instead of if statements with one line inside. Ex: if(aaa) { return nil } should be a guard.
  10. All interface initializations in code should happen in loadView instead of viewDidLoad.
  11. Animations should start from ViewDidAppear rather than ViewWillAppear.
  12. do-catch with printing statements inside is not useful. Should be replace to try!. Ex: ScanCodeVC
  13. Remove all prints from the code.
  14. Replace pyramids of if statements to guards or short functions. Ex: WebServicesBaseRequest, TokenWebServiceRequest.
  15. Replace very long functions like in PopupGenerator with several smaller. Replace nil-verification if statements to ?? operator.
  16. Vice-versa, replace long guards with ifs and switches. Ex: AllPermissionsVC.
  17. Make sure there is no strong references cycles to self when closure happens. No example yet, but good to keep this in mind.
  18. Remove double newlines