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

instance fields have getters by default #1

Closed
dragoncoder047 opened this issue Dec 31, 2022 · 2 comments
Closed

instance fields have getters by default #1

dragoncoder047 opened this issue Dec 31, 2022 · 2 comments

Comments

@dragoncoder047
Copy link

agate/examples/logo.agate

Lines 166 to 168 in 9a2f4fc

x { @x }
y { @y }
z { @z }

Making instance fields have these style of getters by default would eliminate these kinds of lines.

To allow the getters to not automatically be added you could define some sort of naming rule for "private" fields -- Python uses __name.

does this sound like a good idea?

@jube
Copy link
Contributor

jube commented Jan 1, 2023

does this sound like a good idea?

It's not a good or a bad idea, it's a design choice. I prefer the current state for the following reason: encapsulation is stronger and if you want to expose a field, you have to opt in and write a getter. Making all fields public by default would be exactly the contrary, you would have to propose something to opt out (naming rule, keyword or something else).

At one point, I thought about introducing something like attr_reader/attr_writer/attr_accessor from Ruby. But in the end, writing x { @x } is shorter and more explicit than attr_reader x.

@dragoncoder047
Copy link
Author

Okay, then. Never mind...

@dragoncoder047 dragoncoder047 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 1, 2023
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

No branches or pull requests

2 participants