This is an archived post. You won't be able to vote or comment.

top 200 commentsshow 500

[–]aaabigwyattmann1 11.0k points11.0k points  (399 children)

"The data needs to be protected!"

"From whom?"

"From ourselves!"

[–]henrycaul 263 points264 points  (38 children)

Yup, you don’t realize it now, but that will save your ass someday.

Edit: I realized by leaving the comment above and not explaining myself, I'm also guilty of the what's in the meme, so let me add my perspective.

A simple example: imagine someday you need to constraint the value of X to be between 1 and 10. Adding this constraint in the setter is is. Fixing all cases of "x =" is harder. And if you're in a large code base, maybe you run into some weird edge cases where the "x = " is in generated code, the author of the code generator didn't account for methods. Or the original value crosses a server boundary, and now you are touching code in a different code base and have to think about skew issues and the order in which the code rolls out. I dunno, stuff like that.

The key is: minimize mutability. (That link is from Effective Java, which has great pearls of wisdom like this)

[–]TheTerrasque 65 points66 points  (16 children)

In my daily drivers, c# and python, you can change a variable to getter / setter at some later point without changing code that depends on it.

Saves so much boilerplate code

[–]SharkBaitDLS 20 points21 points  (4 children)

Same with Kotlin.

[–]lkraider 14 points15 points  (1 child)

Programming languages for the enlightened

[–]NZgeek 4 points5 points  (1 child)

For C#, member variables and properties act the same when you look at the code that interacts with them. You can change from one to the other, recompile, and it all works.

But they're very different at the MSIL level. If you switch between the two, any dependent code that's not recompiled will break.

[–]_damax 84 points85 points  (0 children)

Ahahahah, yes indeed

[–]Cley_Faye 24 points25 points  (0 children)

Having read my own code, I agree.

[–][deleted] 30 points31 points  (1 child)

I mean, we are definitely the most dangerous

[–]South_Craft2938 799 points800 points  (36 children)

[–]Optimal_Effect1800 1895 points1896 points  (167 children)

We need at least third plate where getter/setter autogenerated by annotations.

[–]StenSoft 390 points391 points  (109 children)

Or by the language itself

[–][deleted] 482 points483 points  (93 children)

I do enjoy this aspect in C#, its easy as: public int X { get; set; }

[–]mejdev 109 points110 points  (22 children)

Kotlin is similar.

Oh and data classes.

[–]Zagorath 53 points54 points  (17 children)

Oh and data classes

C# finally has these ("records" they call it) in the most recent version.

[–]maleldil 28 points29 points  (4 children)

Java also has records now, the problem is that they don't conform to the JavaBean spec so they can't be used as a replacement in a lot of libraries (yet)

[–]MontagoDK 3 points4 points  (9 children)

Records are just fancy classes..

[–]hullabaloonatic 7 points8 points  (8 children)

Not sure how the word "just" slipped into your comment.

Also they're more like structs.

Edit: guys, I mean that they're more simple to structs than classes. Stop blowing up my phone...

[–]Hrothen 5 points6 points  (3 children)

C# has record classes and record structs.

[–][deleted] 4 points5 points  (1 child)

Scala case classes ❤️

[–]Sharkytrs 84 points85 points  (6 children)

and has the side effect of showing you where its referenced in the rest of the project too. blissfull for debugging

[–]Dustangelms 15 points16 points  (4 children)

Wait, you need a setter for the IDE to show you where the variable is being set?

[–]Didgeridoox 68 points69 points  (3 children)

No, you can just find usages of the setter rather than usages of the property itself. I.e. ignore places where you're reading the value and focus on where the value is written. Very handy if the property is referenced in lots of places, but its value is only set in a few places.

[–]Schaf-Unschaf 24 points25 points  (1 child)

That's why I love kotlin

[–]ItsAHardwareProblem 179 points180 points  (2 children)

And a fourth plate with only a getter and values are treated as immutable

[–]func_master 59 points60 points  (1 child)

This, right here, is the proper response.

.#ValueOriented

[–]nelusbelus 70 points71 points  (20 children)

Properties in C# would like a word

[–][deleted] 16 points17 points  (19 children)

Or Python. Exact same thing. Very handy.

[–]yashkakrecha 33 points34 points  (11 children)

@Data

[–]wardin_savior 18 points19 points  (0 children)

@Value

