Programming languages
Clean code( Udemy)
jac99
2023. 10. 13. 13:23
Naming
- meaningful
- Variables, constants: nouns/short phrases with adj
- Functions/ methods ( command): verbs, short phrases with adj
- classes ( use classes to create things): nouns, short phrases with nouns
- name casing:
- snake_case: is_valid, send_response (python)
- camelCase: isValid, sendResponse ( java, js)
- PascalCase: AdminRole, UserRepository ( python, js, java) — classes
- kebab-case: <side-drawer> , ( html) —-custom HTML elements
- value is an:
- object: describe the value ( user, database)
- number / string: describe ( name, age)
- Boolean: answer the true/false ques( isActive, loggedIn)
Comment
Avoid comment!
Good comment:
- legal info
- warning
- Todo notes
- Documentation strings
Vertical formatting
- different concepts should be seperated by spacing
- similar concepts should not be seperated by spacing
- Related concepts should be closed to each other
Horizontal formatting
- Use indentation, avoid very long sentence
- Break long statements into multiple shorter ones
Function
- Minimize number of parameters!
- NO parameter function is good, avoid 3 parameters if possible, always avoid more than 3 parameters