//TODO: Add reference example
regardless of the layer we’re talking about
// TODO: explain
TODO: reformulate
- Scopes should have as few symbols as possible (especially package scope)
- Declarations should have the narrowest possible scope it could have
Control-flow becomes more observable/understandable if it forms
a directed graph with only one vertex which has no incoming (and only outgoing) edges.
This vertex is entry point
, the main()
function.
Data-flow can also be considered as a graph. Every stateful object there is a vertex. Fewer vertices, fewer and shorter edges => more observable/understandable teh data-flow is.
In practice all the state should be packed into the package-level entities (structs). With this approach we also understand the ownership better (i.e.: this entity owns this logger instance, etc...).
As these functions calls POSIX's exit()
internally.
Which, in turn, makes any kind of deinitialization impossible.
In rare cases, if the error is non-critical, then it should be at least reliably reported.
so we can use type switch to implement different recovery scenarios
Most of the logic should be encapsulated into a subordinate entities.
// TODO: explain
// TODO: explain
// TODO: explain
// TODO
All service-wide entities should be instantiated in the entry point and passed through the call stack
i.e.: logger, data access layer instance, etc
Later this object should be passed through the call stack accompanying the control flow.
This object should be nested and passed to every HTTP/gRPC/etc handler call using specific middlewares or http.Server.BaseContext
callback in case of HTTP server.
When the signal is caught, it should cancel the global context to initiate graceful shutdown
The graceful shutdown should be implemented by every internal process.
During the graceful shutdown entry point should wait for them to finish (with timeout).
Graceful shutdown process should have a reasonable timeout, to not last forever.
// TODO: explain
If there is the only entity in a package, then the constructor function should be named New
If there are multiple entities in a package, then constructor functions should be named New%EntityName%
i.e.: DAO should not be used as a DTO
// TODO: explain
// TODO: explain
to be easily readable/understandable
BDD-style tests fits better when it comes to testing stateful APIs (i.e. networked APIs), because it has the state (i.e. user's session in networked APIs) and standardized working routines (or scenarios). BDD tests also provides structured usage examples of your APIs.
// TODO
Code comments should be applied only when necessary. Redundant == wrong.
You don't need comments you have exhaustive naming and clean architecture. (IRL it is rather not 100% achievable)
- DDL -
- BDD -
- DAL - Data Access Layer
- DAO - Data Access Object
- DTO - Data Transfer Object