08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
Be armed to the teeth to maintain a high quality iOS code
1. Be armed to the teeth
to maintain a high quality iOS code
Anastasia Kazakova
2. Program vs Product
• ACM-ICPC: Solve quicker than others, pass tests, start another task.
• Real word: How often do you rewrite the project from scratch?
3. What is code quality?
Some say:
Easy to understand
Easy to maintain
Easy to use
Works right
Some say:
high quality == meets
requirements
Some say (CISQ):
Reliability
Efficiency
Security
Maintainability
Size
10. Possible problems
• Dead code
• Copy/paste,
duplicated code
• Hiding scope
• Too much happening
at one place
• Code style
inconsistency
• Patterns violations
• Bad coding practices
• Over-generalized code
• …
11. What do we have to do?
1. Follow the code style
2. Generate code
3. Run static analysis
4. Refactor
5. Run unit tests
13. Armed to the teeth #1:
Code style
• Apple’s coding guidelines for Cocoa
• raywenderlich.com:
• https://github.com/raywenderlich/objective-c-style-guide
• https://github.com/raywenderlich/swift-style-guide
• GitHub:
• https://github.com/github/objective-c-style-guide
• https://github.com/github/swift-style-guide
• Spotify
• https://github.com/spotify/ios-style
14. Armed to the teeth #1:
Code style
Clang-Format:
• Stand-alone, tools integration.
• Plugin for Xcode: https://github.com/travisjeffery/ClangFormat-
Xcode with option to enable format on save.
• Indents, braces, breaks, line length, base styles, aligns, and much
more.
• Objective-C, no Swift :(
16. Armed to the teeth #1:
Code style
• Pre-commit hooks: ocstyle, SwiftFormat, SpaceCommander (uses
Clang-Format) & more on GitHub.
• Some check in SwiftLint
17. Armed to the teeth #1:
Code style
AppCode
• Settings for
Objective-C, C, C+
+, Swift.
• Reformat action
• On-the-fly
• Format on commit
stage
18. Armed to the teeth #2:
Generate code
• Xcode pre-generates some methods when creating files/classes.
• Xcode code snippets for Objective-C and Swift.
• Override/Implement code generation on completion in Xcode.
• There were some 3d-party tools like xobjc on GitHub.
19. Armed to the teeth #2:
Generate code
AppCode:
• Generate menu
• Live Templates
• Create from usage
• Override/Implement
• File Templates
20. Armed to the teeth #3:
Static analysis
Tools:
• Guidelines/rules
• Configuration settings
• On-the-fly mode
• Quick fixes
21. Armed to the teeth #3:
Static analysis
Clang analyzer:
• Open source, part of Clang project
• Integrated into Xcode
• Basic checks, dead code, API checks, language specific checks
But don’t forget to switch them all on!
22. Armed to the teeth #3:
Static analysis
OCLint: https://github.com/oclint
• Metric-based defects:
• complicated code;
• redundant code;
• long methods, long parameters lists, etc.;
• bad practices (like parameter reassignment).
• 58 rules that can be customized per project
• Integrated with clang analyzer
• Can be used inside the Xcode
23. Armed to the teeth #3:
Static analysis
SwiftLint: https://github.com/realm/SwiftLint
• Similar to OCLint
• Limited in number of rules, planned rules:
• Code style checks (spaces, newlines);
• let over var rule; struct over classes;
• Working with optionals (like not forcing unwrapping);
• Specify access control and more.
• Contribute!
24. Armed to the teeth #3:
Static analysis
OCLint and SwiftLint
25. Armed to the teeth #3:
Static analysis
OCLint and SwiftLint
26. Armed to the teeth #3:
Static analysis
AppCode
• Integrated with clang
analyzer
• 60 inspections for
Objective-C, 40 for C/
C++, on-the-fly mode
• Settings, severity level,
profiles
27. Armed to the teeth #3:
Static analysis
AppCode: complicated cases, bulk mode
28. Armed to the teeth #3:
Static analysis
AppCode: quick fixes, DFA
29. Armed to the teeth #3:
Static analysis
AppCode:
Checks on commit
stage
• formatter
• code analysis
• TODO
• imports
30. Armed to the teeth #4:
Refactoring
• Xcode refactorings
• Rename, Extract (method/function), Move up/down, Create superclass, Encapsulate,
Convert…
• C and Objective-C only
• AppCode refactorings
• + Inline, Safe delete, Change signature, Extract everything, Rename with non-code
usages (strings, comment, xib, etc.) for Objective-C, C, C++
• Rename in Swift
• Some projects on GitHub, like Refactorial
31. Armed to the teeth #5:
Unit testing
• XCTest
• Kiwi: BDD framework for Objective-C
• Google Test: tests for C/C++
• Specta/Expecta: TDD / BDD framework for Objective-C
• Quick/Nimble: Swift BDD framework
32. Armed to the teeth #5:
Unit testing
AppCode: unit tests code generation
33. Summary
TODO:
• Follow selected code style
• Generate standard pieces of code
• Use the swiss-army knife thoughtfully
to find smells
• Refactor to clean up the smells
• Cover every inch with the unit tests
Tools:
• Xcode
• Clang-Format
• OC/Swift-Lint
• AppCode