clemente-lab / fresco

Other
1 stars 2 forks source link

many class attribute getters/setters are unnecessary #38

Open jairideout opened 11 years ago

jairideout commented 11 years ago

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 commented 11 years ago

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

jairideout commented 11 years ago

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