Julia syntax: calling a function with kwargs #2615
Replies: 4 comments 3 replies
-
It is usually a good idea to separate the keyword arguments with a semicolon, since otherwise one might not always get what one wants:
|
Beta Was this translation helpful? Give feedback.
-
In light of the comment by @thofma it seems to be a really good idea to ensure that we use a semicolon before specifying kwargs, otherwise we will have code which "looks correct" but might not do what one reasonably expects (i.e. somewhat evil bugs). |
Beta Was this translation helpful? Give feedback.
-
In PR #2614 @lgoettgens points out that when using a semicolon, one can use short-cut assignments for kwargs (if kwarg-name and assigned value are written identically). This makes the source code shorter... not sure if it makes the code clearer though.. Advice???
could be more succinctly written as
[but then the kwargs do not stand out to the "casual reader"] |
Beta Was this translation helpful? Give feedback.
-
Since no-one has expressed a strong opinion either way, I'll go with what I prefer (in my code), namely |
Beta Was this translation helpful? Give feedback.
-
What is the syntax recommendation for calling a function with kwargs?
I was somewhat surprised to find the following example on the julialang website
Why is the call not
foo(;a=1, b=2, c=3)
? It seems that putting in the semicolon produces the same result as without.Is there a recommendation for which syntax to use in Oscar code?
[This question was triggered by line 585 in
mpoly-affine-algebras.jl
where a kwarg is specified without a preceding semicolon]Beta Was this translation helpful? Give feedback.
All reactions