-
Notifications
You must be signed in to change notification settings - Fork 371
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
Style guide: When to use underscores? #1062
Comments
Since no-one has commented, I'll propose what makes the most sense to me.
We could put this in the style guide, and clean up Hy's source to use this style consistently. @algernon, is this something you could put in Hydiomatic? |
Not sure I can do that, Hydiomatic sees the mangled names only, unless we added some meta-data to Hy while I wasn't looking (or if I was looking, I forgot). But if Hydiomatic can, somehow, figure out the original symbol name, then adding these checks would be a breeze. |
see also #972
All we've got in the style guide so far is:
Should we also use dashes for Python's many "dunder" special names like
--init--
or do we keep them as underscores like__init__
? The latter is more recognizable Python, but the rule would be more consistent if it was "always use dashes". Whatever we choose, it should be stated clearly in the guide. We could also do things like-_init_-
or_-init-_
or--init__
or__init--
. Yeah, that looks weird, but you're forgetting that__init__
also looks weird, and then you got used to it. If any of these were standard Hy style, you'd get used to it. We could have a rule like "never mix dashes and underscores", but I don't think that's a good idea. More on that later.The Python convention for a "private" variable is
_x
. At the module level it gets excluded from thefrom <module> import *
by default. In this case I think keeping the underscore is a better choice, since-x
is too easily confused with(- x)
. We do use a dash to mean negation in number literals like-1
. So maybe "always use dashes" isn't such a good rule. What if we have a "private" compound name like_foo_bar
? Should that be rendered in Hy as_foo-bar
? But now we're mixing dashes and underscores. I don't think it looks that bad though.And finally, inside a class, a double-prefixed attr like
__x
gets mangled to_classname__x
to avoid conflicts with subclasses. Should we render this as--x
in Hy? Or-_x
or_-x
?We're not consistent even in the source of Hy's standard library.
The text was updated successfully, but these errors were encountered: