Resource management

⦿ docs

Exceptions and resource management are important aspects for creating robust systems, because in production unexpected problems can happen and because not immediately released resources can halt a system due to excessive leaking. It is not unusual having a 30% or more of production code devoted to managing these aspects.

Initially I designed exception handling and resource management in the traditional way, with try { .. } catch { .. } finally { .. } code bloks. But then I figured out that resource management is often boiler-plate code, and exception handling code is not very structured because only already open resources can be released, and the repair depends from the point of interruption. So Dok supports resource management (particular in presence of exceptions) favouring metaprogramming compiler rules injecting a default behaviour in code written without explicit resource management.

Exceptions are managed:

  • case A) fixing the problem and re-running the same code, in the Eiffel way
  • case B) signaling the problem to the parent caller, in a traditional way, but inspired also by Erlang approaches