DEV Community

Maxi Contieri
Maxi Contieri

Posted on • Updated on • Originally published at maximilianocontieri.com

Code Smell 29 - Settings/Configs

Changing system behavior in a control board is the customer's dream. And the software engineer's nightmare.

Problems

  • Duplicated Code

  • If Pollution

  • Global usage

  • Coupling

  • Testability and explosion of testing scenarios.

  • Complexity

Solutions

  1. Avoid Settings

  2. Create polymorphic objects. Inject them externally.

Sample Code

Wrong

Right

Detection

This is an architectural pattern so it should be controlled/avoided by design policies.

Examples

Exceptions

  • Sometimes we use Feature togging as a safeguard mechanism. This is acceptable in a legacy system. These toggles should be very short-lived in a CI/CD system.

  • Hyper parameter settings should be managed by configuration objects. You can read these objects from any persistence media and change your system behavior in runtime in an explicit and controlled way.

Tags

  • Globals

Conclusion

Setting runtime behavior is great for software systems.

We should configure our objects, so they can behave in different ways, and we should achieve it in an explicit way with explicit behavioral objects.

In this way, our code will be more declarative, clean and testable. It is not as easy as adding an IF Statement. This kind of lazy developers bring lots of coupling and unexpected issues on our systems.

A system with 300 Boolean configurations has more test combinations (2 ^ 300), than the number of atoms in the universe (10 ^ 80).

Also known as

More Info


Simplicity is the soul of efficiency.

Austin Freeman

Top comments (4)

Collapse
 
alainvanhout profile image
Alain Van Hout

To me, this sounds great in theory, but unlikely in practice: the point of configuration is that you can affect application behaviour without requiring regular redeployments. What you suggest seems only to be workable as a proper replacement for configuration if you use something like OSGi, which is its own can of worms.

Collapse
 
mcsee profile image
Maxi Contieri

Hi Alain!

As with most code smells, they are not rigid rules. I point for possible abuses, but I agree there are many valid scenarios.

I think you should carefully choose your own scenarios and decide if they deserve a configuration object (not a setting) . This will not require a new deployment. I will clarify the article

Collapse
 
aloksdiptim profile image
alokz diptim!

I have a question on coupling

Collapse
 
mcsee profile image
Maxi Contieri

Please write it down here.

I ll do my best on answering it