Skip to content

Unreasonably long files and functions #8596

@inner-daemons

Description

@inner-daemons

Particularly in naga, it seems common to have files that are ridiculously long, like >5000 lines. I was just reading through naga/src/front/spv/mod.rs which is 7000 lines. In particular the Frontend::next_block function is a whopping 3000 lines (!!!). This is especially notable because in my experience, mod.rs isn't usually even meant to be used for large chunks of code, more as a module registry and where some types live (feel free to comment on this if you disagree).

Other offenders in naga:

  • back/msl/writer.rs - 7500 lines
  • back/glsl/mod.rs - 5000 lines
  • back/hlsl/writer.rs - 4600 lines

This makes it very hard to read these files, and slows down IDEs even for simple tasks like coloring. Developers with slower computers will have a miserable time contributing. Additionally, long functions are worse, almost always being very difficult to read and understand.

I propose splitting these files and functions up, in addition to perhaps instating some new rules, each arbitrary and up for debate:

  • No function can be longer than 1000 lines
  • No file can be longer than 4000 lines

The second one at the very least could probably be done through simple CI checks.

I would also like to shout-out wgpu-hal here: despite being quite a large codebase, each backend module is very well split up between several files, in fact no files are more than 3000 lines long. Wgpu-core also only has 2 files that are more than 3000 lines long, the larger of which being ~4500 lines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: infrastructureTesting, building, coordinating issueshelp requiredWe need community help to make this happen.type: enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions