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

consistent underscore naming policy #1539

Closed
StefanKarpinski opened this issue Nov 13, 2012 · 31 comments
Closed

consistent underscore naming policy #1539

StefanKarpinski opened this issue Nov 13, 2012 · 31 comments
Labels
breaking This change will break code decision A decision on this change is needed
Milestone

Comments

@StefanKarpinski
Copy link
Sponsor Member

This is kind of a blanket issue that intersects with API cleanup and naming consistency, but we need to figure our shit out regarding when to underscore and when not to underscore. One possibly controversial proposal (that I'm not really sure I favor), would be using underscores consistently, which turns especially predicates like isempty into the much more annoying is_empty, but which would be addressed by adding support for names that end in ? and writing empty? instead. Another proposal would be that names in base, as the basic "grammar" of Julia don't use underscores whereas things in packages and user code use underscores. Or we just go fully Germanic and don't use underscores ever. Or we can just keep on being completely inconsistent.

@johnmyleswhite
Copy link
Member

I actually like having underscores everywhere, but also think that ? would be a great idea.

While we're on the topic of consistency in names, did we ever standardize on push! and similar examples?

@StefanKarpinski
Copy link
Sponsor Member Author

No, but I think we should. I'll make an issue for that.

@StefanKarpinski
Copy link
Sponsor Member Author

Oh, wait, we already have one: #907.

@staticfloat
Copy link
Sponsor Member

I'm ambivalent on underscores; I have no great love or hate of them, I could go either way.

For the question-mark syntax, since we need parens to call a function, are you suggesting the following:

if empty?( a )
  println( "a is empty!" )
end

@StefanKarpinski
Copy link
Sponsor Member Author

Yeah, that's the idea. It would make empty? a valid identifier for all purposes, but the convention would be only to use it for functions that are predicates. Not entirely sold on the idea, but it's a possibility.

@JeffBezanson
Copy link
Sponsor Member

I'd rather not, since we already allow the syntax a?1:0. I would also personally find is_empty very annoying, as would matlab users. I believe there would be too many other functions affected as well. Would we say flip_lr, cum_sum, fft_shift, etc.? Being 100% consistent here is not realistic IMO.

@johnmyleswhite
Copy link
Member

I agree that isempty and cumsum aren't bad, although I think flip_lr and fft_shift are actually much better.

Maybe there's an intermediate compromise where there's an accepted set of prefixes in the way that ! is a suffix? in and cum seem like legitimate prefixes to me, while fft doesn't.

@JeffBezanson
Copy link
Sponsor Member

I like the idea of standard prefixes, so you can predict whether there is an underscore. The only wrinkle is that it's confounded by established names like strerror, getenv, and in the case of matlab fftshift.

@jacg
Copy link

jacg commented Nov 16, 2012

I would like to register my support for allowing '?' as a constituent character of identifiers. Someone else suggested that we be obliged to separate any preceding name from the '?' in the ternary operator. Unlike the proposer, I'm not convinced that this is, in and of itself, a good thing to impose, but I do think it is a price worth paying for the ability to name predicates with a trailing '?'.

@StefanKarpinski
Copy link
Sponsor Member Author

Another fact that pushes me in favor of using trailing ? for predicates: we are currently pretty inconsistent about the is prefix, probably because it's linguistically awkward a lot of the time. For example, contains is a predicate, but doesn't begin with is; we could write iscontained, but that would be super awkward, imo. The same goes for has which is also a predicate. The list goes on. First off, contains and has should probably be merged into in, but then that still doesn't have an is prefix. I guess we could do iselem, but that's pretty awkward too. I'd rather call it in? or elem?

@johnmyleswhite
Copy link
Member

Since we're invoking intuitions from natural language, it's pretty clear that English predominantly makes questions by using tone at the end of sentences, which is what the ? gets at it. That makes its use natural for an English speaker, whereas the is_ prefix (which I nevertheless like) is going to fail in every case where the English sentence would contain "does" instead of "is".

Another perspective is that predicates derived from adjectives will work with is, but predicates from verbs need does. Stefan's contains example is one case of this problem.

@JeffBezanson
Copy link
Sponsor Member

I don't think it's necessary for every boolean function to be named consistently.

@sth4nth
Copy link

sth4nth commented Dec 31, 2012

why not camel. Functions begin with lowercase letters, types begin with upper case letters. isEmpty vs Matrix. Underscore can produce reeeeealy long names. I dont want to name my linear regression with automatic relenvance determination prior using empirical bayesian fitted by EM function as lin_reg_ard_eb_em()

@diegozea
Copy link
Contributor

diegozea commented Jan 6, 2013

Exclamation mark ! when you are going to modify the data and ? for function asking things, looks too easy of understand and use. Even for Spanish speakers like me. In Spanish. ( And I like the idea of something consistent, but can be awkward introduce some extra rule for ternary operator )

In Spanish, we grammatically use two sings, one for open ( ¿ ¡ ) and one for close ( ! ? ). But English it's so popular and using a trailing sign is more faster and comfortable, we use to use the English notation in the colloquial writing now.
Have a prefix instead of a suffix have a clear usability went you are using tab for auto-completion or if you forget the function name (but you know is a kind of question to data) [ it's common to me, because I'm used to switch between programming languages and because English it's not natural for my ] [ for ! is good at the end, because some function can have a version with and without the ! ]

Using ¿ ¡ symbols in beginning it's not going to collide with nothing... But can be awkward to native English speakers?

fill!()
empty?()

?empty()

¿empty()

The last looks to good to my, because I'm a Spanish speaker. But I'm comfortable whit the two first.

P.S.: I'm think that dequeue functions need to be consistent with the ! rules
[ https://groups.google.com/forum/?hl=es&fromgroups=#!topic/julia-dev/wKIlMaSj0YE ]

@johnmyleswhite
Copy link
Member

As you said, opening ¿ ¡ are clearly on their way out of the layperson's Spanish language. So I don't think adding them would help Julia.

I do agree that we should strive for greater consistency in naming functions that modify their inputs.

I would like to add ?, but that interferes with the ternary operator.

-- John

On Jan 6, 2013, at 5:23 PM, diegozea notifications@github.com wrote:

Exclamation mark ! when you are going to modify the data and ? for function asking things, looks too easy of understand and use. Even for Spanish speakers like me. In Spanish. ( And I like the idea of something consistent, but can be awkward introduce some extra rule for ternary operator )

In Spanish, we grammatically use two sings, one for open ( ¿ ¡ ) and one for close ( ! ? ). But English it's so popular and using a trailing sign is more faster and comfortable, we use to use the English notation in the colloquial writing now.
Have a prefix instead of a suffix have a clear usability went you are using tab for auto-completion or if you forget the function name (but you know is a kind of question to data) [ it's common to me, because I'm used to switch between programming languages and because English it's not natural for my ] [ for ! is good at the end, because some function can have a version with and without the ! ]

Using ¿ ¡ symbols in beginning it's not going to collide with nothing... But can be awkward to native English speakers?

fill!()
empty?()

?empty()

¿empty()
The last looks to good to my, because I'm a Spanish speaker. But I'm comfortable whit the two first.

P.S.: I'm think that dequeue functions need to be consistent with the ! rules
[ https://groups.google.com/forum/?hl=es&fromgroups=#!topic/julia-dev/wKIlMaSj0YE ]


Reply to this email directly or view it on GitHub.

@StefanKarpinski
Copy link
Sponsor Member Author

Trailing ? can be dealt with pretty easily – an identifier immediately followed by ? can just be parsed as an identifier. Putting the ? in the ternary operator right after an identifier is kind of a readability snafu anyway (although we do it a few times in base, that can easily be fixed); technically, it would be a breaking change, however.

@Keno
Copy link
Member

Keno commented Jan 7, 2013

Do we have an issue open for ? at the end of function names?

@johnmyleswhite
Copy link
Member

I don't believe we do. We should add one.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Feb 2, 2013

what was the decision on this? i recall that we would continue being inconsistent, preferring underscores for most names, but dropping them for short, common names like isempty and established names like getenv. if so, this issue can presumably be closed.

@StefanKarpinski
Copy link
Sponsor Member Author

General thinking, discussed with Jeff the other day is that names without spaces are in some sense "atomic" or "indivisible" – they are the words from which sentences are formed. Functions with spaces (i.e. underscores) are conceptually sentences, e.g. frob_the_foo – a function that frobs a foo. Base should only provide atomic functionality – i.e. words – not full sentences, so rather than providing a frob_the_foo function, it should provide a generic frob verb which can be applied to all kinds of things. So the basic takeaway is that base should generally not have underscores, but in user code it's fine since wrapping a "sentence" up as a reusable function is a good thing.

@StefanKarpinski
Copy link
Sponsor Member Author

To that end, we have been endeavoring to eradicate underscores from base, either by breaking them down into more basic pieces or by not exporting them at all.

@toivoh
Copy link
Contributor

toivoh commented Feb 9, 2013

How about e.g. Base.show_unquoted? I've been thinking that it should be exported from Base, but I'm not sure how to do that in an underscore-free way in accordance with the above.

@StefanKarpinski
Copy link
Sponsor Member Author

This doesn't have to be set in stone, but I've been finding that looking for underscores is an awfully good way to find the smellier parts of base.

@StefanKarpinski
Copy link
Sponsor Member Author

I think we've done a fair enough job of this for 0.1 so I'm retagging this as 0.2.

@wlbksy
Copy link
Contributor

wlbksy commented Mar 13, 2013

As there aren't much Boolean function in Julia, I think it's a good idea to make question mark as a prefix.

This would benefit people who needs autocomplete to help them remembering which Boolean function they should use, i.e., ?contains? ?empty

The parser should consider ? a "ternary operator" only when ? has space both before and after it.

@pao
Copy link
Member

pao commented Mar 13, 2013

@wlbksy that was #1910. We decided not to do that.

@JeffBezanson
Copy link
Sponsor Member

each_line and each_match have been de-underscored.

Another idea: parse_int to parseint, and remove parse_bin, parse_hex, and parse_oct. No need for special names for 3 bases.

JeffBezanson added a commit that referenced this issue Mar 16, 2013
…le_hint->precompile

un-export enq_work
rename each_line in doc
rename usleep to systemsleep (not exported)
@ViralBShah
Copy link
Member

How about renaming findn_nzs to findnz? I came up with the original name and I have hated it every single time I have to use it.

JeffBezanson added a commit that referenced this issue Apr 3, 2013
@JeffBezanson
Copy link
Sponsor Member

Go ahead. Any underscore removal is usually good.

@JeffBezanson
Copy link
Sponsor Member

I think the "policy" is resolved and now this is just normal renaming over time.

@pauljurczak
Copy link
Contributor

This is probably way too late, but I'm new to Julia: https://groups.google.com/forum/#!topic/julia-users/IvdFNaaV1qA

fredrikekre pushed a commit that referenced this issue Dec 13, 2019
…34091)

git log --oneline 0c2dddd40e4d7492d2a7337be54c345011e5f1e1^..8e236a7f993f1e732ffd0ab5c15736b2594e4109

8e236a7 (HEAD -> master, origin/master, origin/HEAD) Merge pull request #1544 from JuliaLang/sk/telemetry
90b8482 telemetry: factor out telemetry file loading
228fb97 CI telemetry: send indicators for common CI env vars
246dbd0 Pkg protocol: basic anonymous opt-out telemetry
e66a75f Introduce special REPL syntax for shared environments (#1488)
afeb1ee Merge pull request #1538 from JuliaLang/sk/pkg-client-auth
9c357bb Pkg client auth: support connecting to authenticated Pkg servers
6dd7f34 PlatformEngines: revert API part of headers support (broken)
6825b48 Merge pull request #1539 from 00vareladavid/00/fixes
3f1cf40 it is invalid to `add` a package with no commits
0766765 test: default environment should be created when the primary depot does not exist
43f46f8 check no overwrite is occuring when resolving from a project file
37b6853 handle primary depot as relative path
53fdf24 Check for duplicate name/UUID input
8a6387c Remove redundant precompile statement
4d0901e Dont throw error when autocompleting faulty input (#1530)
d69f6d7 Refactor and test `Pkg.test` (#1427)
8ca8b6d PlatformEngines: use `tar -m` to ignore mtimes (#1537)
6797928 Make sure sandbox's temp Project.toml and Manifest.toml files are writable (#1534)
f968cc9 clarify: stacked envs only affect top-level loading (#1529)
0dfef59 PlatformEngines.download: add header support (#1531)
49ab53e Fix tree hashing with nested empty directories (#1522)
0c2dddd fix #1514: install_archive call in backwards_compatible_isolation (#1517)
KristofferC pushed a commit that referenced this issue Apr 11, 2020
…34091)

git log --oneline 0c2dddd40e4d7492d2a7337be54c345011e5f1e1^..8e236a7f993f1e732ffd0ab5c15736b2594e4109

8e236a7 (HEAD -> master, origin/master, origin/HEAD) Merge pull request #1544 from JuliaLang/sk/telemetry
90b8482 telemetry: factor out telemetry file loading
228fb97 CI telemetry: send indicators for common CI env vars
246dbd0 Pkg protocol: basic anonymous opt-out telemetry
e66a75f Introduce special REPL syntax for shared environments (#1488)
afeb1ee Merge pull request #1538 from JuliaLang/sk/pkg-client-auth
9c357bb Pkg client auth: support connecting to authenticated Pkg servers
6dd7f34 PlatformEngines: revert API part of headers support (broken)
6825b48 Merge pull request #1539 from 00vareladavid/00/fixes
3f1cf40 it is invalid to `add` a package with no commits
0766765 test: default environment should be created when the primary depot does not exist
43f46f8 check no overwrite is occuring when resolving from a project file
37b6853 handle primary depot as relative path
53fdf24 Check for duplicate name/UUID input
8a6387c Remove redundant precompile statement
4d0901e Dont throw error when autocompleting faulty input (#1530)
d69f6d7 Refactor and test `Pkg.test` (#1427)
8ca8b6d PlatformEngines: use `tar -m` to ignore mtimes (#1537)
6797928 Make sure sandbox's temp Project.toml and Manifest.toml files are writable (#1534)
f968cc9 clarify: stacked envs only affect top-level loading (#1529)
0dfef59 PlatformEngines.download: add header support (#1531)
49ab53e Fix tree hashing with nested empty directories (#1522)
0c2dddd fix #1514: install_archive call in backwards_compatible_isolation (#1517)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking This change will break code decision A decision on this change is needed
Projects
None yet
Development

No branches or pull requests