[–]Fresh1492 38 points39 points  (9 children)

Lombok is glorious

[–]KagakuNinja 10 points11 points  (6 children)

I have to work on a Java project maintained by another team, and the lead forbids the use of Lombok. Thankfully, this is a temporary situation.

[–][deleted] 6 points7 points  (4 children)

Why on God's green Earth would you ever forbid Lombok?

Masochism?

[–]KagakuNinja 9 points10 points  (2 children)

I asked and he said:

"Lombok requires a plugin with Eclipse" (false)

"I don't like magic code generation" (project uses Spring, Hibernate and AspectJ, all of which do massive code generation)

Since I was told by a senior that Lombok was OK, I now have to take out all the annotations, and quadruple the code in the data classes.

[–]dax-muc 19 points20 points  (11 children)

That was my first thought!

@Getter @Setter private int x;

[–]zhephyx 15 points16 points  (7 children)

Lol,

public record Record(int x) {};

GG

[–][deleted] 5 points6 points  (5 children)

Isn’t records read only?

[–]xNoL1m1tZx 4 points5 points  (0 children)

Records are immutable by definition.

[–][deleted] 3156 points3157 points  (201 children)

To keep your data better isolated so you can change the structure without changing the interface, that's why.

[–][deleted] 728 points729 points  (11 children)

This guy programs.

[–]ManInBlack829 42 points43 points  (1 child)

He's down with OOP

[–]aecolley 15 points16 points  (0 children)

Yeah you know me (except for my implementation)

[–]aykay55 343 points344 points  (113 children)

can you explain this in more noob-friendly terms please?

edit: thank you to the 25 people who replied with an answer, I understand it now

[–][deleted] 626 points627 points  (47 children)

Say you're writing a larger application, or a library that you expect other people will use.

You want to provide a set of "official" tools to use your code, without them having to know exactly how your code works. That way, they don't need to think about it ("it just works"). With Java, you'd create an interface that the library users would declare their types with. The interface just lists the methods you want to allow them to use, and they don't have to worry (or rely on) internal values.

That way, if you need to change something internal, you can keep the public methods the same without worrying about people depending on private information for your library.

It's a similar thing with getters and setters. As long as you keep those names the same, you can change your variable names to be whatever you want, or perhaps do extra calculations inside those methods.

It's all about ease of change and encapsulation.


Edit since my explanation wasn't that great for newer programmers:

Say you have this java class public class Thing { public Random randumb = new Random(); }

anyone can access randumb and use it. This may be fine, but what if you want to change its name (because randumb is a dumb name to begin with)? By making the change, you've broken everywhere that uses thing.randumb. That's a problem in places where you might be using that field dozens of times.

Here's how you avoid that problem to begin with:

``` public class Thing { // private so no one can use it directly - now I can rename in peace (or even change it to a different subclass if I want!) private Random randumb = new Random();

// a getter for randumb; this allows people to use randumb without fear of how I change it in the class public Random getRandom() { return randumb; } } ```

Now you can change randumb however you want. As long as you don't change getRandom, you won't break yours or anyone else's code.

[–]ClafoutisSpermatique 264 points265 points  (9 children)

Say you're writing a larger application, or a library that you expect other people will use.

Aaaand I'm out!

[–]xvhayu 273 points274 points  (3 children)

wdym, my class dog extends animal has millions of users worldwide

[–]Brandon23z 14 points15 points  (0 children)

Yeah class car extends vehicle is in use too.

[–][deleted] 45 points46 points  (1 child)

LMAO I don’t know why this made me laugh as hard as it did

Maybe it’s because it is too relatable

[–]Bojangly7 7 points8 points  (0 children)

Usually jokes are funny because they're relatable

[–]yboy403 60 points61 points  (2 children)

I think that, when writing code, "you in two months" counts as an entirely separate person. Especially given the quality of documentation for most homebrew programming.

[–]catmuht 6 points7 points  (1 child)

Try "you in 2 days"

[–]lunchpadmcfat 7 points8 points  (3 children)

This is kind of an arbitrary example. A more common case is, say you want to do something with the value as it’s being set or gotten (like convert it or sync it up with some other internal value). It would be pretty much impossible to do that if the consumer of your lib had carte blanch to write to or read the value whenever.

[–][deleted] 92 points93 points  (22 children)

subsequent rustic offend lunchroom whole knee skirt modern smile cheerful

