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

document conventions about public vs private API #7561

Closed
ggggggggg opened this issue Jul 10, 2014 · 4 comments · Fixed by #35715
Closed

document conventions about public vs private API #7561

ggggggggg opened this issue Jul 10, 2014 · 4 comments · Fixed by #35715
Labels
docs This change adds or pertains to documentation

Comments

@ggggggggg
Copy link
Contributor

In the discussion of #1974 there seems to be an implicit consensus that accessing information via the a.b syntax is part of the "private" API, and the "public" API consists of calls like b(a). The canonical example seems to be that if a is a FloatRange object a.step is not a useful value for public purposes, where step(a) is.

Depending on how that issue is resolved the convention may change somewhat, but in either case there will be some preferred convention. That convention should be documented, and so far is not as far as I could tell. Perhaps the Types section of the manual makes sense?

@ssfrr
Copy link
Contributor

ssfrr commented Jul 11, 2014

I don't think that the "fields are private, methods are public" convention is particularly universal. I generally don't like trivial setter/getter functions. Part of the decision for me is where the type sits on the inheritance hierarchy. If it's a concrete type and field access feels natural then I use the direct access. If it's an abstract type I'm much more likely to define a method so that subtypes are free to implement the access as they choose. If I'm subtyping and the supertype already has an access method as part of its API, then I'd use that method and consider the referenced field to be private.

I do rather like the python convention of leading underscores for private fields (e.g. a._step). It's simple and clear.

@StefanKarpinski
Copy link
Member

One of the things I like about the a.b overloading proposal is that you can disable a.b easily and it's clear that a..b is truly private.

@ivarne
Copy link
Member

ivarne commented Jul 13, 2014

Wouldn't it be wildly confusing if FloatRange had fr.step and fr..step return different values. I'm starting to think that the step field should be renamed because it has a different meaning than the intuitive one. Maybe mstep or something?

@StefanKarpinski
Copy link
Member

I don't know, I think that would be fine – the fr..step is effectively private.

vtjnash pushed a commit to vtjnash/julia that referenced this issue Apr 19, 2021
vtjnash pushed a commit that referenced this issue Apr 20, 2021
Provides some guidelines, in addition to those added recently by #40533 to the style-guide, per #7561.
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this issue May 4, 2021
close JuliaLang#12064
close JuliaLang#7561

Co-authored-by: Spencer Russell <spencer.f.russell@gmail.com>
ElOceanografo pushed a commit to ElOceanografo/julia that referenced this issue May 4, 2021
Provides some guidelines, in addition to those added recently by JuliaLang#40533 to the style-guide, per JuliaLang#7561.
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this issue May 9, 2021
close JuliaLang#12064
close JuliaLang#7561

Co-authored-by: Spencer Russell <spencer.f.russell@gmail.com>
antoine-levitt pushed a commit to antoine-levitt/julia that referenced this issue May 9, 2021
Provides some guidelines, in addition to those added recently by JuliaLang#40533 to the style-guide, per JuliaLang#7561.
johanmon pushed a commit to johanmon/julia that referenced this issue Jul 5, 2021
close JuliaLang#12064
close JuliaLang#7561

Co-authored-by: Spencer Russell <spencer.f.russell@gmail.com>
johanmon pushed a commit to johanmon/julia that referenced this issue Jul 5, 2021
Provides some guidelines, in addition to those added recently by JuliaLang#40533 to the style-guide, per JuliaLang#7561.
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants