DEV Community

Discussion on: Keeping your code clean by sweeping out "if" statements

alwynschoeman profile image
Alwyn Schoeman

The problem is that people do not work with significantly large and/or complex programs with multiple developers.

The examples here are simple value mappings, but what happens when those if blocks perform logic? Different types of logic blatantly ignoring the single responsibility principle. The more complicated they get the bigger the chance that there are unmatched use cases.

But that's a code smell? Yes, but if statements are like candy to children who just want to plug some code in somewhere to finish a ticket. Code they don't understand and that gets more complicated with each if statement.

Apart from functional declarative solutions there is also the proper use of OOP which is really what design patterns are all about.

All of these require reasoning about code, which apparently is too much too ask.

Thread Thread
binarydelight profile image
Binary Delight

Agreed. This is going to sound snobbish. Anyone can code; but not everyone can apply coding principles.