jeramyRR
Is it necessary to warn about the @doc attribute for a private function
Is it really necessary for the compiler to spit out a warning about using @doc with private functions?
I don’t want to have to document my functions in two different ways. I want one clean way to present my comments to other developers throughout the codebase, at least at the function head.
I’ve seen others say, on this forum, that private functions aren’t meant to be documented because they are ephemeral. I believe this to be nonsense. Someone else not writing my code has no say in how long I keep my private functions around. I guarantee you even great developers like Jose Valim write private functions. You can probably find them in elixir’s code itself.
I don’t think we need an @docp or any modifiers to go with the @doc attribute. Just good ole @doc would be great for all functions.
Anyways, I know other people have asked the same question and get the same answer, but I think it’s worth drudging up again.
Trending in Discussions
Other Trending Topics
Chat & Discussions>Discussions
Latest on Elixir Forum
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #elixirconf-us
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 52 Posts!
joaoevangelista
I have the same feeling about the warning, maybe not even using a new attribute like
docp. If that warning is to warn you that you are documenting a function that will never used outside and maybe you declared it wrong by usingdefpinstead ofdefthen the undefined function check will catch it. Or if the documentation will not render on hexdocs it’s ok too it’s private the function will not appear there anyway. Just let us write our docsmudasobwa
Sure thing. What you are missing is the main point: if there is a need to document a private function, it means there is a need for other developers to use this private function, which means it should not be private.
Private functions are not meant to be re-used. Private functions might stay there forever, but they are just implementation details, they are none of anybody’s business.
If you find yourself explaining to mates what your private functions do, you are either teaching them Elixir in general, or doing it plain wrong.
jeramyRR
Yeah sure, I get some of what you say, but I don’t think you’re thinking about every situation where you might want to document something you’re doing. Let’s say for instance you’re interfacing with someone else’s api which may be a little complicated, or maybe not. You may want to document why, or what the api is requiring from you in that function.
Or even better, this is a dynamic language, and not everyone uses dialyzer. You may want to document the format of the returned data.
Maybe i’m trying to conform to an RFC and I want to document where to find it.
There are plenty of reasons why I want to document something. All these “you’re doing it wrong if you have to document it” excuses is really just a blow off answer.
To directly answer your “it means there is a need for other developers to use this private function”, that’s not the only case. It’s possible that my logic is completely wrong, or something breaks later on down the road. I want to let the developer that comes after me know why I chose to do something the way I did, or what I thought my function was going to do/return.
I haven’t been programming for that long, but I swear I’ve never seen a community so against documenting their code or making others feel like dog crap for wanting to document theirs.
mudasobwa
I never ever meant this. What I meant is being restrictive here, Elixir compiler plays the role of linter. There are 100 to 1 cases when documenting private functions is wrong. For the rest one still has any other type of comment, including but not limited to assigning the module attribute like
Allowing comments for privates because not everyone uses dialyzer is exactly what we are against of. It’s like allowing
"0" == 0because not everyone uses proper type conversions, IMSO.jeramyRR
This is kind of what I’m talking about “what we are against”. We who? The coding gods that say “Thou shalt program the way I want you to program?”
And, if the coding gods want us to always use Dialyzer, something that’s not even a part of the language, then the coding gods should make the language strongly typed.
I don’t buy this at all. If you’re writing code that is going to be pushed into production, and you’re not commenting it, you’re treating the people that are going to have to debug the code later just plain wrong.
It doesn’t matter that anyone here thinks that you shouldn’t write a private function, or whatever the case is. People are going to write code, and they’re probably going to write it in a way that you think they shouldn’t. It doesn’t matter. There still should be a standard way of documenting or commenting it. The way for that was chosen… @doc. That should be available everywhere.
mudasobwa
That is where you got it wrong. The way for that was chosen (by language creator.) This way is (like it, or hate it, it does not actually matter): you use
@docto comment public functions only, period.mudasobwa
There is nothing more overhyped for zero value than strong typing. It brings literally nothing save for headaches and enormously huge boilerplates.
jeramyRR
This is the whole reason for this post. The fact that it can only be used for public functions. In my opinion, and obviously others since there are more posts on this forum talking about it, that it should be open to all functions, not just public.
jeramyRR
That’s an opinion, and you already went against it when you suggested that commenting be replaced by using dialyzer, which is a typing addon to the language.
benperiton
I think the ‘problem’ is that there isn’t a way to just comment and document (in the ‘what this does’ sense, not the ‘create documentation’ sense) a function no matter what it is.
@docis used to also create documenation automatically - hence people saying don’t use it for private functions, as you don’t want other people to consume those really.What you want is something like a
@nodocor@docnothat allows you to use the same format to comment code, but without it getting attached to auto generatred docs?Last Post!
nulltree
The second point is what really gets me - I pretty much just care about getting better info about the private function’s contract ‘on LSP hover’ myself. My mind is a single-core processor with a small cache - I can’t juggle a lot of context in my head and jumping back and forth to read comments is effectively that.
If that requires a new nomenclature besides documentation and code comments, I’m fine with that.