Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I mean it's only dumb IF both getter and setter of the same member contain bare boilerplate. Like in cases where programmer tries to mimic access control in a language that was not designed for it.
Yes, *that* is dumb. -
@aviophile Yeah I get your point, but I have mainly seen their benefit in 1) inheritance and 2) enforcing the private member OOP design. Otherwise people will just make members public Willy-Nilly and most of us know how that can go. (I guess this is only applicable to languages that are setup for good ol OOP)
-
Jedidja10053ywell I'm literally just sitting in front of a:
std::string getSomethingSomethingSomethingErrorMsg()
{
return "error"
}
is this bad? -
8lall01943y@arcioneo @phat-lasagna what' the point of having a private member with a simple get() {return $this->mem} and set($mem){$this->$mem = $mem} when making It public does exactly the same thing.
-
Depends on the language I guess.
But still, if you have a complex get/setter, it's probably doing too much. -
But now serious question, as I read about this in the Google code styleguide.
What if the private object is set within the class (multiple times during the runtime), so it's reference may change and you don't want it to be set from outside?
So private prop, get prop() with a simple return, but no set.
Allowed? If no, what's the suggested design for this? -
@phat-lasagna if it is going to be public, just ignore getter. I have never seen public attribute had to have public getter method down in inheritance line. Also, inheritance is overrated and is not necessarily part of oop.
-
ars140813y@PonySlaystation this is giving me flashbacks to the shit project that had hundreds of lines in getters.
-
@PonySlaystation justification of reuse of code is extremely contextual and heavily overblown. When we were in university, it was also advertised as part of core oop which is a lie. Compositionis almost always better anyways.
-
They even teach these shit practices in uni:
Always make getters and setters for class members.
Always write 10 lines of doc comment for each single method, explaining every single parameter and return value
Always make a subclass if you want to reuse code.
😣
Related Rants
If you find a programmer that uses getters() and setters() without any complex logic inside them, you should burn him/her/whatev with the strength of a thousand suns.
rant
oop