-
Notifications
You must be signed in to change notification settings - Fork 49
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
standardize and export getter names #190
Conversation
Codecov Report
@@ Coverage Diff @@
## master #190 +/- ##
==========================================
+ Coverage 86.27% 86.29% +0.02%
==========================================
Files 29 29
Lines 12561 12560 -1
==========================================
+ Hits 10837 10839 +2
+ Misses 1724 1721 -3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I went with standard deprecations without forcing warnings even when
We'll need to remember to increase the minor version before this change makes it to a new release. |
For users, the documentation has information
|
Any other thoughts on this: about the new names? about exporting them? |
Thank you Cécile for working on this ! I like the new names, and I agree that we should export them. The standard deprecation mechanism you chose seem indeed appropriate. I have only maybe one comment about the functions : there are a lot of them, which could make them difficult to discover for the users. You already link some of them in the doc with a "See also" paragraph. Maybe we could increase the links there ? Eg refer to An other approach we could take is to use keywords arguments. So eg instead of having 4 functions: getparent(node; parent="node", type="major") So that default getparent(node; edge=false, major=true) With this semantic, we have only one function, and all the features are easily discoverable (all are documented in the same docstring). However, some drawbacks are that (1) the function is more complex; (2) there might be some strange combinations (eg Anyway, these are just some thoughts, and I'm happy with the current naming scheme. |
Thank you Paul!
Ah yes absolutely (duh!!). It would greatly help discoverability.
That's a very neat idea. My main worry is performance. Code that has forks / branches (depending on keywords) could become slower. Multiple dispatch is super-efficient in Julia, so having 2 methods for
Aha, that's another great idea: we could, in fact, document all these functions in a single docstring. That could actually be much better than many different docstrings that refer to each other. For short docstrings at least. |
There could be a small overhead to use keyword arguments instead of different function names, based on the silly example below, so I'd rather stick to different functions. I consolidated the docstrings (7 fewer than earlier). You can check a preview of the documentation starting around here. I also fixed a function that would have bugged on networks with a hybrid ladder (sorry for adding unrelated changes!), and I plan to improve the docstring for the function that calculates the hardwired-cluster "distance". function foo(x; type=:add, what=:one)
if what == :one
if type == :add
fun = addone
else
fun = subone
end
else
if type == :add
fun = addtwo
else
fun = subtwo
end
end
return fun(x)
end
@noinline function addone(x) return x .+ 1; end
@noinline function addtwo(x) return x .+ 2; end
@noinline function subone(x) return x .- 1; end
@noinline function subtwo(x) return x .- 2; end
foo(5.5)
@benchmark addone(rand(1)) # mean: 89.525 ns
@benchmark foo(rand(1)) # mean: 100.739 ns |
Thank you for checking the keyword option, I hadn't think of the computational overhead. Thanks ! |
@crsl4 @pbastide this is ready for discussion, started on #80. I went with these principles:
get...
oris...
orhas...
.edge
as suffix if the function returns an edge, instead of a node. No suffix if the function returns a node, to get shorter names.minor
as a suffix if the function returns the minor instead of major edge. No suffix for major, again for shorter names, also because there's nominor
option in some cases (e.g. parent node of a tree node).isa
,indexin
,typeof
etc.Questions:
GetChild
andchildnode
functions.edge
andminor
be switched, when both are used?getOtherNode(edge, node)
?What I'll do later: think about
descendants
and functions to get node ages or distances between nodes.Below is a recap of the name changes so far.
new functions:
For most of them, the goal is to avoid using the internal structure (e.g.
node.leaf
), which is not recommended. These function will be inlined by the compiler, so there is no cost to performanceexisting functions, renamed and exported: