Skip to content
This repository has been archived by the owner on May 11, 2019. It is now read-only.

RFC: Visibility #19

Open
Qix- opened this issue Jun 4, 2016 · 5 comments
Open

RFC: Visibility #19

Qix- opened this issue Jun 4, 2016 · 5 comments
Labels
Projects

Comments

@Qix-
Copy link
Owner

Qix- commented Jun 4, 2016

TODO Both method visibility as well as unit visibility

@corbin-r
Copy link

corbin-r commented Sep 6, 2016

Method Visibility

Working proposal

Note: scope and visibility are synonymous in this instance

Variables, structs, enum, and type definitions placed inside of methods should only have an accessible scope/visibility from inside the enclosing method.

Methods in the same file have visibility to all other methods inside the enclosing file.

Structs, vars, enums, and type definitions placed inside the enclosing file's scope can be accessed from other files, methods, enums, and structs.

# Method scope begins here
fn someMethod()
     # Do stuff in here

     # Variable scoped to this method only
     someVar: u32 = 0

     # Outside method can be referenced here inside another methods scope.
     someOtherMethod()
# Method scope ends here at col:0


fn someOtherMethod()
    # Do some stuff

# Method scope ends here at col:0

Public/Protected/Private Visibility

A note on visibility: private until made public by pub. Don't think protected-type visibility will be necessary. Haven't decided yet. - Qix-

Public

Public is defined as accessible and/or modifiable from all scopes.

Protected

Protected is defined as accessible only the current item or sub-elements (extended or implemented)

Private

Private is defined as accessible only from the current scope [or file] or friend elements
Note: The compiler assumes all elements are declared as private until declared otherwise.

Examples:

# Public method accessible from any scope
pub fn doStuff()
    # foocode



# Private method accessible only from this current scope
# Note, no given scope declaration, assumed: Private
fn doThings()
    # foocode



# Protected method accessible only via derivative elements or current element
prot fn doFoobar()
    # Protected foo  code

@Qix-
Copy link
Owner Author

Qix- commented Sep 6, 2016

A note on visibility: private until made public by pub. Don't think protected-type visibility will be nexessary. Haven't decided yet.

@Qix-
Copy link
Owner Author

Qix- commented Sep 15, 2016

Looks okay for the moment @PolyGN. I think prot will have to be re-evaluated once traits get fleshed out.

@corbin-r
Copy link

corbin-r commented Sep 15, 2016

@Qix- sweet!
And yeah, prot was just a kind of "on the spot" idea. Figured it'll get fleshed out once traits have been written.

On a side note, I'm writing the RFC for potentiality of preprocessor commands and macros in Arua. I've got it in a text file and will just copy'paste when done.

Preprocessor commands and macros not going to be implemented

@corbin-r
Copy link

Thought on protected...
After doing some digging into a thesaurus... Some synonyms we could use for protected could be:

   guarded
   guard
   preserve

Note! guard in this instance does not have synonymous function to Swift's implementation of guard

Or maybe we use symbol implementations... I'm against this in my opinion as symbolic parsing of visibility could prove to be troublesome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
RFCs
Proposed
Development

No branches or pull requests

2 participants