Profile

User's avatar
npub179e9...lz4s
npub179e9...lz4s
My second week of Rust (only a few hours a day though: I am on vacation after all) has me reproducing and enhancing a tool I wrote in C. It takes multiple lines and runs stats on the numbers in it. This is useful for quick benchmarks: `for i in $(seq 10); do /usr/bin/time myprog; done | linestats`. Each line with the same literal parts is combined, with numbers replaced by "min-max(mean+/-stddev)". The C one wasn't very clever about decimals, so it needed a good rewrite. The new code works, but needs polish, more options, optimization, tests and documentation before I release it. The good thing about these small projects is they don't get hamstrung by Rust's glacial build times!
Since I'm taking a few weeks vacation, I've decided to seriously try to learn rust. My method in this case is to ask ChatGPT to guide me (but not write for me!) a library ("crate") that I've always wanted to write and never got around to. Of course, I get a lot of feedback on appropriate rust styling, but some of it veers into things I feel are deeper constraints. In this case, I had an open function, which took a struct containing some flags, such as "writeable", "create if didn't exist". It didn't like the fact that I asserted if you set create and didn't set writeable. Here is my response: --- Re: assert!(). I dislike APIs which allow misuse. Callers of a library should not rely on such checks in the library, in fact the concept of adding an InvalidOptions error type is offensive. A recoverable error is strictly a worse api than an unignorable error. But a compile time error is better. We should use an enum READONLY, WRITE_MUST_EXIST, WRITE_MAY_CREATE. --- Of course, it's a waste of time for me to lecture it on style, but I can't help myself!!
Damn, right before I closed my laptop for the afternoon I had uncovered a weird bug, which git bisect says is triggered by a trivial commit. But I really should record myself tracking it down, for my Intro to CLN Development series, so I am having to resist the urge to look at it tonight...