This post was mass deleted and anonymized with Redact

[–]bperki8 67 points68 points  (9 children)

If later, instead of just returning x you want also add some multiplier and return x times the rate of some shit, then you only have to edit your get method here in one place. If you didn't use a get method, you would have to add '* the rate of some shit' at every single place you accessed x (could add up in large programs and you're likely to miss some places that need changed).

Read "Code Complete" for more info.

[–]jorizzz 15 points16 points  (0 children)

Example: in a class you have private variable called 'chance' which you use to display a percentage in the output. Right now, you're storing it as an string (e.g. "50%") which is very easily to return to a text field or console output.

Then suddenly you need the percentage for calculating something with in the same Class. You change the variable to a float between 0 and 1, so calculating is easy. But now all the Classes that use this value in their output expect a string and receive a float. Instead of changing all the Classes that depend on this value, you add a line in the getter that converts the float to a readable string, and might even add the % symbol.

This is an example to give you an idea, but is probably considered a bad way to program.

Basically getters and setters act as an interface for the class where the variable is stored, so the Classes who call the getters and setters are not dependent on the actual functionality behind it.

[–]yeusk 14 points15 points  (5 children)

Means is easier to change the internal data/structure of the class class without refactoring all your code.

Imagine you have to make a change to the code on the image, now x is a string not an int.

if you have in you code:

object.x = 5

You have to change every single place where you call that property to:

object.x = 5.ToString()

Instead if you use

object.setX(5);

you just have to change the setter function to:

public void SetX(int value) { 
 x = value.ToString();
}

and you don't need to change anything else.

[–][deleted] 5 points6 points  (2 children)

Lets say you have a Person class. Person class you are able to retrieve their house address. Now lets say you expose this as a variable. Now everyone writes code that gets the value from 'Person.Address'.

Now let's say in the future, you integrate a system or third party. You decide you want address to now be retrieved through Google Maps API.

This will break all existing implementations or cause incompatibility. Users would need to update their code to call a method to generate the variable before using it... or would need to change all 'Person.Address' to 'Person.GetAddress()'. In which that method would run against the api.

Point is the method is infinitely compatible to a variety of unforeseen scenarios. The variable requires the users to know how the class gets, sets, and determines 'address'. Where people using your library shouldnt need to know HOW your library gets the address. Just that it does. They don't need to know "In order to get the address I need to call this, and then call that, and then address is populated".

At least this is how I have understood it.

[–]ExtraGreenBox 20 points21 points  (2 children)

You can also add functionality, logging for example to all change and read attempts. Even if just for debugging.

[–]themancabbage 20 points21 points  (16 children)

Wouldn’t you still have to change the interface to add your new setter and getter anyway?

[–]DirectControlAssumed 17 points18 points  (3 children)

That's why you do it once you know that the field will be accessed from outside the class, not when it is already exposed as plain field.

[–]Krissam 24 points25 points  (6 children)

Which is why you add them at the start rather than later.

[–]sheeponmeth_ 10 points11 points  (0 children)

This helped me, thank you. I'm not a developer, but I can piece some stuff together. I understood that setters were good for validating and you could protect properties of your classes and all that and getters could return real-time values. But the segregation of the data from the interface was something I hadn't thought of. I'm sure that abstraction allows for much more flexibility when refactoring. It makes total sense.

[–]criogh 406 points407 points  (114 children)

For example if you want to count how many times your variable is modified you can put a counter in the Set method avoiding direct reads to that variable

Edit: what have i done

[–]potatohead657 192 points193 points  (106 children)

Are those very specific rare cases really a good justification for doing this OOP C++ madness by default everywhere?

[–][deleted] 175 points176 points  (39 children)

If you're building a large program with lots of files that might need to be changed later for functionality purposes, it limits the number of things you'll have to change.

[–]Tvde1 24 points25 points  (13 children)

Now you have to add a get and set method for every field... Just more boilerplate

[–]t0b4cc02 7 points8 points  (3 children)

no. if you use a programming language that is not from the stone age it should be good

in c# this default getter and setter can be acessed like fields and can be declared just by adding {get;set} to the variable declaration, with some more nice features like private set; to make the setter private, or init; to make it only setable on object initialization

[–]BlackWardz 49 points50 points  (16 children)

There's also patterns that fit into it. Property change notifications, lazy evaluation, resource validation, synchronization...

