DEV Community

loading...

Discussion on: When DRY Doesn't Work, Go WET

Collapse
functional_js profile image
Functional Javascript • Edited

Nice write-up Nick.

Some more tips:

  • WEF (write everything four times) is fine advice
  • Don't rush to refactor (it's a good architectural stategy to defer as late as possible)
  • Unrefactoring is as important as refactoring
  • Keep your functions orthogonal, like a pipeline
  • Keep your functions monomorphic (take only one type, and return only one type)
  • The ideal function is a one-liner that takes one strongly-typed arg and returns one strongly-typed value
  • Keep your code as flat as possible but no flatter
  • Remove cyclomatic complexity (branching count)
  • Use "if statements" for simple validation and state checks, not for comprehensive use-case branching

Terms:

cyclomatic complexity:

a measure for the complexity of code
related to the number of ways there are to traverse a piece of code
this determines the minimum number of inputs you need to test all ways to execute the program

Forem Open with the Forem app