An advantage over Erlang and Elixir is that this looks like any language from the C/Java family including all the clutter as in<p><pre><code> import std.fs.file.ReadOnlyFile
import std.stdio.STDOUT
class async Main {
fn async main {
</code></pre>
We basically have a zero signal to noise ratio here but it's a declarative pattern common to many successful languages so it will make many people feel at home. I think it's a good design decision.<p>On the other side I feel like the naming decisions in the error handling section are weird. The expect method breaks my expectations:<p><pre><code> let file = ReadOnlyFile
.new('README.md')
.expect("the file doesn't exist")
file
.read_all(bytes)
.expect('failed to read the file')
</code></pre>
Well, no: I expect the file to exist and to be able to read from it.<p>An expect method is common in test libraries and it behaves like an assertion. When I see an expect method I expect it to have a condition and stop the program if it evaluates to false, or propagate the error in any way appropriate to the language. So I expected<p><pre><code> let file = ReadOnlyFile
.new('README.md')
.fail("no_ro", "the file exists but it is not read only")
.expect("created")
.expect("open")
</code></pre>
I intentionally changed the probable behavior of the class, that seems not to create a read only file but only to open it. I made it create the file to show a softer version of expect() than an assertion. At least one of them must be true. The implementation of how to chain those methods without failing at the first failed expect() is a detail.<p>And about .unwrap_or(0), what that even means? The linked post [1] hints about a<p><pre><code> "wrapper type,” like Maybe<T>
</code></pre>
so it's an established naming convention in some language but if it works as I think, what about this?<p><pre><code> .default(0)
</code></pre>
That because unwrap_or seems to ignore errors and return a default. If it doesn't, it confirms that it's a bad name.<p>[1] <a href="https://joeduffyblog.com/2016/02/07/the-error-model/" rel="nofollow noreferrer">https://joeduffyblog.com/2016/02/07/the-error-model/</a>