-
-
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
associating data with functions, modules, and globals #3988
Comments
I'm pretty excited about this; I think it'll make documentation easier as a first pass, but being able to attach data to functions in general can be used for quite a few neat things. The first time I wanted something like this was when I was developing the codespeed infrastructure; I wanted to annotate functions with metadata stating the name of the test that function ran, what units the resultant metric of that test would be, (Time, FLOPS, bytes/clock cycle, etc....) whether "less is better" for that particular unit, etc..... So I think whatever we come up has the opportunity to be somewhat more than the only analogue I can think of right now (Python's docstrings), which is just a single string of data. We have the chance to make the data we attach highly structured, in the sense that it can be manipulated by other julia code. |
regards to all .. imho .. @StefanKarpinski writes this right
In any creatively powerful software paradigm, and so certainly with Julia, there is available a dynamism that at once allows a design to run well, go fast reliably, and harvest the deep accurately and at another affords development, investigation and playfulness the robust power and makes perspective, conception, and insight readily accessible as a newly realized design that runs well, goes fast and is reliably accurate. As Stefan notes, it is entirely reasonable and sound that Julia offer the language user each modality's respective advantage; that is more compelling than a requirement that they operate in mutual simultaneity. |
+1 |
To comment on You are probably much more flexible in what you can do than us in IPython, and we will happily see what you come up with. Be carefull though, with rich mimetype representation of documentation, doc may become a security issue (inject javascript in the notebook that can execute code in the kernel), but it can also be an advantage as you could also have executable or dynamic doc, like runable sample code. One thing we were not totally able to solve is how to have working cross-link in the live documentation in the notebook. |
similar to #2508 |
This issue has been neglected for too long. Let me make a concrete proposal to get the ball rolling. A basic starting point could be:
On top of this machinery, various pieces could be added:
The simplest documentation would be in the form of strings, for which only the
or there could be a |
I like the simplicity of this approach. @velicanu might be interested. |
This is a really great idea. |
This is interesting, I'll try to do it. |
We also need some way of associating documentation with manual sections in a hierarchy (e.g. "Mathematical functions / Special functions / Bessel functions"). And in general we want a way to associate metadata with objects. One option, in line with the above proposal, would be to:
and would store them in a "metadata" |
Some thought should go into the |
@loladiro, is there any missing functionality in the above proposal compared to what is needed to implement the REPL |
Have you considered dooing so only at install time for libs ? I'm especially thinking that for library. One would probably like to build the all html doc at once when the library is installed, because of cross-links and everything |
@Carreau, on top of this one can build various tools, e.g. a tool to import a module and build documentation in some format. As @StefanKarpinski said at the top of this thread, however, that is conceptually separate from the task of associating the data with the objects in the first place. |
@stevengj Sorry I wasn't clear, I was not worried about the external tool to build the doc, I was wondering about associating externally this back to the objects. Like an external way to add value to |
I'm not sure what you mean by an "external way to add a value to |
I might have misunderstood something, and will re-read, but
I was more thinking of a persisting database of those info (for example build at package installation time) |
The global dict What's missing is the possibility to associate data with globals. Either make all globals containers with a |
What's wrong with a global in this context?
What is the concrete disadvantage of a global dictionary that overcomes its advantages in simplicity and functionality? Blanket prejudice against globals is not persuasive. |
To me segregating the function/method metadata from the function is odd. There is plenty of (meta-)data already associated with methods/functions/modules (e.g. signature, module...), why treat the additional metadata differently? (See point 3 for the most important argument) Say for instance, I have a method which is 'private' to my module, i.e. I don't export it. But I may still want to document it (for my own purpose) or I want to add other metadata like @staticfloat mentioned. Why should this metadata, which is private to a module, live in a global variable? Comments to your points:
Well, either way, it will be good to have a way to associate metadata with functions etc., especially for docs. |
Number 3 is actually not a problem, since you would use the function object itself etc. as the key: |
Argh, github though that my 3. was a 1. I was talking about number 3, anyway. |
There was a lengthy discussion about help/documentation/etc on the mailing list recently, worth referencing here: Of course, no consensus was reached but a few interesting things were discussed:
|
Jeff and I just talked about this today and a bare string literal in void context followed by a definition seems like the way to go. This should be lowered by the parser something like this: "`frob(x)` frobs the heck out of `x`."
function frob(x)
# commence frobbing
end becomes the moral equivalent of this: let doc = "`frob(x)` frobs the heck out of `x`."
if haskey(__DOC__, :frob)
__DOC__[:frob] *= doc
else
__DOC__[:frob] = doc
end
end
function frob(x)
# commence frobbing
end Important points about this approach:
An open issue is how to handle adding methods to functions from other modules. Does the definition go into the current module's [cross-posted from here] |
I don't like the fact that doc are before function but that's probably beeing use to python. Though for me it raises a side question. When printing function source code, will it show docstring above function? I'm asking cause it is one of the things that annoy me in js, which is inability to print docstring in repl when they are before function def. I know it's a detail but just want to bring it up. Envoyé de mon iPhone
|
I agree. The thing I most look at documentation for is to see the signature and the one-line summary. Having those right next to each other (as in Python) is really nice. In this proposal, will they often be separated by a lot of detailed documentation? One way around this is to reproduce the signature, as in the above example, which seems a bit silly given that the perfectly good signature (often with great type information) is available right at the start of the function. I guess another way around this is to put a one-line summary at the end of the docs, which seems weird to me. |
@StefanKarpinski, two things:
Your example would then look like: "`frob(x)` frobs the heck out of `x`.":
function frob(x)
# commence frobbing
end becomes the moral equivalent of this: function frob(x)
# commence frobbing
end
setdoc!(frob, "`frob(x)` frobs the heck out of `x`.") Two more things:
|
I guess that in generated docs the issue of signature/summary separation does not exist as things can be reordered. The issues arise only when reading source code. Envoyé de mon iPhone
|
One motivation for this design is that it extends to simple variables, e.g.
Supporting that also seems to preclude attaching the doc string to the object. |
If you play around with this syntax in the presence of multiple dispatch, you can see immediately that the doc string inside approach just doesn't work: you want to have the doc string for a generic function before a series of method definitions for the same generic function, not inside one of the method definitions. We're also going to use this for things like globals, which don't have an "inside". |
Some other examples:
|
What would this do?
|
At first that might have to be a parse error, or we just ignore the doc string if we don't know how to attach it to the following expression. |
It would be nice if one could refer to args by name in the doc. I find this really useful for more elaborate explanations. Like "blabla @arg blabla" If you think @ clashes too much with macros then just use another character. |
Since these are presumably also going to be collected into external On Tuesday, September 30, 2014, Steven Sagaert notifications@github.com
|
See #8514; @StefanKarpinski's preference is that the documentation be inserted into external docs by some kind of |
It would be nice to have the possibility to refer to args by name in the doc string/comment like “this is the doc for f. @x specifies the input” function f(x) …. end I’ve used @x here because that’s what’s used in javadoc but if you think this clashes too much with macros then just take another character. This can be really handy when you have longer doc with more detailed explanation. Van: Jeff Bezanson Some other examples: "doc for g" add docs to a function without defining anything"doc for h" — |
Is it fair to close this with the recent work on Cc: @one-more-minute @MichaelHatherly |
For reference: #8514 |
Yes, this issue seems to be basically concerned with the core doc system (storing + displaying metadata), which we have now. We do still want things like syntax, but now that those have their own issues this doesn't seem that relevant. |
Yeah, the general concerns in this issue seem to be covered by @one-more-minute's recent work. |
close this |
@ViralBShah looks like you performed a drive-by tag removal, but you didn't close--what is the remaining work here? |
…6cff6 (#55463) Stdlib: Pkg URL: https://github.com/JuliaLang/Pkg.jl.git Stdlib branch: release-1.10 Julia branch: backports-release-1.10 Old commit: 45521a6e8 New commit: a4f26cff6 Julia version: 1.10.4 Pkg version: 1.10.0(Does not match) Bump invoked by: @IanButterworth Powered by: [BumpStdlibs.jl](https://github.com/JuliaLang/BumpStdlibs.jl) Diff: JuliaLang/Pkg.jl@45521a6...a4f26cf ``` $ git log --oneline 45521a6e8..a4f26cff6 a4f26cff6 [release-1.10] Pkg.precompile: Handle when the terminal is very short (#3988) ``` Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
There are a number of issues discussing documentation for Julia code (#762, #1619, #3407), but I'd like to separate this problem into two very distinct issues:
We keep getting bogged down in the combination of these two issues, but they can be tackled separately, and should, imo, remain decoupled – that is, the infrastructure for (1) should be reusable with different approaches to interpreting comments and different mechanisms for presenting documentation (help, sphinx, dexy, jocco, etc.).
This issue is for discussion of (1):
Let's solve this first and then figure out how to interpret and present things.
The text was updated successfully, but these errors were encountered: