5
kobenz
112d

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
  • 6
    My linter is configured to raise a finger at 60 lines and to pull out a shotgun at 200 lines.
  • 2
    Why shouldn’t long functions be in utils?
  • 0
    @Lensflare utils are normally small things like ms_to_human_time that does only one thing. Smth with many lines does more than one thing. Should be splitted in several functions what should be isolated by its own file since they're only getting used there. Maybe some of those functions could migrate to utils
  • 1
  • 3
    @electrineer the one that looks like an exclamation mark.
  • 1
    I have a library that I include for all projects. It is multiple files. I have made an application to merge it all to one (only self written source, no system libs) and that file is copied to /usr/include and to use my lib with many features I only have to:

    include <rlib.h>.

    The merging is important because everything is related to eachother. I have every related file specified in right order declared in _rlib.h that compiles to rlib.h. Double includes get deleted.

    Consider to do the same
  • 1
    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