Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Getters and setters: pythonic?

  • 05-03-2010 3:04pm
    #1
    Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭


    From what I've been reading online they're consider wrong in the older articles. However, with the property() function getters and setters can be hidden behind an attribute. This imho is a good thing however I'm new to python and have had to adopt new ways of looking at code.

    The reason I think they're good is that any additional work that may be required on a attribute can be done under the bonnet so to speak which leads to good encapsulation. But what do other's think? Is it still not considered pythonic?


Comments

  • Registered Users, Registered Users 2 Posts: 134 ✭✭anton


    I suppose it depends on the task, personally I wouldn't use them too often, just for a sake of redability - seeing something like x.a = b hints it's (usually) a simple assignment withn no side effects.

    There are however, cases where customized atribute access is essential, all sorts of proxy objects - in ORMs, remote object wrappers and so on.

    So use them if you need to, but not simply because they are there.
    Evil Phil wrote: »
    From what I've been reading online they're consider wrong in the older articles. However, with the property() function getters and setters can be hidden behind an attribute. This imho is a good thing however I'm new to python and have had to adopt new ways of looking at code.

    The reason I think they're good is that any additional work that may be required on a attribute can be done under the bonnet so to speak which leads to good encapsulation. But what do other's think? Is it still not considered pythonic?


  • Registered Users, Registered Users 2 Posts: 7,468 ✭✭✭Evil Phil


    I'm using them in a very specific case, everything else I'm doing normally.


Advertisement