← Back to context

Comment by Too

2 years ago

Surprised to see the line count go up so much, 56K LOC of C++ to 75K of Rust. The blog attributes it to rustfmt using less oneliners. Even so, i would believe that should be a small factor compared to the heaps of duplicate code you get from c++ header files and all the other syntax ergonomics rust gives you.

Is this typical for such a translation. They also mention addition of new features contributing to more code, how much of the addition was new features vs pure translation?

Would be interesting to see the line count of the c++ version if it was run through a formater with similar configuration.

Rust is denser than C, but both Rust and C++ can work on similarly high level of abstraction.

It may be just down to rustfmt. It really adds a lot of vertical sprawl. I personally can't stand how much rustfmt makes multi-line code explode.

  • Default to 80 chars is a travesty IMO, 100 or 128 would be a much better place.

    • rustfmt uses 100-char lines by default (and can be configured to fill more), but that's not the problem with it.

      The problem is that as soon as a whole statement doesn't fully fit on a single line, rustfmt switches from "horizontal" to "vertical" strategy. It then stops caring how much vertical space it takes, inserts line breaks as often as the style allows, and won't try to use the available line width.

      You end up with long runs of finely chopped lines that contain only a single variable or a single call (often with each argument on a separate line too), which looks like having a 20-char line length limit.

      It's either fully oneliner `foo().bar().baz()` or fully vertical

          foo()
          .bar()
          .baz();
      
      

      and you can't have anything in between. It will fight you if you put two calls on the same line.

      3 replies →