Junior
What is soft-code?
sobes.tech AI
Answer from AI
Soft coding is an anti-pattern where the program logic is externalized into configurations (files, databases) instead of being explicitly implemented in the code. This is done to make the program's behavior more flexible without the need for recompilation.
Examples of soft coding:
- Storing business logic in configuration file parameters.
- Using external scripts or formulas for calculations instead of direct code.
- Moving branching conditions into configurable flags.
Advantages:
- Theoretically allows changing behavior without recompilation.
- Potentially simplifies setup for different environments.
Disadvantages:
- Debugging complexity: Logic is spread across different places, making it hard to trace execution.
- Reduced readability: It's not obvious how the program works just by looking at the code.
- Risk of errors: Changes in configuration can break the program without compile errors.
- Testing complexity: Requires testing combinations of code and configuration.
- Technical debt: Maintaining and developing such a system becomes more difficult.
- Reduced performance: May require dynamic interpretation or loading.
Instead of soft coding, it is preferable to use more predictable and testable approaches, such as:
- Explicit implementation of logic in code.
- Using design patterns for flexibility.
- Applying dependency injection to manage dependencies.
- Using external configurations only for simple parameters (server addresses, ports, etc.).