UI for new homogenization function: "confusion" between optional parameter and keyword parameter #2582
Replies: 5 comments
-
This comment is more "private" (i.e. relevant only to those interested in the function
seems to be easier to read/comprehend than the current form
where a reader unfamiliar with the signature would like wonder what the argument |
Beta Was this translation helpful? Give feedback.
-
I agree.
… Am 20.07.2023 um 14:31 schrieb JohnAAbbott ***@***.***>:
This comment is more "private" (i.e. relevant only to those interested in the function homogenization).
@wdecker <https://github.com/wdecker> What do you think of changing pos into a keyword parameter? I like the idea because a call to homogenization with a nameless integer argument is not easy to understand (unless one has the signature clearly in memory). Taking the example from above:
homogenization(J, W, h; pos=1)
seems to be easier to read/comprehend than the current form
homogenization(J, W, h, 1)
where a reader unfamiliar with the signature would like wonder what the argument 1 means in this context.
Yes, I know that my proposed change is not backwards compatible (and would entail rewriting some documentation). But I currently think that it brings genuine advantages: e.g. easier to read/comprehend, less risk of problems from an "almost invisible" typo.
—
Reply to this email directly, view it on GitHub <#2582 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AASSXESMKSTETLQ7NR4SJATXREQJ5ANCNFSM6AAAAAA2RKYGYE>.
You are receiving this because you were mentioned.
|
Beta Was this translation helpful? Give feedback.
-
I have just pushed revised code which (hopefully) implements this revised UI. A few tests on my machine suggested all is OK. |
Beta Was this translation helpful? Give feedback.
-
Do we have guidance for writing documentation for functions with optional keyword arguments?
If we expand out each possible case we obtain this rather long version:
Or we could employ a verbal description, perhaps something like the following
In fact the normal argument
Which approach is easiest to comprehend? Or should we just use the first option (i.e. julia syntax), and then give 8 examples to show the different variations? |
Beta Was this translation helpful? Give feedback.
-
Since one revision to the user interface to
If the parameter is an optional kwarg then specifying the name would require writing something like this:
The kwarg name Bear in mind that if we wish to specify both name and position then we must write something like:
This is starting to become rather "verbose"... |
Beta Was this translation helpful? Give feedback.
-
I have just spent some time tracking down a "weird, syntactic bug": I made a minor "almost invisible" typo, and obtained unexpected results. My question will be: should we change the UI so that others cannot make the same mistake?
These two methods correspond to the last parameter
pos
being optional (otherwise the signatures are the same). The bug was triggered by an incorrect call, namely:The crucial point is that I typed a comma instead of a semicolon (just after
h
). This call was accepted by Julia (without warnings), but it matched the second signature: the boolean value ofextra_gens_flag
was automatically coerced into anInt
. With a semicolon instead of a comma the call matches the first signature (and does what I'd expected/intended).Yes, there are several could have and should have (but I didn't). My main point is that it would be easy for another person to make the same mistake... and I can assure you it was not easy to spot the typo!
So, how could I revise the UI (i.e. the signatures) so that this minor typo cannot cause future headaches?
My suggestion would be to change
pos
into a keyword parameter; this means that calls tohomogenization
where the value ofpos
is to be specified would look like the first two in the following:My description here is (obviously) in the context of the
homogenization
function, but the message is intended to be general.Beta Was this translation helpful? Give feedback.
All reactions