Skip to content

Instantly share code, notes, and snippets.

@franzwong
Last active April 11, 2018 00:52
Show Gist options
  • Save franzwong/cd96799c4a5b3d3f906119ce0c331edf to your computer and use it in GitHub Desktop.
Save franzwong/cd96799c4a5b3d3f906119ce0c331edf to your computer and use it in GitHub Desktop.
Coding guideline

Coding guideline

Coding recommendation

  • Composition over inheritance
  • Extract code to separate method instead of putting code comment
  • Return early
  • Don't ignore exception
  • Avoid singleton pattern

Java

  • Provide private constructor only for utility classes
  • Prefer non-static instead of static method for non-utility method
  • Reuse ObjectMapper
  • Prefer ObjectReader / ObjectWriter to ObjectMappaer
  • Use StringBuilder instead of StringBuffer if no thread synchronization is needed
  • Override Array / StringBuilder / StringBuffer's default capacity if the expected size is known
  • Use constant.equals(variable) instead of variable.equals(constant) to prevent null checking
  • Use Boolean.TRUE.equals(variable) instead of (variable != null && variable)
  • Use switch on string instead of if-else-if-else block

Javascript

  • Use === / !== instead of == / !=

Logging

  • Write log with correlation ID

Project structure

  • Group files by features

Configuration management

  • Provide a common configuration and override configuration instead of duplicating the whole set of configuration

Testing

  • Use Theories or Parameterized for multiple data tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment