Hi guys
Been trying to get serious with python over the last few days and Ive have not seen a lot of get and set methods used in most of the code example.
So my question is do you find get and set methods all that useful in python and not necessarily methods prefixed with get but just using methods to access and manipulate class variables instead of directly.
I know this is more a matter of personal preference and productive code can be achieved with or without these methods I'm just trying to see what the general python practices are
Do you use get/set method in python
Started by solartic, Jul 05 2010 06:31 PM
4 replies to this topic
#1
Posted 05 July 2010 - 06:31 PM
|
|
|
#2
Posted 08 July 2010 - 08:26 AM
well if you are programming a quick script that will do some quick job for you then you will probably not use get and set, or classes for that matter, but if you are going to be in a programming team, and be in charge of a piece of a application, then yes of course you will use set , get and classes
actually it all depends on the buyers demands (very rarely will that happen ), but generally you will be using that, as in all the languages that are OO ( object oriented )
actually it all depends on the buyers demands (very rarely will that happen ), but generally you will be using that, as in all the languages that are OO ( object oriented )
#3
Posted 08 July 2010 - 05:54 PM
Thanks for your input ferovac, very helpfull
#4
Posted 13 July 2010 - 01:24 PM
It isn't overly used in Python, but there's something extremely powerful in Python which renders the "direct" access(C.foo instead of C.getFoo()) of member variables to be "secure" in a way.
They're called properties, when you write C.foo, it won't just return C.foo, it'll call a function you choose, like C.getFoo(), but transparently.
Here's a nice example: The Python Property Builtin
Then again, as in any OO language, it's a good practice.
But in Python, I think, things like properties are better because it allows things to be done in the background, so that the end-user is not annoyed.
As for usage and general Python practices, I think most people don't use it because it's often not essential and Python code is often meant to be written rapidly rather than thoroughly.
They're called properties, when you write C.foo, it won't just return C.foo, it'll call a function you choose, like C.getFoo(), but transparently.
Here's a nice example: The Python Property Builtin
Then again, as in any OO language, it's a good practice.
But in Python, I think, things like properties are better because it allows things to be done in the background, so that the end-user is not annoyed.
As for usage and general Python practices, I think most people don't use it because it's often not essential and Python code is often meant to be written rapidly rather than thoroughly.
#5
Posted 13 July 2010 - 06:37 PM
Thanks manux, I do agree its good practice but sometime they just seem to be more of an annoyance that anything. I actually tried property() over the weekend and I like it a lot, it make it easier to access class variables for me personally and you still have your method ready and waiting if you ever feel like switching. oh and thank for the link


Sign In
Create Account


Back to top









