-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add manual section on method design and more advanced ambiguity resolution #18111
Conversation
Thanks. What's your opinion on including some of the following points or thoughts.
Ref 17794 This statement only apply to types if my understanding is correct? In other words, there is no difference between the following two functions |
doc/manual/methods.rst
Outdated
|
||
- avoid defining either of these methods: instead, rely on a generic method ``-{T}(A::AbstractArray{T}, b)`` and make sure this method is implemented with generic calls (like ``similar`` and ``-``) that do the right thing for each container type and element type *separately*. | ||
|
||
- if at least one of these must be defined, prioritize dispatch on the container |
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 don't understand what you mean by this point.
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.
That is to say, where possible don't dispatch on T
, but it's OK (often necessary) to dispatch on MyArray
.
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.
Note quite clear to me what you mean, maybe add example?
@musm, that's right. The limitation regarding types ( |
doc/manual/methods.rst
Outdated
|
||
This is often the right strategy; however, there are circumstances | ||
where following this advice blindly can be counterproductive. In | ||
particular, the more methods you have, the more possibilities there |
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.
Just to be on the save side, I'd write "...,the more methods a generic function has,..."
Good addition, thanks for writing down your insights. |
The material in this pull request is insightful. Any hope of reviving it? Thanks! |
6cc9ad0
to
06a528c
Compare
Comments addressed and rebased. |
the manual isn't in rst any more, bad rebase adding that file |
Indeed. See #20702. |
myfilter(A, kernel) = myfilter(A, kernel, Replicate()) # default boundary conditions | ||
|
||
function myfilter(A, kernel, ::Replicate) | ||
Apadded = pad(A, kernel) |
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.
would it make more sense for this to be the same padding function replicate_edges(A, size(kernel))
as above?
I think many people struggle with how to resolve ambiguities, and this really gets into how one should design Method hierarchies in Julia. For some time I've thought we could use a bit more documentation on this topic; here's an attempt to start that conversation.
There are many caveats to this:
In other words, it's just about perfect for generating discussion on the topic 😉.