Skip to content

Intro to Coding

raisercostin edited this page Oct 19, 2017 · 18 revisions

Rules to follow when writing code:

  1. Use principles as guide in unknown territory
  2. Simple classes
    • Should
      • be immutable
      • ideally : private final Type field; . If really needed public final Type field;
      • initialized once at construction time
    • Should Not
      • have getters/setters
  3. The absolute needed libraries are:
    • junit - testing api
    • slf4j - logging api - Intro to Logging
    • logback - simple logging implementation
    • guava - google utilities
  4. Careful on exception idioms
    • Never swallow an exception. If in doubt rethrow it.
    • principle~Fail Fast
    • A logged exception at info level is always a bug.
    • The exception should give enough details to be able to investigate the problem without debugging. If the investigation lasts more than 30s you have a bug on investigation of the exception.
    • see Checked Exceptions vs Unchecked Exceptions
  5. Do not use
    • static fields
    • null (use java.util.Optional) - Null Object
      • Do not have references to null objects.
      • If you could return null better to return Optional.empty()
  6. Try to use
    • final fields
  7. Beans, Getters and Setters are overhyped
  • Immutable classes (do not confuse with final fields)

Table of Contents

Clone this wiki locally