Post

@CodeRed_dev Over the years I've been reviewing what patterns work and which didn't.
I believe in most cases you're better of starting with simply:
private int _x;
Only if you need to use something externally: add accessors
1/2
English

@CodeRed_dev private int balance;
public void setBalance(int value)
{
if(value < 0) balance = 0;
else balance = value;
}
English

@CodeRed_dev Because not everybody should have access to your privates. But really, accessors and mutators make it easier to tell who is messing with what.
English

@CodeRed_dev The reason, for anyone wondering, is to make sure X can't be changed by accident.
You typically see it with projects that have multiple people working on it
English

@CodeRed_dev Also I have started writing variables as private by default, and then get confused to why it doesn't show up when I need it. Then I need to add those setterd and getters and my code just turns into garbage lol
English

@CodeRed_dev You might want to do some "magical behavior", like clamping values or updating another variable or...
So this is the mark of someone that don't want to change all the value = value.x to value = value.GetX() later on.
English

@CodeRed_dev Because people are retarded. it's nice to teach these at school to learn that not everything should have access but in reality this screws many people.
At some point it's better to just make whatever specific thing you are trying to access public.
English

@CodeRed_dev because OOP is a poison and makes people code in needlessly abstract ways that make things simpler in the short term but wildly over-complicated in the long term and ultimately makes everything inefficient
English

@CodeRed_dev Its OOP. A programming style that was invented in the late 60's and should have stayed there.
English

@CodeRed_dev gotta make sure x doesn’t get changed on accident 🤬🤬
English

@CodeRed_dev I only do this if I specifically need some custom get / set logic, or I only need to be able to get but not set (or vice versa). Otherwise this is honestly just kind of unnecessary, goofy behavior IMO.
English

@CodeRed_dev It is called Encapsulation, and it is one of the principles of Object-Oriented Programming (OOP). Encapsulation offers many benefits, including protecting the internal state of an object, controlling access to data, and maintaining data integrity.
English

@CodeRed_dev Or worse, they put that in a single header file by itself.
English

@CodeRed_dev I’ll do this when I believe it won’t always be handled like that internally. I’ll also do it for consistency if it is grouped with things done similarly.
English

@CodeRed_dev Being radical about either option is a bit dumb. Encapsulation, debugging and mutate verification are main reasons to make them private. Less bloat is a reason for making it public. It depends on the team and project, not on the language or paradigm. Use both.
English

@CodeRed_dev So you can keep track of what is changing your variables. Using a method to get and set them is easier to follow.
English

@CodeRed_dev people think that adding complex rules to writing code will change the bad behaviors of bad coders 😔
they don't - they can get around this by getting pointer to the memory address - and they will 🙁
not using C won't help either 😮
they find a way - they always do😨
English

@CodeRed_dev I usually add a wrapper to the type if I need to debug.
Regular breakpoint is easier then data breakpoints for all instances. We need better debuggers, tbh.
English

@CodeRed_dev Because they are dumb, dogmatic and don't care about computers
English

@CodeRed_dev Careful what you post, a whole generation was taught that this slop is the One True Way of Programming 😂
English

@CodeRed_dev don't touch the raw with bare hands, we're not monsters
English

@CodeRed_dev If it's possible or likely you'll have to handle *how* it is set and handle cascades or side effects, you have the boilerplate to expand from immediately.
Otherwise, something will set it incorrectly and you're doing huge searches to find a bug where it was used improperly.
English

@CodeRed_dev Uh, you should read up about get and set
English

@CodeRed_dev There are a bazillion reasons why it's useful, but the main benefit boils down to just "control and traceability".
Ex: If you want to lock x n y without get/set, it would be annoying as sin, with get/set you just shove a "if not locked" on the set.
English

@CodeRed_dev It's future proofing when working with more complex code. But game gevs can often get away with not doing the most optimally scaleable code when working on indie projects.
English

@CodeRed_dev If they pay $0.50 per line I’ll make my money’s worth
English

@CodeRed_dev It's your getter and setter.
Its when you are paranoid your code is secretly trying to take you down
English











