4
kobenz
1y

An utility function longer than 100 lines shouldn't even be a single function. Shit, it shouldn't even BE inside the "utils" file

Comments
  • 5
    My linter is configured to raise a finger at 60 lines and to pull out a shotgun at 200 lines.
  • 1
    Why shouldn’t long functions be in utils?
  • 1
  • 3
    @electrineer the one that looks like an exclamation mark.
  • 0
    If one of my functions is over 10 lines I get really antsy.

    Sometimes it can't be helped without massively overcomplicating it, but its very very rare that a function of mine is over 10. They're usually around 5.

    If any bigger than 10, it usually indicates that the function is responsible for too much and therefore you can't skim it -> its easier to fuck it up.

    Essentially long functions break KISS, IMO
  • 1
    @MammaNeedHummus mostly true but there are a few exceptions:
    * Mapping functions which map/transform some data or states.
    * functions which build up ui structure. You can extract most stuff into smaller functions but it often makes readability worse because you need to jump to different places to understand a single piece.
  • 1
    @Lensflare "there's an exception to every rule; even this one"
Add Comment