luni, 25 ianuarie 2016

Programming: Writing methods -- Best Practices

Writing methods -- best practices:

  • Use meaningful names for methods and their arguments
  • Try to keep the number of arguments as low as possible (to be less than 6)
  • Methods should be short (adhere to single responsibility principle)
  • Document public methods
  • Perform argument validation
  • Try to avoid returning null 
  • Use visibility and accessibility rules 
  • Java: Use annotation to mark "special" methods (@SafeVarargs or @Override)