↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Action-Oriented C# - Kill All Defects

The post describes a point where code quality and flexibility stopped improving, even though the code already followed SOLID principles. The author then uses Action and Func to replace repeated patterns, especially where a condition controls whether custom logic runs and where the same change would otherwise need to be made in several places.

The main idea is that passing delegates makes methods more configurable. Action is presented as a method signature with no return value, while Func returns a value. Using a lambda expression in a Func call can shorten the calling code, and the author says this can improve maintainability and reduce defects from duplication, even if the syntax is a little harder to read.

Reading notes
#

  • The author reached a plateau where code quality and flexibility stopped improving.
  • The code was already pretty SOLID, but it still had many similar patterns that made maintenance harder.
  • A repeated routine checked a property, ran custom logic only when the property was true, and stored the result on the object.
  • The pattern resisted method extraction because some calculation methods could not run unless the related degree was present.
  • A bug or code change in that pattern could require updating the same logic in three places.
  • Copy / paste driven development is described as an anti-pattern and a source of bugs when changes are not applied everywhere.
  • Passing Action and Func types gives methods configurable behavior.
  • Action is described as a generic signature for invoking a method without a return type.
  • Func is described as similar to Action, except that it returns a value, with the last generic type argument as the return type.
  • A Func can be used to extract a method with configurable behavior.
  • Lambda expressions are used in the example and are compared to those used in LINQ queries.
  • The syntax is harder to read, but the maintainability benefits are presented as real.
  • The post frames this as a useful idea from functional programming that can also help in object-oriented programming.