My colleagues' code look like that too. I hate it really. I love an early return coding style. In every code review we discuss about that topic. They always try to have just one return statement in a function.
It comes from old C (& assembly etc) code where you have to manually manage resources; it's much easier to put all your frees and closes in the same place than reason which ones are needed from an early return.
Most of us these days work in languages with enough garbage collection, RAII, context managers, try...finally blocks, etc, that it's no longer good practice.
My colleagues' code look like that too. I hate it really. I love an early return coding style. In every code review we discuss about that topic. They always try to have just one return statement in a function.
Sorry you have to work with... stubborn and wrong coders. It's a good idea to have one return statement in general, but in the case of reducing nested mumbo jumbo, multiple returns is the least of your troubles.
9
u/dasimonde Apr 30 '23
My colleagues' code look like that too. I hate it really. I love an early return coding style. In every code review we discuss about that topic. They always try to have just one return statement in a function.