snafu icon indicating copy to clipboard operation
snafu copied to clipboard

Comparison to anyhow

Open dhouck opened this issue 1 year ago • 3 comments

Like with #321, the Comparison page seems incomplete without a comparison between SNAFU and Anyhow. As far as I can tell the Whatever type in SNAFU is very similar to an Anyhow error, but I donʼt know enough about the details of either one to write a good comparison myself.

dhouck avatar Jul 15 '24 05:07 dhouck

I wrote a piece about migrating a software project to SNAFU some years ago. Some of the parts are outdated, but the concept of anyhow relying on a dynamic error type still holds.

anyhow and eyre are mostly designed for applications, as they facilitate the aggregation of multiple error types into a single source of information about the error. This error can be expanded across the program stack via the extended context operator, hence gaining additional information. They deliberately employ a "kitchen-sink" error type, which is more complicated to take part in code flow if necessary. When it comes to libraries, structured error types are usually preferred.

Enet4 avatar Jul 21 '24 11:07 Enet4

I definitely prefer structure types in a lot of cases, but since snafu has Whatever also, it seems worth doing direct comparisons with that.

dhouck avatar Jul 22 '24 20:07 dhouck

I looked into Whatever. Seems it is fat pointer on stack. While seems Anyhow is hack to have smaller pointer on stack. So anyhow optimizes for usually OK flows better. Anyhow has use of manageable panic like this https://github.com/thrumdev/nomt/issues/609

dzmitry-lahoda avatar Dec 30 '24 19:12 dzmitry-lahoda