code quality
DESCRIPTION
Highlights how to write quality code and what are some major pitfalls which we do on daily basis. Presented by me to the Mobile team at Systems Ltd on 10 October 2014.TRANSCRIPT
Code Quality (Generic)Hussain Mansoor Systems Ltd.
Light ViewControllers/Activities
Remove database fetching methods (or insertions)
It should be via DB Layer
Remove Network requestsIt should be via Network Layer
JSON/XML Parsing is also not a part of Controllers/Activity
Move Common code into BaseClass
Weak References
Have weak references of Context/Activity/View whenever possible
By default all references are ‘STRONG’
If weak reference is Null don’t continue
WeakReference r = new WeakReference(Obj);
__block __weak
Overriding useful methods
toString() / [object description]
Comparator methods
Values in codeAll the numbers and strings should be part of constants file
In perfect scenario code will not have any number or string, all will be referenced via constants
Use dimen files
Move static data into xml/plist files
Code improvementsUse ‘lint’ tool in Android
Use Analyze feature of Xcode
Profile for Memory
Profile for Processing
DebuggingUse Android provided Log class method with sense
Every log can’t be Log.d() or Log.e()
Use Xcode Colors
Understanding debugging with threads
Disable logs for release mode