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

many class attribute getters/setters are unnecessary #38

Open
jairideout opened this issue Sep 16, 2013 · 2 comments
Open

many class attribute getters/setters are unnecessary #38

jairideout opened this issue Sep 16, 2013 · 2 comments

Comments

@jairideout
Copy link
Contributor

Unlike some other OO languages (e.g., Java), a common practice in Python is to avoid adding getters and setters for each class attribute. Instead, the more Pythonic thing to do is allow users of the class to access the attributes directly. Then, if a getter/setter is truly necessary (e.g., some code must be executed before returning a class attribute), Python properties can be used instead (similar to C# properties).

As many of the classes in fresco are simple data containers, I think most of the class attributes should have their getters and setters removed, and replaced with properties where necessary. This will cut down on the verbosity/size of the code, make it easier to read, and still flexible enough to easily add getters/setters in the future if/when they become necessary.

See this SO post for more details, and the classes in this QIIME module for some examples of where this is being used.

@rybern
Copy link
Contributor

rybern commented Sep 17, 2013

Thanks for the tip, I didn't know about properties. I'll fix that when I get the chance.

@jairideout
Copy link
Contributor Author

No problem- this definitely isn't a high priority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants