Post

CodeRed
CodeRed@CodeRed_dev·
Why people code like this.
CodeRed tweet media
English
97
24
602
49.7K
NeverSink
NeverSink@NeverSinkDev·
@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
1
0
5
749
Joseph
Joseph@0xTraderJoes·
@CodeRed_dev private int balance; public void setBalance(int value) { if(value < 0) balance = 0; else balance = value; }
English
2
0
2
245
Stacked Cats🦜Final Flock🐦
@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
7
1
153
6.7K
Johann Ungerer
Johann Ungerer@Kaegun·
Because at some point in the future you may want to perform some validation before setting x, or in the case of a reference type, lazy load the type. This way you don't need to change any of the code that depends on those properties. Yes it's encapsulation, but this is why it matters.
English
12
0
84
8.1K
Techno Joe
Techno Joe@TechnoJo3·
@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
5
0
55
3.8K
Fear the Phantom (game in bio)
Fear the Phantom (game in bio)@Phantom_TheGame·
@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
1
0
37
2.1K
Styg
Styg@stygdev·
@CodeRed_dev Because they've been brainwashed by OOP gurus.
English
1
0
19
1.8K
DanLoup
DanLoup@DanLoup256·
@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
1
0
13
891
Yonatan
Yonatan@22yonking2·
@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
1
0
8
1.8K
J Hellyer
J Hellyer@hellyer_ja26490·
@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
1
0
5
234
Carl Schulze
Carl Schulze@CarlvSchulze·
@CodeRed_dev Its OOP. A programming style that was invented in the late 60's and should have stayed there.
English
0
0
4
266
VIDEO GAME FABLES available now on Steam!
@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
1
0
4
798
Sila Kayo
Sila Kayo@SilaKayo·
@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
0
0
4
587
crispybacon
crispybacon@CrisPyBacon99·
@CodeRed_dev Or worse, they put that in a single header file by itself.
English
0
0
2
526
Flipcoder 🚀
Flipcoder 🚀@FlipCoder·
@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
0
0
2
2.8K
Inan Evin
Inan Evin@inanevin0·
@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
0
0
2
152
DDI Racing Studio
DDI Racing Studio@ddiracing·
@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
0
0
2
1K
Mutantleg Games
Mutantleg Games@mutantleg·
@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
0
0
2
247
Simplex
Simplex@simplex_fx·
@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
0
0
2
181
Nathan Yahoo
Nathan Yahoo@survotreson·
@CodeRed_dev Because they are dumb, dogmatic and don't care about computers
English
1
0
2
30
Azleur 马克
Azleur 马克@Azleur·
@CodeRed_dev Careful what you post, a whole generation was taught that this slop is the One True Way of Programming 😂
English
0
0
1
55
Kadin
Kadin@KadinCooler·
@CodeRed_dev Java ¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯
Tiếng Việt
0
0
1
17
The Royal Feathered 🦆
Back in the early 90s there was this new indoctrination going around in universities called software design and we were too young to realize it was bad and that we should fight it. A generation of lost souls after, some never found their way back may heavens rest easy on their UML souls.
English
0
0
1
112
Alex is glad it was so difficult
@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
0
0
1
241
JaySaltyGeez
JaySaltyGeez@JaySaltyGeez·
@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
0
0
1
274
PaperPrototypes (Dev Interviews)
PaperPrototypes (Dev Interviews)@PaperPrototypes·
@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
0
0
1
382
ElRattoMatto
ElRattoMatto@HideYK1·
@CodeRed_dev It's your getter and setter. Its when you are paranoid your code is secretly trying to take you down
English
0
0
1
124
Paylaş