-
Notifications
You must be signed in to change notification settings - Fork 3
Best practices
These best practices are related to CFlow only. Since CFlow is in essence a routing engine, these practices will mostly concern configuration. This page assumes you know all about that.
- Only use conventions for small applications that are easy to oversee. In the majority of cases, use configuration. It also allows other developers to gain insight in the flow quickly.
- Define one target per configuration file, and give that file the name of the target.
- Don't create deep directory structures for your configuration. As a rule, go no deeper than one level below your main configuration directory. If possible, put all configuration files in one directory.
There are many analogies between building your configuration and actual coding. One thing is that, like code, configurations can smell. More concrete, some analogies can be seen with object oriented programming:
- objects - targets
- methods - events
- method calls - dispatching events
- instructions - tasks
The analogy is far from complete. For one thing, dispatched events do not return values. But the analogy is good enough to apply many of the rules and patterns that apply to object oriented programming.
Below are some guidelines to help you prevent poor configuration.
- Don't create deep task hierarchies. Although task nodes can contain children that contain children, it is usually better to organize the children in separate events.
- First create the (concept) configuration, then start coding. But of course, don't try to create an elaborate configuration beforehand. Be agile.
- Keep the number of tasks within an event small. Events with many tasks are more difficult to understand, and probably not reusable. Chances are you're going to have to duplicate configuration.
- Name your events based on what has happened, not on what its tasks are supposed to do. This sounds easy but is actually quite hard to keep up. This habit helps you to keep events concise and reusable, because it reduces coupling between events (not coupling in code, but 'mental coupling').
Think about targets and events like they're objects and methods respectively, and try to apply object oriented patterns. There are many analogies.
Just like with coding, it's good to avoid duplication.