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

Clarify that private variables should not be prefixed with an underscore #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrPowers
Copy link
Contributor

I agree with the majority of posters in this thread that private variables should not be prefixed with underscores.

In the Spark codebase, the majority of private variables are not prefixed with an underscore, but there are a lot of exceptions. Run ack private\ val\ \_.

Please provide some more guidance if I'm missing something (e.g. certain private variables should be prefixed with underscores and others should not). Thanks!

@rxin
Copy link
Contributor

rxin commented Mar 31, 2017

So this has been debated in the past and a lot of people with experience in Java / C++ are used to writing underscores. I personally don't have an issue with it.

@MrPowers
Copy link
Contributor Author

MrPowers commented Mar 31, 2017

@rxin - I did some research on how some popular open source Scala projects name private variables.

project # of private vals prefixed with underscore # of private vals # of total vals
scalaz 0 12 3,696
spark 77 1,991 71,390
scalding 0 57 6,447
playframework 2 165 8,974
akka 28 836 25,585

Here are the commands I used to generate the counts:

  • num private vals prefixed with underscore: ack private\ val\ \_ --type=scala | wc -l

  • num private vals: ack private\ val --type=scala | wc -l

  • num total vals: ack val --type=scala | wc -l

Most private vals are not prefixed with underscores in the selected projects. I think a codebase should be consistent, pick one convention and stick with it.

It seems like the Scala community generally favors not prefixing private variables, so I think my pull requests stands. I am open to your thoughts / comments. Thanks!

@rxin
Copy link
Contributor

rxin commented Apr 3, 2020

The issue is that what is the convention for naming a private variable that has a public method with the same name? Prefix underscore is a very natural way to do this (even in other Scala projects).

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.

2 participants