-
Notifications
You must be signed in to change notification settings - Fork 115
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
When to use type annotations for function parameters: best practice and what to do in Trixi? #44
Comments
In GitLab by @ranocha on May 11, 2020, 14:47 I'll try to answer your questions here.
Personally, I tend to like docstrings very much and would like to use more of them in Trixi. If I code and test something in the REPL, I usually try to get some answers from docstrings instead of asking Google at first. It also serves as additional documentation. For example, we could also add DOIs to docstrings of numerical fluxes etc. |
In GitLab by @sloede on May 20, 2020, 09:33 Summing up the conclusions of our discussion on Monday:
Please fix it directly here if I did not get it right. @ranocha I think we can close this issue now. If you think it is necessary to remove all existing unnecessary type annotations, I think we should create a new issue specifically for that. |
In GitLab by @ranocha on May 20, 2020, 09:49 Sounds good for me. |
In GitLab by @sloede on May 20, 2020, 09:53 closed |
In GitLab by @sloede on May 11, 2020, 14:28
@ranocha started a discussion in #42 about the (mis-)use of type annotations for function parameters, e.g. in src/solvers/dg.jl:
He suggested to remove type annotations that purely serve documentation purposes and are not required for multiple dispatch (in the example: all but
::Val{true}
), and to instead capture the documentation aspects in a docstring instead. To me, this seems like a very reasonable proposal. However, before changing anything in Trixi, it would help (at least me) to have these two questions answered first:As far as I understand, there are only two cases where you must use type annotations: If it is required for multiple dispatch, or if you use parametric types for which you need to access/use the actual type. In all other cases I can think of, type annotations are optional and, quoting the Julia manual:
I think most cases in Trixi belong to the second or third category (or a mixture thereof): We often use type annotations like the ones above to show a user/programmer what kind of function parameters are expected, and to immediately throw an error if a programmer violates this. For example, in DG code we often have methods like
flux
orcons2prim
that could very well work on the entire DG dataset (i.e., all elements, all nodes) or just on a single point.Thus, back to my questions: What are the best practices ("the Julian way") and how do we want handle this in Trixi? The biggest advantages of the current style (annotations-as-documentation) are IMHO that
The biggest advantages of using docstrings are IMHO
If we start to move towards using non-annotated function parameters together with docstrings, we would have to consider what our own guidelines would be, such that it is easy for students (and for ourselves) to decide when and how to put documentation in docstrings.
I have not yet made up my mind yet about the way we want to handle it in Trixi, but would be very interested in your ideas! Also, I'd by very interested in learning about the "true" Julian way - maybe @ranocha can shed some more light on this, since he is by far the most experienced Julia developer here ;-)
The text was updated successfully, but these errors were encountered: