I’ve recently started using Rust and was hoping I could get some feedback on my code. I’m sure much of it isn’t idiomatic Rust and certain things could be cleaner. The whole project is just under 1000 lines of code, but I’d like to point out a few things that I’m unsure of.
I’ve written a BASIC interpreter (github repo here) in Rust.
A few of the pain points I’d like guidance on:
I’ve defaulted to using
Stringin most places, I don’t really have an intuition when to use
src/evaluator.rs(see the source) I have a lot of copy and pasted code that was modified slightly for each case. The combination of handling the types in BASIC and Rust’s types made this ugly. In my Python version of this code, I just had something that returned a lambda for the operation and with Python’s “Duck Typing” it just handled it. I would have liked to have a trait that was implemented for each operator that handled this, but I wasn’t sure how to handle the different argument types.
In general, the right-ward march of my code. I like that Rust’s type system makes me deal with errors with
Optiontraits. But this tends to make my code be deeply nested and it makes me feel like there is something I’m not getting.
My use of
clone()feels a little bit too much. I admit I tended to use it in places to please the borrow checker, but maybe there are more fundamental patterns that I’m missing out on so that it isn’t always the most appropriate thing to do.
I know I’m asking a lot, so I appreciate it if anyone can offer any amount of time to help me out. I’ve enjoyed my experience with Rust so far and I’d like to spend some more time with it.