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

RFC: make __xxx__ names officially reserved #18249

Closed
StefanKarpinski opened this issue Aug 26, 2016 · 8 comments
Closed

RFC: make __xxx__ names officially reserved #18249

StefanKarpinski opened this issue Aug 26, 2016 · 8 comments
Labels
docs This change adds or pertains to documentation speculative Whether the change will be implemented is speculative
Milestone

Comments

@StefanKarpinski
Copy link
Member

We've used the name __init__ as a function name with special meaning in modules (function that is automatically called after a module is loaded but before the module is precompiled) and we may introduce __main__ in the future as a function in Main that is automatically called if it exists when a script run as julia script.jl finishes – the purpose being to allow a hypothetical julia-compile script.jl to produce a binary that behaves in the same manner as if you'd run julia script.jl without any changes to script.jl. In general, this points to the notion that we should officially reserve names of the form __xxx__ as having special meaning to the system.

@StefanKarpinski StefanKarpinski added speculative Whether the change will be implemented is speculative docs This change adds or pertains to documentation labels Aug 26, 2016
@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Aug 26, 2016
@stevengj
Copy link
Member

stevengj commented Aug 26, 2016

Seems unnecessary and possibly counter-productive. Did we actually hit any conflicts when we introduced __init__ or __precompile__?

@stevengj
Copy link
Member

stevengj commented Aug 26, 2016

Grepping for this, I see a number of such identifiers used in packages: __ids__, __rospy__, __sys__, __inits__, __entropyinit__, __sslinit__, __MAXCACHE__, ..., so evidently people find this useful. The use of this kind of name for "internal" identifiers is a commonplace habit from Python (and other languages, including C).

(No one is currently using __main__ as far as I can tell.)

@yuyichao
Copy link
Contributor

yuyichao commented Aug 26, 2016

Ref #11098 I also think we shouldn't use module level special names as long as it's possible so that it is easy to make use of those features in macros/libraries or moving code between modules.

It might not be too meaningful to allow multiple entry points but I think a interface like @main function my_main() end should work equally well and can also throw errors at compile time (i.e. when the module is evaluated) if the function/method registered doesn't make sense.

@eschnett
Copy link
Contributor

Does it suffice to reserve _jl_ and __jl_? If there are not too many anticipated names, a jl prefix doesn't hurt, and might help readability.

@stevengj
Copy link
Member

@eschnett, I'm not sure what purpose _jl_ would serve, because _jl looks like a prefix for Julia internals, which we can just put in Core or Base without exporting them. Any symbol we actually want to use would be something like __init__ or __precompile__ or __main__, and a _jl_ prefix seems confusing in those cases.

@vtjnash
Copy link
Member

vtjnash commented Aug 27, 2016

@Stefan I have largely expected Main.__init__ would take the place of __main__ or __start__ or other such. Is there any other need for these internal names? For most things, we can provide registration functions from Core (or via ccall), so I don't really see us needing to reserve a namespace in every Module for internal use.

@StefanKarpinski
Copy link
Member Author

No, the name Main.__init__ would be fine and fits well with the existing meaning. The broader point of this issue is to have a way of pre-reserving names that have special meaning to Julia. People mistakenly use __xxx__ names in Python as well, but when they do so, they risk having their code break in strange ways in future versions where that name means something special.

@StefanKarpinski
Copy link
Member Author

StefanKarpinski commented Oct 27, 2016

Seems like we don't need this (unlike Python, Julia doesn't have a global method namespace).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation speculative Whether the change will be implemented is speculative
Projects
None yet
Development

No branches or pull requests

5 participants