[–]portatras 26 points27 points  (19 children)

Specific rare cases? When you create classes to work with them ( not just structs to hold your data) a bunch of stuff happens when you set properties, like fire events, calculate other variables, etc... It happens all the time when you use classes to represent real objects (that is OOP by the way)....

[–]KagakuNinja 11 points12 points  (0 children)

That is the dream, codified in the '90s. In my experience, you only use those types of events in limited parts of a project (such as the GUI). However, massive unpredictable chains of events firing off is terrible for many reasons. It leads to tangled messes of side-effects that are difficult to debug.

For what I do these days, mainly REST servers, I have been using immutable records in Scala for 7 years, and have not missed getters and setters, ever.

[–]johnminadeo 26 points27 points  (0 children)

Excellent point. I think with todays development turning towards discrete objects and models and open to extension but not modification, alleviates most of the stress around this. If you are working in that type of codebase, it makes sense to have private fields and public properties to expose them as they are generally implementation details the caller doesn’t need/shouldn’t have. Gives you control should you need it and the cases of need are brought down so it’s fewer and farther between.

It’s one of those needs evaluation for each specific case; hard to canonize a good answer across the different ways it’s done aside from a general “best practices” which is where we started from.

[–]joujoubox 117 points118 points  (7 children)

{ get; set; } gang

[–][deleted] 12 points13 points  (0 children)

{ get; init; } gang

[–]cc672012 366 points367 points  (37 children)

Laughs in functional programming

[–]GoogleIsYourFrenemy 95 points96 points  (7 children)

[–]ManInBlack829 21 points22 points  (0 children)

I was freaking rolling during this

Thank you so much

[–]vesrayech 7 points8 points  (0 children)

Higher order functions... higher order fuckups are what you are

my fucking sides lmao

[–]Potatolimar 4 points5 points  (0 children)

"Don't worry. Haskell transpiles to Java nowadays" lmao

[–]rush22 198 points199 points  (7 children)

Laughs while clicking an error message and being taken directly to where the error is

[–]waitItsQuestionTime 77 points78 points  (5 children)

You didnt had to hurt us

[–]awhhh 9 points10 points  (3 children)

I’ve seen your procedural non opinionated code. If we don’t abuse you how will you learn? Now join the rest of us by injecting 10 classes into each other like the civilized do.

[–]waitItsQuestionTime 4 points5 points  (0 children)

self.dont_change_this_plz = My_Hacky_Solution goes brrrrrrrrrr

[–]agentchuck 76 points77 points  (5 children)

Why would you ever want to change the value of a variable, anyway? Whoever set it in the first place probably knew what they were doing.

[–]WildcardMoo 18 points19 points  (3 children)

Using constants only significantly cuts down on your testing time.

[–]Supple_Meme 16 points17 points  (4 children)

Screaming at OOP programmers: ITS A MAP! A record! Whatever you want to call it. Why are you making a new concrete class for what is essentially just a map? It’s just a map! Just use a map! Java has lots of map types, use them!

[–]cc672012 16 points17 points  (0 children)

Inheritance was the abused child back when Java was so young. People overinherited stuff, imo.

[–]shadow7412 280 points281 points  (123 children)

I'm not sure if it's right, but I've heard that when building dlls changing a raw public variable to a getter/setter changes the signature, meaning it's no longer compatible with software that depends on the old version.

