- Set up your editor to run
rustfmt
whenever you save a file, or use cargo fmt
from the command line frequently.
- Fix every warning. Yes, every one! They’re there for a reason!
- Also run
cargo clippy
(maybe even before every build) and follow its suggestions. If you’re unsure if a lint makes sense or not, ask on Zulip!
- Read error messages! They’re usually actually good!
- If you see an error you don’t understand, try using
rustc --explain
with its error code. I have my editor set up so I can click the error code to get this information.
- If your program crashes with a panic, it will tell you the line it crashes on. If this isn’t enough information, do
RUST_BACKTRACE=1 cargo run
and get a full trace. If this doesn’t help and the panic isn’t in your code, put your own panic or assert in there with a println-style format string. If that doesn’t help, set up a debugger and have at it!
- If you have a hard to track down bug, try to find a way to exhibit it in a unit test. Then
cargo test
can quickly show the bug without you having to interact with the game, and even better it will tell you if you ever accidentally put the bug back!