174: Reducing Waste and Unnecessary Expenses in Your Organization
Code clarity to improve flexibility and reducing costs in teams and organizations
Thank you for reading Snippets of Text. Snippets from media about tech, programming, parenting, and more. This is a preview of a post available exclusively to paying subscribers. You can get unlimited access to all articles by purchasing a subscription.
Off Topic: Maintaining Code Clarity and Flexibility
To ensure a function is static, it should not have the potential to behave differently in different situations. It is generally better to have multiple functions instead of passing code into a function to determine its behavior. Nonstatic methods are typically preferred over static methods. When in doubt, make the function nonstatic. Switch statements are commonly used because they are straightforward but may be the best solution sometimes. Considering Polymorphism before switching statements is essential, mainly when new functions are more likely to be added than new types.
Base classes with abstract methods are typically better than switches/cases with named enumerations. When writing conditionals, it is easier to understand positives than negatives. Public classes should not be scoped inside another class if they are not utilities of that class.
The first rule of functions is that they should be small. Functions should not be large enough to hold nested structures. The second rule of functions is that they should be smaller than that. To ensure our functions are doing “one thing,” we must ensure that the statements within our function are all at the same level of abstraction.
The ideal number of arguments for a function is zero (niladic). Three arguments (triadic) should be avoided where possible. Next comes one (monadic), followed by two (dyadic). More than three (polyadic) require exceptional justification and shouldn’t be used. Even obvious dyadic functions like assert_equals(expected, actual) must be revised. How many times have you put the actual where the expected should be? The two arguments have no natural ordering. The expected, actual ordering is a convention that requires practice to learn.
In a clean system, we organize our classes to reduce change risk. It uses function and class declarations to add commentary to the code. Keeping functions small and keeping parameter lists short can sometimes lead to a proliferation of instance variables used by a subset of methods. This also means that our classes lose cohesion because they accumulate more and more instance variables that exist to allow a few functions to share them. When cohesion is high, it means that the methods and variables of the class are co-dependent and hang together as a logical whole. Short parameter lists and small functions lead to many instance variables used by some of the methods in a class. Having an accumulation of instance variables that are shared between a few methods. When this happens, it almost always means that at least one other class is trying to get out of the larger class. When classes lose cohesion, split them!
Separate the variables and methods into two or more classes to make the new classes more cohesive. Breaking large functions into smaller ones causes a proliferation of classes. If your function must change the state of something, have it change the shape of its owning object. Either your function should change the state of an object, or it should return some information about that object. Methods should either do something or answer something, but not both. Doing both often leads to confusion.
[^]: Clean Code: A Handbook of Agile Software Craftsmanship
Current Work: Reducing Waste and Unnecessary Expenses in Your Organization
Reducing unnecessary expenses and adding necessary functions like HR and legal can reduce waste. This includes minimizing expenses like office space and commuting costs. It's essential to avoid venture capital and not obscure individual contributions as the company grows.
Thanks for looking at the free preview of Snippets of Text. Please consider subscribing to the paid version if you find my work helpful. This way, I can spend more time developing new ideas to share with you.
Keep reading with a 7-day free trial
Subscribe to Snippets of Text to keep reading this post and get 7 days of free access to the full post archives.