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

Incompatibility between @doc and import #3272

Closed
josevalim opened this issue Apr 16, 2015 · 6 comments
Closed

Incompatibility between @doc and import #3272

josevalim opened this issue Apr 16, 2015 · 6 comments

Comments

@josevalim
Copy link
Member

Today, even if we @doc false some function, it will still be imported if someone imports the module. I am listing this as a potential bug, although I am not sure if it qualifies as one or if there are any solutions.

@whatyouhide
Copy link
Member

This is one tricky case :). In Elixir it looks like @doc false is the "standard" way to use a function from another module within the same library, without exporting it outside the library. Maybe the solution could be something like a @hidden attribute:

@hidden
def my_fun do
  # ...
end

The @hidden (or whatever name) attribute would

  • hide the function from the documentation
  • prevent the function from being imported with import
  • [insert whatever other thing is useful when dealing with this pattern]

@tony612
Copy link
Contributor

tony612 commented Apr 16, 2015

@whatyouhide It seems like defp

@whatyouhide
Copy link
Member

@tony612 with the major difference that you can actually call that function from outside the module (provided you know the name and arity of the function).

@liveforeverx
Copy link
Contributor

"The @hidden (or whatever name) attribute would"

It make sense, only if there will exists contrapart something like import_all, that really import all 'def'-defined functions, without exceptions.

@whatyouhide
Copy link
Member

@liveforeverx instead of introducing import_all, you could easily solve this like in the following example:

defmodule MyMod do
  @hidden true
  def my_fun() do
    # ...
  end
end
import MyMod, hidden: true

@josevalim
Copy link
Member Author

This discussion pointed out that the current approach is fine. There are multiple ways of avoiding this (moving to another module, using underscore, etc). It seems better than somehow coupling to unrelated things. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants