You are browsing as a guest. Sign up (or log in) to start making projects!

1h 43m logged

Breaking it up

Divide and Conquer

When I was setting up my build.rs to use clap_mangen, I had to separate my CLI arg parser construct from the rest of my code and put it in a new file. I also realised that some of my code in my (basically) main function (change_leading_zeros()) was repetitive and could be extracted into functions.
My change_leading_zeros() was extremely long and deserved its own file. Even after moving a ton of code into helpers.rs, it’s still 78 lines long, thoroughly violating Uncle Bob’s standards. (Granted, his standards are bad, and Uncle Bob could go trip on a log for all I care)
I have never worked in a multi-file project before, not even for my Pong game, which is just 747 lines of code all in one file, and it could have easily been broken up into more files. I have a really fast scrolling speed on my laptop, to the point of it being almost unusable, so scrolling all the code in that project was annoying. Because I have never made a multi-file Rust project before, I had no idea what I was doing. I ran into a ton of errors, including my LSP stopping working, so I didn’t have autocomplete or clippy linting for one of my files for a bit, so I got even more confused. Now, fortunately, everything works now, and I even found some issues in my code (an if condition with an OR in which the first part of the OR was redundant; a for loop that instead could have been an iterator chain; a variable that stayed mutable after mutability was unnecessary), so it was an overall great success!

Illiteracymaxxing

Previously, I mentioned that the LZU operates off of a target length for file names, so having a schema like file01.txt project02.rs problem03.py wouldn’t work, but I was dead wrong. I haven’t worked on the project in a month and a half, and when reading over my code to see what it does, I mistook target as the target filename length, not the target length of the numeric portion. I thus removed the warnings associated with what I believed to be a behaviour of the LZU from the short help, long help, and README. The lesson is maybe to double-check with a friend or smth when you get confused by your own code.

0
20

Comments 0

No comments yet. Be the first!