-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: More detailed introduction for Option and Result #15
Conversation
skarllot
commented
Jun 29, 2024
- More detailed introduction for Option and Result
docs/core/option.md
Outdated
present. | ||
The `Option` type encapsulates an optional value in a way that explicitly represents either the presence | ||
(represented as `Some`) or absence (represented as `None`) of a value. It can be used to replace nullable types | ||
and to deal with errors or exceptional cases without resorting to drastic measures such as throwing exceptions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure about emphasizing error handling as a feature of Option, it’s really just a type-safe alternative to nullable types. Maybe describe how its simpler than for example dealing with potential nulls for reference types and default values for value types? Option lets you treat them the same, it doesn’t care whether its a reference or a value type.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think that the second sentence should be dropped?
Haskell documentation define Maybe as an error monad: https://hackage.haskell.org/package/base-4.20.0.1/docs/Data-Maybe.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, the text looks very close to the Haskell one, but Maybe
replaced with Option
. If we're going to quote the Haskell docs, we should do so with a quote block and a link.
However, I don't agree with the Haskell docs on the point of it being for error handling.
How about the following intro text:
The `Option` type is a powerful construct used to represent the presence or absence of a value.
This type is particularly useful for eliminating null reference errors, a common source of bugs in C# applications.
An `Option` can be either `Some` (containing a value), or `None` (indicating the absence of a value).
By using `Option`, developers can enforce safer code practices, making it explicit when a variable,
property, or parameter might not have a value and requires handling both cases.
I've made some changes to the documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last bit, then we're good 👍
Thanks again @skarllot ! 🙏 |