Coding principles: Demeter, DRY, and Mutation rules
masterAdhere to these core software engineering principles:
- Law of Demeter: Use only one dot notation when accessing objects or services (e.g.,
someObject.someProperty). Avoid deep chaining likea.b.c.d. - DRY (Don't Repeat Yourself): Do not duplicate text, expressions, or logic. Move repeated code into constants, Enums, Classes, or functions.
- Mutation Rules:
- Components: Avoid mutations inside components to prevent issues with
OnPushchange detection. - Nested Functions: Do not change references to object properties from within nested functions. Instead, initialize the object where it belongs and use return values to update it.
- Components: Avoid mutations inside components to prevent issues with
- Control Flow: Prefer
if (condition) return;(early return) overif (condition) { ... } else { ... }.