python_api icon indicating copy to clipboard operation
python_api copied to clipboard

setter methods in various code

Open zopyx opened this issue 9 years ago • 2 comments

Looking at examples/create_forest.py

The tons of set_xxx() methods are completely superfluous and unpythonic. Why don't you just use

create.some_property = value

directly instead of usinger setter methods? Python is not Java!

zopyx avatar Feb 16 '16 14:02 zopyx

Interesting. Are they really a python antipattern?

If one wants to have validation when necessary and consistency, it seemed like they were necessary.

ndw avatar Jun 14 '16 15:06 ndw

setter/getter methods are the anti-pattern #1. No offense but this anti-pattern is often seen by code written by people from the Java world. We call that "unpythonic".

Regarding validation: I would pass the result from parse_args() to a dedicated validation method performing the validation of all parameters. Or you look into a higher-level module 'click' http://click.pocoo.org/5/ for having parameter types or hooks for validation. 'click' is not part of the Python core but you are already using external dependencies like 'requests'...so further deps should not be a big problem.

zopyx avatar Jun 15 '16 05:06 zopyx