Back
Question
Asked

If you had to make a complex piece of logic configurable. Think logic as data. What would you do and why?

I'm thinking of two options. Either using an eval(), or implementing a DSL. Neither of them makes me really wanna.

What would you do? Got any better suggestions?


I would consider another pattern, Swizec. There is one, which is actively used by D3.js. Basically you create an object and then each instance method returns that object back. This way you can create a neat chain of settings without any ugly config objects or time consuming DSL. Example: instance = new Instance(); instance.setMemory(300).setStorage(1000).setMemoryAlertThreshold(0.8).start(). There is no context of what you work on, but hope it helps.