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

1h 0m 5s logged

I’m Smart but I’m Bad at Taking Tests

Hello again! You know what they say, new commit, new devlog!

“[Test] Torsion”

We got MORE UNIT TESTS!!! The get_filenames() fn was formerly the only function in helpers.rs that had no unit tests, so I added 6 unit tests for it. They have about the same general structure as the unit tests for change_leading_zeros().

Beautification

I was trying to make my code prettier, and I accidentally screwed up an ownership issue. My unit tests made use of tempdirs with the tempfile crate to test change_leading_zeros() and get_filenames.

This is the original pattern for getting the temp dir’s path:

let binding = tempdir().unwrap();
let dir = binding.path();
// stuff can be done with dir now

This is what I changed it to:

let dir = tempdir().unwrap().path().to_owned();

When the tempdir gets dropped, it also deletes the directory, which makes dir a path to a dir that doesn’t exist. Everything compiles fine, but the code panics because the tempdir doesn’t exist.

Override

Something I forgot to mention in my last devlog is that if there was the files file1.txt and file01.txt, it (c/w)ould rename over one of the files and silently delete the file written over. I still have to fix this issue.

I’ve wanted to learn Zig, so I looked up Zig crash courses on Youtube, and this is from the one I was watching.

0
181

Comments 5

@Lxsh-S

I’ve also started learning zig!
May I know your reasons I think you already use rust right?

@max_silly

@Lxsh-S That’s awesome! My main language used to be Python until the start of this year. My friend is a hardcore Rust dev and they introduced me to the language. I had experience in languages like C#, C++ (for microcontroller boards), and C, yet somehow not enough to have written a malloc(). The moment I started using Rust, I fell in love with the language. My dad recently gave me a crash course in memory management in C, which wasn’t nearly as bad as I thought it would be (I thought I would have to manually find my own memory on the heap). I only recently (like in the last week) heard about Zig from The PrimeTime Bun rewrite video, but I didn’t really think about it until I watched this video, and he mentioned he thought of it as doing a better job at being a modern version of C/C++ than Rust. I decided it might be interesting to have another language under my belt, so I decided to start learning!

@Lxsh-S

Cool! @vidur_thammineni, thanks for this detailed answer I asked it because I also want to get into low level stuff so thought to learn C first, but got amazed by zig and rust :)

@max_silly

@Lxsh-S You should 1000% try C before Zig and Rust, in my opinion. Once you move to Zig and/or Rust, you’ll gain an appreciation for all the useful things they have because C doesn’t have those things. Just the basics of C is enough, I think. Use-after-frees and dangling pointers will make you appreciate the finer things.

@Lxsh-S

Alrightt thankss!!!!!
Will follow