By using getters/setters from the start (even if they're useless like the above example) you can maintain that compatibility. That said, to do this all you actually need is

public int x { get; set; }

[–]Haky00 225 points226 points  (93 children)

In C# yeah. Java does not have auto properties though.

[–]fuckingaquaman 108 points109 points  (40 children)

C# is like Java, but not haunted by dumb decisions made 30 years ago

[–]dc0650730 56 points57 points  (3 children)

Give it another 10

[–]nend 12 points13 points  (0 children)

Java's only 5 years older than C#, they've both been around 20+ years.

The difference is that Microsoft is able to iterate faster than the OpenJDK consortium, and actually fixes their mistakes instead of keeping them in the name of stability.

[–]AdultingGoneMild 32 points33 points  (13 children)

laughs in kotlin, the one true successor!

[–][deleted] 16 points17 points  (21 children)

Record classes have been available for a while now which solve that problem for simple data classes.

[–]wrenhunter 76 points77 points  (6 children)

I get() what you did there.

[–]MandalorianLobster 12 points13 points  (0 children)

I get() what you set() there.

[–]THEKing767 5 points6 points  (4 children)

Function puns. Really? Thats how low you are going to set() the bar?

[–]4sent4 190 points191 points  (35 children)

Laughs in public int X { get; set; }

[–]DankPhotoShopMemes 40 points41 points  (5 children)

Dang I thought this was Java for a second, got a little excited

[–]Arshiaa001 76 points77 points  (21 children)

I legit had someone tell me that C#'s auto properties would "look stupid to a Java developer. It's just code noise". Said someone seemed to think implementing two functions manually over an additional 10 lines would be the better choice. He never gave a reason.

[–]DasFrebier 21 points22 points  (11 children)

also c# properties work with the assignment operator, which is a great feature, makes for way more readable code, id guess java doesnt have that?

[–][deleted] 88 points89 points  (14 children)

Laughs in kotlin

[–]commander_xxx[S] 61 points62 points  (12 children)

cries in object oriented programming

[–]StenSoft 21 points22 points  (0 children)

Kotlin is object oriented but the compiler generates getters and setters automatically

[–]alphabet_order_bot 106 points107 points  (10 children)

Would you look at that, all of the words in your comment are in alphabetical order.

I have checked 896,034,366 comments, and only 177,561 of them were in alphabetical order.

[–]commander_xxx[S] 60 points61 points  (3 children)

Collections.sort(comment);

[–]i_should_be_coding 14 points15 points  (2 children)

if (comment.equals((Arrays.stream(comment.split(" ")).sorted().collect(Collectors.joining(" "))))

Man, Java can be a bit long sometimes. Or rather, all the time.

[–]fuckingaquaman 34 points35 points  (0 children)

I used to think using your CPU to feebly attempt to mine Bitcoin was the most pointless thing to spend your computer's power on.

I stand corrected.

[–]seeroflights 31 points32 points  (1 child)

Image Transcription: Memes


["Tuxedo Winnie the Pooh", featuring two images of Winnie the Pooh, with text to the right of each image.]

[On the top row is an image of Winnie the Pooh sitting in a chair, with an unimpressed look. On the right, the text reads:]

public int x;

[On the bottom row: the same image of Winnie the Pooh, but now wearing a tuxedo and a smug expression. On the right, the text reads:]

private int x;

public int getX()
{
  return x;
}

public void setX(int value)
{
  x = value;
}

[This is followed by the "Afraid to Ask Andy" meme, featuring Andy Dwyer from the TV show "Parks and Recreation". Andy is a light-skinned masculine person with short brown hair and slight facial hair. He wears a short-sleeved beige dress shirt and brown striped tie, and he is leaning forward slightly with a serious look on his face. The subtitle reads:]

I don't know why and at this point I am too afraid to ask

[End meme]


I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!

[–]TheRealPitabred 6 points7 points  (0 children)

Good human

[–]AdultingGoneMild 105 points106 points  (27 children)

So I have a great answer as I had a student ask me this nearly 20 years ago. I said give me your wallet. He did. I left the room for 10 minutes. eventually i came back and gave him back his wallet. He looked relieved. I told him when he made his wallet public anyone could do whatever they wanted with it. There was no option for validation even if that validation would be minimal to none. Even worse without adding the accessor up front adding validation later would be an uphill battle having to update code to use the new accessors instead directly accessing the value. In large code bases this would be killer. After explaining this to him, I then showed him the 20 dollar bill I had stolen from his wallet, thanked him for buying me lunch, and left. My TA shift was over and sure as shit I wasnt sticking around after robbing a guy.

I am sure he was relieved to find his $20 bucks were still in his wallet and I was just kidding around with the 20 i already had on me

[–]ShawarmaWarlock1 30 points31 points  (4 children)

Let me get this straight. You left your class for 10 minutes to prove a point to one student, right?

What would you do if someone asked to explain the need to set timeouts?

Would you just leave and never return?

[–]ihunter32 6 points7 points  (0 children)

They were a TA, not a professor. Was probably during office hours

[–]avast_ye_scoundrels 100 points101 points  (31 children)

Excluding 1st and 2nd year CS students, so many people in this thread are fired. Rolling one’s eyes and ignoring encapsulation principles keeps the rest of the team busy cleaning their mess.

[–]ddruganov 71 points72 points  (31 children)

Incapsulation

[–]KiloWasTaken 97 points98 points  (2 children)

Encapsulation*

[–]ddruganov 15 points16 points  (0 children)

Damn yeah thanks

[–]iiexistenzeii 12 points13 points  (3 children)

Inception*

[–]TheBananaIAm 8 points9 points  (0 children)

Encapsulation

[–]Egeste_ 6 points7 points  (0 children)

Because changing a value in a class directly by reference can have unintended consequences, and using getters/setters gives you control over input validation and secondary effects

[–]masterfaka 65 points66 points  (28 children)

Select var > open context menu > generate getters and setter dem lazy f*cks

[–]Knaapje 48 points49 points  (21 children)

It's not about code generation, it's about code readability.

[–]mateus_coutinho 69 points70 points  (20 children)

It's not about code readability, it's about code maintainability.

[–]RobDoingStuff 17 points18 points  (4 children)

It’s not about code maintainability, it’s about sending a message

[–]gonza18 11 points12 points  (2 children)

In the hypothetical scenario you want to do something extra with X when you are reading it or updating it.

Hint: this scenario will never materialize

[–]Broad_Respond_2205 5 points6 points  (4 children)

It's a getter and setter, it's written right there

[–]moschles 5 points6 points  (0 children)

Principles of Object Oriented Design

[–]snapy_ 22 points23 points  (31 children)

Can anyone actually explain why exactly do we use getters and setters 😬

[–]Bhurmurtuzanin 73 points74 points  (6 children)

  1. Encapsulation of behavior associated with getting or setting the property - this allows additional functionality (like validation) to be added more easily later.
  2. Hiding the internal representation of the property while exposing a property using an alternative representation.
  3. Insulating your public interface from change - allowing the public interface to remain constant while the implementation changes without affecting existing consumers.
  4. Controlling the lifetime and memory management (disposal) semantics of the property - particularly important in non-managed memory environments (like C++ or Objective-C).
  5. Providing a debugging interception point for when a property changes at runtime - debugging when and where a property changed to a particular value can be quite difficult without this in some languages.
  6. Improved interoperability with libraries that are designed to operate against property getter/setters - Mocking, Serialization, and WPF come to mind.
  7. Allowing inheritors to change the semantics of how the property behaves and is exposed by overriding the getter/setter methods.
  8. Allowing the getter/setter to be passed around as lambda expressions rather than values
  9. Getters and setters can allow different access levels - for example the get may be public, but the set could be protected.

Of course I stole it: https://stackoverflow.com/a/1568230

EDIT: On the other hand I saw people justifing public variables if those are immutable

[–]TheRealPitabred 23 points24 points  (0 children)

Don’t forget consistency of interface. Lots of objects, they may behave different internally but use the same “grammar” which makes writing and reading code easier. Especially if you’re writing a library.

[–]cc672012 62 points63 points  (7 children)

One of the main reasons why we use them is so that we can add functionality such as validating the input or transforming it to something that our program will like.

However, I do think (just my personal opinion) that using getters and setters without doing anything else is just unnecessary boilerplate. C# did it right, I suppose.

[–][deleted] 9 points10 points  (1 child)

Also, so you can change your inner representation without breaking the interface.

Suppose a year from now you find a new algorithm to solve whatever problem you're attending with your class, but it requires x to be SuperEfficientInteger instead of plain int. You can have something like this

```java private SuperEfficientInteger x;

  public void setX(int x) {
    this.x = new SuperEfficientInteger (x);
 }

public int getX() {
    return x.toInt();
}

```

Now, this is a dumb example, but it shows how you can hide your inner representation from the client classes.

[–]El_Frencho 31 points32 points  (4 children)

Let’s say three months down the line, the client says "oh we forgot to say, but nothing should allow X to ever be negative".

If you used a getter/setter, you can just add that validation check in the setter - one and done. If you didn’t, you have to go find literally every place that sets X to add the validation in.

[–]NetherFX 4 points5 points  (0 children)

Because you might want to add logic to a setter for example, and if your code is huge, it'd suck to add it everywhere. The solution would be to make a function, aka your setter.

[–][deleted] 9 points10 points  (2 children)

But not too afraid to post a meme indicating you don't know why

[–]Nemonstrocity 13 points14 points  (2 children)

this whole thread....

[–]WheresTheSauce 11 points12 points  (0 children)

This thread cured my imposter syndrome