Replies: 8 comments 7 replies
-
A very nice write up <3. My 4,5 cents on this: I.2I feel like it should be the other way around. The procedure group II.2II.2 Since many procedures are already well-named and self-explanatory, a full description can be considered optional—though, as with the examples, it's still encouraged. |
Beta Was this translation helpful? Give feedback.
-
Great, some notes:
|
Beta Was this translation helpful? Give feedback.
-
Thanks for the input. I have updated this discussion to reflect on the changes, there are a few more questions to clear up. First, I would like you to read this. Do we want to follow this? Aside from the benefits to it as for writing skills, there's also one other benefit we could have from it -- cleaner diffs. This, combined with making 120 character limit could be readable in plaintext, and push documentation contributors to try their best at writing shorter, more concise sentences that flow naturally. The second thing that I have a problem with is the format of the first sentence of the full description. Does it need to start with
Might not be too bad? |
Beta Was this translation helpful? Give feedback.
-
Regarding "This procedure", I just happened to look at what git generates as the commit message when reverting a commit via
Instead of saying "this commit" it simply states "this does X". So If I translate this to a sample documentation comment, it would look something like: /*
Round a duration to a specific unit
This rounds the duration `d` to a specific unit `m`
*/
duration_round :: proc "contextless" (d, m: Duration) -> Duration How does it look? I know @laytan had some issues with "this procedure" prefix, do you think this makes it any better? Regarding my work on the documentation front, I've just moved out, and it's gonna take a while until I get my desk, keyboard and everything else. I will probably continue after a few weeks. |
Beta Was this translation helpful? Give feedback.
-
Hm, this is what concerns me the most. Odin in general needs more guides. I mean ANY guides. It is very cool language that "feels right" with a lot of out of the box comfort, but the lack of tutorials might kill it. |
Beta Was this translation helpful? Give feedback.
-
Hi. For |
Beta Was this translation helpful? Give feedback.
-
I think that's great 👍 |
Beta Was this translation helpful? Give feedback.
-
Here's an interesting thought I had. If you copy-paste documentation (as opposed to saying "see procedure/type X documentation"), you can delete any functions without worrying about updating documentation of other similar procedures. Of course this can't be applied generally, because there are other legitimate reasons to cross-reference documentation, but it does give you a slight advantage when developing a highly volatile package. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion would be changed to reflect the current state of the conventions.
Changelog:
2025-05-05 - Version 2
2025-04-16 - Version 1
<details>
tag.package
declaration2025-04-15 - Initial version
Context
Documentation for Odin's
core
packages is written alongside the code, which means there is a single source of documentation and many more consumers -- Text Editors, LSPs, Documentation testers, and pkg.odin-lang.org. This document outlines common guidelines that allow this single source of documentation to be usable for most consumers that we may care, as well as readable to the users of thecore
packages.These guidelines are meant to be applied to Odin's
core
packages only.vendor
packages are excempt from these, as they have their primary source of documentation elsewhere. Any other Odin code is encouraged to use these, but not required.Currently, we have the following issues with documentation in the
core
packages:Inputs:
andReturns
sections etc)Goals
The goal of the conventions to be defined below are as follows:
I. How to document packages
1. Package documentation
In order for a comment to be considered package documentation, it needs to directly precede the
package
declaration at the top of the file.There should be only one package-level documentation comment per package. The following paragraph explains how to chose that file.
Package-level documentation should be located inside the
doc.odin
file inside of the package directory. This file should not contain any other declarations. If the package only consists of one file, instead ofdoc.odin
, the package documentation may reside in that file.One file in a package
More than one file in a package
2. Procedure groups
When documenting procedure groups it is important to consider the following:
Copy-pasting documentation is not a problem. The problem is not having it available conveniently when it's hidden somewhere else. Therefore it's important that both the group and its procedures, all have proper documentation treatment.
However, it is advised that each variant at least contains the short description (see below).
❌ How NOT to
✅ How TO
This should be a good balance between copy-pasting a lot of text (causing noise) and providing value for the users.
3. Structs and enums
For structs and enums, each field may want its own documentation. In this case, each field must be prepended with a documentation comment as opposed to following the field. Unlike every other documentation comment, these should be line comments.
❌ How NOT to
✅ How TO
This should make it easy to find where the documentation comments are inside of the structs, even if multiple lines are required in a doc comment.
4. OO-style API
OO-style API is quite common. I refer to the type that is associated with many procedures that operate on that type. For example, the
Allocator
implementations incore:mem
, or the string builder incore:strings
.For these API's it is advised that the main type is given the most thorough documentation, describing how it's used, why it can be used, and how it is different from other types in the package, or otherwise.
For examples, see synchronization primitives in
core:sync
or the allocator implementations incore:mem
. These should be done correctly on that specific front.II. The structure of the documentation comment
The documentation comment should be a multi-line comment. The text inside of the comment should not be indented, and the
/*
and*/
should be followed/preceded by newlines respectively.❌ Don't use single-line comments for documentation
❌ Don't indent the contents of comments
✅ How TO
The choice of unindented comments has to do with tools -- some markdown parsers will parse indented strings as codeblocks, and not all editors have control over that. However, it could be possible to pre-process the strings before passing them to the markdown parser, indented comments might still be open?
The insides of the comment consist of the following parts:
1. Short description
The short description of the procedure must fit on a single 50-80 characters long line. By looking at this line, the reader should be able to quickly tell whether this procedure is the one might want to use or not.
The short description should start with a verb in an imperative form, and form proper sentences.
2. Full description
The full description should describe the procedure fully. This includes how the parameters of the procedure are used to return its value, what it does under the hood, and most importantly -- why this procedure/type exists, and why you might want to use it.
Ideally, the full description mentions the parameter names from the Input sections. They should be wrapped in backticks.
Not sure: The full description should not be wrapped manually to 80 characters per line. Instead, each sentence should be written on a separate line. This makes the diffs look clean.
❌ How NOT to
✅ How TO
Not sure: Whether to allow
This procedure
prefix. I don't, aesthetically speaking, like two lines starting with same words, so I'm using it for that purpose.3. Inputs and Returns
This sections purpose is to link the parameter names to the description above. In cases where the connection is clear enough, these sections are allowed to be omitted.
pkg.odin-lang.org automatically converts all section names to bold. Therefore putting asterisks manually is not advised. LSP hover providers should take that into account as well.
The input field must contain a markdown list of parameters. It should be formatted as follows, with backticks surrounding the parameter names (If the parameters are unnamed, names are dropped), and the colon separating the parameter name from its description.
Exactly the same formatting is expected for the Returns section.
Avoid more than one line per parameter in this section, and also avoid too many references to parameters, when not required:
❌ How NOT to
✅ How TO
Note that this effectively spells the same thing twice -- once in the full description, and once more in the inputs/returns sections. This is on purpose. The information is duplicated to allow quick scanning of documentation to obtain the information in whatever format you need -- if you need a quick reference, the user will quickly scan for Inputs/Returns sections. If more detail is needed, they would carefully read the full description. Therefore the full description should also mention the fields by name.
4. Examples and Output sections
These section are optional, but strongly advised. These two sections always come in pairs.
The Examples section must contain executable source code inside a code block. The code must be a valid Odin file (aside from it not needing a
package
declaration, and some imports). The code must contain a function named<something>_example
.TODO: Resolve what is allowed
The code block must be formatted as an indented string (the tools should correctly deduce the type of code as
.odin
)✅ Example
It is also advised to use real examples of how you might use the procedure, and giving variable's "very descriptive" names.
Do not spam examples to test the edge cases. Examples are not a way to test the procedure, it's the opposite, we test the examples to make sure they run and describe what's gonna happen correctly. For most procedures one is enough. For some 2-3 would suffice.
If the code is not meant to be tested (for example if it has a potential to hang the CI) then
_example
suffix can be dropped, and the output section in this case becomes optional.✅ Example
These rules have a two-fold purpose:
5. Other possible sections
core:simd
to explain the array logic in plain-old-loops using pseudocode.Other sections can be used for packages if they require it. The choice for naming and conventions has to be consistent though.
When introducing a new section, make sure it doesn't belong to the full description instead. The purpose of sections is to provide an information that is uniform across all procedures/types of a package to allow reader to quickly scan the information. An example of a section might be the performance characteristics for data structures. An example of non-section would be Notes, because there's no reason for anyone to try and "quickly find Notes".
6. Notes
When formatting a note you can parenthesize its scope. For example, to Note something for windows implementation you can use:
III. Formatting guidelines
-
**
, italic with*
'|'
) inside table cells. Markdown parsers are pretty inconsistent about their escaping.<
and>
should be escaped to<
and>
by the parsers.[[ Example; https://example.com/ ]]
, or[[ https://example.com ]]
IV. General guidelines
Make sure your documentation includes:
For the package documentation: it should give an overview of what the package is about, define field-specific terminology, and so on.
Make sure you form your sentences using the proper grammar (capitalize words, end with period, some crap about oxford commas). Try to use simple words, and avoid terminology. Some package-specific terms (like critical section in
core:sync
, or lifetime incore:mem
) should be described in the documentation for the package.Make sure the full description properly references inputs and returns from the respective sections and the names of the variables match the function signature.
Beta Was this translation helpful? Give feedback.
All reactions