Jan-11-2019, 04:04 AM
(Jan-10-2019, 10:10 PM)sneakyimp Wrote: In my experience, if you don't want someone changing the properties/attributes of an object, you make them private. Conversely, it seem super tedious and unnecessary to create a get & set method when you don't apply any restrictions. This is really the essence of my question. Why create all those trivial get/set functions if you don't have to?You don't as getters/setters make no sense in Python,if you don't have damn good reason other wise not.
Python Is Not Java say it clear.
Quote:Getters and setters are evil. Evil, evil, I say! Python objects are not Java beans.
Do not write getters and setters. This is what the 'property' built-in is for.
And do not take that to mean that you should write getters and setters, and then wrap them in 'property'.
That means that until you prove that you need anything more than a simple attribute access, don't write getters and setters.
They are a waste of CPU time, but more important, they are a waste of programmer time.
Not just for the people writing the code and tests, but for the people who have to read and understand them as well.