Programming languages

Clean code( Udemy)

jac99 2023. 10. 13. 13:23

Naming

  • meaningful
  1. Variables, constants: nouns/short phrases with adj
  2. Functions/ methods ( command): verbs, short phrases with adj
  3. classes ( use classes to create things): nouns, short phrases with nouns
  • name casing:
  1. snake_case: is_valid, send_response (python)
  2. camelCase: isValid, sendResponse ( java, js)
  3. PascalCase: AdminRole, UserRepository ( python, js, java) — classes
  4. kebab-case: <side-drawer> , ( html) —-custom HTML elements
  • value is an:
  1. object: describe the value ( user, database)
  2. number / string: describe ( name, age)
  3. 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