Is it bad practice to have my getter method change the stored value?

I think it is actually quite a bad practice if your getter methods change the internal state of the object. To achieve the same I would suggest just returning the “N/A”. Generally speaking this internal field might be used in other places (internally) for which you don’t need to use the getter method. So in … Read more

Is it good practice to make getters and setters inline?

I don’t inline anything until a profiler has specifically told me that not inlining is resulting in a performance problem. The C++ compiler is very smart and will almost certainly automatically inline such simple function like this for you. And typically it’s smarter than you are and will do a much better job at determining … Read more

Do you use the get/set pattern (in Python)? [duplicate]

In python, you can just access the attribute directly because it is public: class MyClass: def __init__(self): self.my_attribute = 0 my_object = MyClass() my_object.my_attribute = 1 # etc. If you want to do something on access or mutation of the attribute, you can use properties: class MyClass: def __init__(self): self._my_attribute = 0 @property def my_attribute(self): … Read more

tech