4 ms·
It's very strange for main to return something, the logic should be wrapped in a different function and the error checking done from main.
by Thaxll 4y ago
It's very strange for main to return something, the logic should be wrapped in a different function and the error checking done from main.
- lillecarl 4y agoIf your program can fail, main should return an integer. This way everything you might use to invoke your code knows if it failed or works. Not strange at all!
- IceWreck 4y agoInstead of returning an exit code manually or finishing with 0 when you should not you can return an anyhow error instead.
- estebank 4y agoUsing `fn main() -> Result<(), Box<dyn Error>>` isn't necessarily unstylistic, the ability is there for a reason, but it is not great for CLI tools: it prints the `Debug` output of the error, which in many occasions is great for a developer to figure out what went wrong, but from subpar to terrible for end-users. The main benefit of having main return a `Result` is being able to write `?` and be done with it. A tool meant to be used by others like ripgrep? You better use a more explicit mechanism to ensure good output for wording, context and formatting.
- avgcorrection 4y agoPrograms conventionally return an exit code or whatever it’s called.