Python Forum
when to make attributes private?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
when to make attributes private?
#5
(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.
Reply


Messages In This Thread
when to make attributes private? - by sneakyimp - Jan-10-2019, 01:08 AM
RE: when to make attributes private? - by stullis - Jan-10-2019, 02:48 AM
RE: when to make attributes private? - by sneakyimp - Jan-10-2019, 10:10 PM
RE: when to make attributes private? - by snippsat - Jan-11-2019, 04:04 AM
RE: when to make attributes private? - by snippsat - Jan-11-2019, 06:11 PM
RE: when to make attributes private? - by snippsat - Jan-11-2019, 07:13 PM
RE: when to make attributes private? - by nilamo - Jan-11-2019, 07:13 PM
RE: when to make attributes private? - by sneakyimp - Jan-21-2019, 02:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Lint and private var names PatM 1 748 Dec-15-2022, 05:08 PM
Last Post: deanhystad
  Unable to import Private Repo using setup.py Bob786 1 1,806 Sep-02-2021, 04:19 PM
Last Post: snippsat
  python 3 dns lookup private domain didact 1 2,655 Sep-19-2020, 06:01 PM
Last Post: bowlofred
  [split] Помощь по приватным ключам/Private key help sairam17519 0 1,651 Sep-07-2020, 12:55 PM
Last Post: sairam17519
  Download file from Private GitHub rep vinuvt 0 2,042 Jul-27-2020, 11:38 AM
Last Post: vinuvt
  Private package distribution abomination disadvantages research andreir 2 2,232 May-07-2020, 12:32 AM
Last Post: andreir
  Помощь по приватным ключам/Private key help vlrubl777 5 6,139 Mar-15-2019, 08:16 PM
Last Post: vlrubl777
  Fetching private ip address from instances of an autoscaling group deepsonune 0 3,339 May-18-2018, 10:32 AM
Last Post: deepsonune
  Inheritance private attributes vaison 5 13,067 May-03-2018, 09:22 AM
Last Post: vaison
  Can access class private variable? Michael 2 7,244 Aug-11-2017, 01:59 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020