Skip to content
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

More notes on EAFP #2

Merged
merged 1 commit into from
Jan 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ Try.jl exposes a limited set of "verbs" based on Julia `Base` such as
an error value `Err{NotImplementedError}`. This let us use these functions in
the ["Easier to ask for forgiveness than permission"
(EAFP)](https://docs.python.org/3/glossary.html#term-EAFP) manner because they
can be called without getting the run-time `MethodError` exception. Such
functions can be defined using `Try.@function f` instead of `function f end`.
They are defined as instances of `Tryable <: Function` and not as a direct
instance of `Function`.
can be called without getting the run-time `MethodError` exception.
Importantly, *the EAFP approach does not have the problem of the trait-based
feature detection* where the implementer must ensure that declared trait (e.g.,
`HasLength`) is compatible with the actual definition (e.g., `length`). With
the EAFP approach, the feature is enabled simply by defining the method
providing the function (e.g., `Try.length`). (Implementation details: In
Try.jl, such "EAFP-compatible" functions are declared using `Try.@function f`
instead of `function f end`. They are defined as instances of `Tryable <:
Function` and not as a direct instance of `Function`.)