CodeNewbie Community 🌱

Discussion on: What clean means and why you should care

Collapse
 
michaelcurrin profile image
Michael Currin

Yes I agree that too much nesting is hard to test and reason about, rather refactor like split into functions.

Uncle Bob said to use 2 or at most 3 params for functions. It limits the number of combinations to test in unit tests, which grows exponentially for every param added. Also I like adding a structure as a param to keep things like. Pass an object of type Person which has 10 attributes, instead of 10 attributes. Where Person might be a class, or it could be a type of interface - typed languages like Go and adding types in Python and JS means you can pass a data structure to a function and be confident it has all the attributes set (while a plain dictionary without typechecking would be unreliable)