Tips for programming - kanuku/misc GitHub Wiki

First class functions
[Orthogonal](http://twitter.github.io/effectivescala/#Object oriented programming-Traits)
Sentinels and Unifying types.

Know when to Log'm and when to Fold'm

Throwing exceptions should be avoided when possible. Consider the next aspects for each Exception to help you decide when to to Log'm and when to throw'm. Consider

  • Most important is to decide what does this exception mean for your lib/application?
    • Does it mean that the exception mean that the application will not be able to work normal (100%)?
      • Yes = Throw'm, example here would be connection to a database.
    • Is this error applicable only for one single action?
      • Yes = Log'm, example would be an exception caused by user input.
    • Should the user/caller know that there was an error?
      • Yes = If there is no proper way of informing the user, then just throw'm.

When you doubt wether or not you should throw an exception, take the next steps into account:

  • Is the function where I am in returning a result?
  • YES: Then if you can't fulfil the function's expectation, you should either:
    • 1 - Change the return type to be optional, like in scala: Option[String]
    • 2 - Throw an exception
  • Is the function where am in not returning a result
  • A function that returns a result, should never allow

In order to make your code ready, you must: