Introduction to Coding Guidelines
In this tutorial, i am going to explain what are the things want to take care when you start writing codes for iOS application development. These are the 15 golden rules must be followed when you write iOS Codes.
- Function names should be meaningful and according to iPhone/iOS standards
- No spelling mistakes should be there anywhere in the code. In comments, variable names and anywhere else.
- No unnecessary empty lines, no unnecessary commented code
- Logical comments everywhere in the code, above functions and classes
- No magic numbers (means no hardcoded numbers directly in code, define constants)
- No function should be more than 40 lines. Make sub-functions. Complete function should be visible in single screen without scrolling.
- Think where classes should be created. Make proper class design before coding. This is very important.
- Standard patterns for callbacks (proper names etc.)
- Use GIT for code versioning. Put mandatory comments when committing code (compulsory).
- Proper indentation of coding.
- No too many if-else or switch-case in the code. No too much copy-paste of same code (make proper functions that can be reused with parameters). These things can be avoided by proper class/object oriented design. Learn OO from Ram.
- Use logic that will use less code (ex: predicates instead of for-loops). Make code simple and not complicated.
- Proper error handling must be done. Functions should take error variable as parameter and should put error codes in it by the called function. The caller of the function should check this variable for any errors. If the web service is down, the app should not crash. It should show proper error message.
- When doing coding think about all the cases. The code should not work in one condition and fail in another condition.
- Do static and dynamic memory leaks testing. Object which is allocated must be freed at the right time and the right place. This should be planned properly.
you can read more about the iOS Coding standards from here
No comments:
Post a Comment