Skip to content
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

New EEP: Module attributes for documentation #24

Merged
merged 1 commit into from
Feb 17, 2022
Merged

New EEP: Module attributes for documentation #24

merged 1 commit into from
Feb 17, 2022

Conversation

josevalim
Copy link
Contributor

No description provided.

@josevalim josevalim changed the title EEP 57: Module attributes for documentation New EEP: Module attributes for documentation Jun 2, 2021
eeps/eep-0057.md Outdated Show resolved Hide resolved
eeps/eep-0057.md Outdated Show resolved Hide resolved
eeps/eep-0057.md Outdated Show resolved Hide resolved
eeps/eep-0057.md Outdated Show resolved Hide resolved
eeps/eep-0057.md Outdated Show resolved Hide resolved
eeps/eep-0057.md Outdated Show resolved Hide resolved
@essen
Copy link

essen commented Jun 2, 2021

First, attributes without parens is weird. :-)

I agree about wanting a different solution than code comments. Comments are not documentation. I disagree about documentation in the source code being easier to keep in sync, it gets out of date just as easily as external documentation. On the other hand when the documentation is in the source code it's easier to sneek in potentially breaking documentation changes unnoticed.

As a result I would much prefer to keep external documentation but still make use of these attributes, perhaps via something like:

-moduledoc({external, "doc/src/manual/my_module.asciidoc"}).
-doc({external, "doc/src/manual/my_module.my_function.asciidoc"}).

This would close any debate about documentation inside or outside the source code since both would be possible. There is also no issues around quotes when using external documentation.

I suppose a compile flag could be added to locate the external files more easily, though . is perfectly fine in my case.

eeps/eep-0057.md Outdated
Copyright
=========

This document has been placed in the public domain.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should strictly describe license, like CC0, as not all jurisdictions allow voluntary assigning document to public domain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the standard of all other EEPs, so I won't change it, but perhaps this conversation needs to brought up elsewhere? Or maybe it only matters for what is valid in Sweden in this case?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim created #25

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, the templates were copied from PEP, so this phrasing is likely just an old artefact. I agree it should be changed to CC0. In many countries (including most of Europe) saying "this is placed in the public domain" does not have any legal effect. Copyright is automatic as of the Berne convention of 1988.

@josevalim
Copy link
Contributor Author

@essen thank you for the comments and the suggestion. I will amend the proposal to allow embedding external documents too. It may be a bit repetitive to provide a path for each doc but I guess someone could write a parse transform that maps everything in a directory to moduledoc+doc if they really want to reduce the duplication?

@KennethL
Copy link
Contributor

KennethL commented Jun 2, 2021 via email

@RaimoNiskanen
Copy link
Contributor

An EEP should have line breaks as any Markdown document (that follows E-Mail conventions).
From EEP 33:

You must adhere to the Emacs convention of adding two spaces at the
end of every sentence. You should fill your paragraphs to column 70,
but under no circumstances should your lines extend past column 79.
If your code samples spill over column 79, you should rewrite them.

eeps/eep-0057.md Outdated Show resolved Hide resolved
@josevalim
Copy link
Contributor Author

@RaimoNiskanen updated!

@essen and @KennethL, I added a section about supporting -doc({file, Path}). There is only one concern: you wouldn't be able to place documentation metadata in an asciidoc file. But I assume that is fine? The metadata is typically License+Author for modules and Since+Deprecated annotations for functions.

@lhoguin
Copy link

lhoguin commented Jun 2, 2021

Yes no problem about metadata.

eeps/eep-0057.md Outdated
The new `-moduledoc` attribute can be listed anywhere and it will contain
the documentation for the given module. The `-doc` attribute must be
listed once before each function and it will contain the documentation
for the following function.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ordering preferences compared to type specs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ferd please expand? I am not sure I follow the question. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

People have a tendency to do something like:

%% @doc This function turns the programmer into a much more productive one
-spec levelup(programmer()) -> programmer().
levelup(Programmer) -> Programmer*10.

The new literal translation would be:

-doc "This function turns the programmer into a much more productive one".
-spec levelup(programmer()) -> programmer().
levelup(Programmer) -> Programmer*10.

This will work with the spec above if we read "listed once before each function", meaning there can be one -doc attribute before any function and it will get assigned to the one that follows.

However the spec could also force the following if we read it to mean "the doc must be listed once right before each function":

-spec levelup(programmer()) -> programmer().
-doc "This function turns the programmer into a much more productive one".
levelup(Programmer) -> Programmer*10.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. We don't look at other attributes, so it can be anywhere before a function. I will clarify.

eeps/eep-0057.md Outdated
`u"Héllò World"`. While adding such construct is not a direct part
of this EEP, the point made in this subsection is that, if we require
the documentation or its metadata to be a binary, we may need to
provide conveniences for writing UTF-8 binary strings in Erlang.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, to me, would point towards supporting both formats and converting. Erlang strings should represent safe unicode data that can be converted later with unicode:characters_to_binary(CharData) and for the time being provides safe unicode with low syntactic overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I agree with you. What about metadata? Should it be automatically rewritten too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could make sense. I'd see this as an extension of all Erlang-style things where CharData gets flattened down for you when possible. It would in principle not harm anything as long as you specify you expect data to be UTF-8 compatible, meaning raw strings, binaries in the utf8 encoding, or lists of either of these.

@hauleth
Copy link

hauleth commented Jun 2, 2021

@josevalim

you wouldn't be able to place documentation metadata in an asciidoc file

ASCIDoc has built-in support for document metadata via attributes. So with "smart enough" implementation the metadata could be stored in the external files as well.

@essen
Copy link

essen commented Jun 2, 2021

I would suggest keeping the external file format implementation not smart to begin with and build upon them later if there's strong interest. Asciidoc attributes are one option, but there's also Hugo-like header variables that work with any file format for example.

@moiseev
Copy link

moiseev commented Jun 3, 2021

Any thoughts on the warning similar to -compile(warn_missing_spec). now that these docs are known to the compiler?

eeps/eep-0057.md Outdated Show resolved Hide resolved
eeps/eep-0057.md Outdated Show resolved Hide resolved
eeps/eep-0057.md Outdated Show resolved Hide resolved
@josevalim
Copy link
Contributor Author

josevalim commented Jun 3, 2021

@moiseev I have added a section mentioning this feature could also be added in the future too, thanks!

eeps/eep-0057.md Outdated Show resolved Hide resolved
@hauleth
Copy link

hauleth commented Sep 23, 2021

I would suggest keeping the external file format implementation not smart to begin with and build upon them later if there's strong interest.

@essen that was what I meant. It shouldn't be Erlang concern to understand and extract metadata from documentation, but the documentation processor (external) should be able to achieve something like that in future.

@michalmuskala
Copy link
Contributor

This seems like a fantastic proposal that would simplify dealing with in-code documentation significantly compared to edoc comments. Is there anything I could do to help move this forward?

@KennethL
Copy link
Contributor

Can you please change the file name to eep-0059.md and I will merge this PR so we can refer to it as EEP-59

@josevalim
Copy link
Contributor Author

@KennethL done! I have also updated some parts with the feedback received in this PR.

@josevalim
Copy link
Contributor Author

I pushed again to make the linter happy!

@KennethL KennethL merged commit b31999c into erlang:master Feb 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet