Some of my best practices after 3 years as a developer
1 min readAug 21, 2018
Number 3
- A function or a variable must be named less than 3 words, best at only 1 word, for example: if component input only has on properties “onChangeInput”, the function name must be reduced to “change”
- In a Component, arrange 3 properties in a line in Component declared
Don’t repeat yourself (Don’t repeat third time and combine if possible)
- Don’t repeat logic code: repeated logic codes which appear more than twice should be written in utility file for later reuse
- Don’t repeat string: repeated strings which appear more than twice tends to be changed in the future should be written in a configuration file or constant file
- Don’t repeat metrics value: many metrics numbers which appear more than twice in the project, for example, the height of a View, the height of tab bar which is platform dependence (IOS and Android maybe difference) must be written in one file
- Don’t repeat Component: long Component, which repeats more than twice, should be written in common Component
- For variable which has the same type, for example, refUsername and refPassword, make an object name ref, which have 2 properties username and password
- For functions that have the same feature, for example processUsername and processPassword, combine to one function process and accept params type as a mark to use switch — case to process.
Before:
After: