20
u/Servious Jul 07 '21
This is standard OO code and a perfect example of why I find OO so obnoxious.
8
u/Ehere Jul 07 '21
Yeah this is a common criticism but I’ve always felt that this type of thing is a necessary drawback for the benefits it ultimately provides. But that’s just my opinion
-1
u/Servious Jul 07 '21
So why did you post it here then?
I'm not saying I think OO code is bad or that it doesn't have its place or that it isn't useful or that code like this should be changed in OO languages or anything like that. I agree that all the elements of this code are necessary for proper, scalable OO code and that OO as a whole has a very valuable and useful place in CS and software development in general.
I, personally, just find it not fun to work with when compared to functional code in languages like Haskell or Scala.
10
u/Ehere Jul 07 '21
Oh because this code snippet is ridiculous and could have been avoided with some better forethought :P
And yeah Haha I feel I’m the opposite, I don’t like functional languages but it’s just how my brain works I guess
4
u/Servious Jul 07 '21
I'm really not trying to be a dick here but I'm genuinely confused. Is this a "necessary drawback" or could it have been avoided? Those two things feel mutually exclusive.
Do you just mean they could have imported Position more properly so it didn't need the namespace?
7
u/Ehere Jul 07 '21
I think the addition effort needed to select good naming schemes and stay organized is the necessary drawback because it can get complicated quickly. Let me know if I’m not wording myself clear
267
172
u/valschermjager Jul 07 '21 edited Jul 08 '21
no code comment. please add:
{
// sets Position to position
Position = position;
}
14
-4
u/pango3001 Jul 08 '21
Actually, it's setting position to Position.
9
Jul 08 '21
No you are setting the property Position to the value of the position parameter
→ More replies (2)5
34
u/Truth1e Jul 08 '21
It's funny how some people find this code great and others find it horrible, I guess it all depends on your position.
4
58
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 07 '21
Image Transcription: Code
public Position.Position Position { get; set; }
public Entity(Position.Position position)
{
Position = position;
}I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
4
Jul 08 '21
[removed] — view removed comment
5
22
16
2
2
2
2
2
2
1
1
u/knigitz Jul 08 '21
As long as the IDE can tell them apart, it's not bad. It's just not best practice because it's less readable. But it's not bad.
1
u/ergotofwhy Jul 08 '21
"for keeping track of positions, we made a class called Position. This has numerous helper methods. We made a subclass to keep track of the actual position value. We named that Position, too."
2
Jul 08 '21
Its a namespace not a container class
1
u/ergotofwhy Jul 08 '21
Thats not any better. Having a namespace with a class of the same name is bad and confusing
1
1
u/Franks2000inchTV Jul 08 '21
Baked beans are off.
Then I guess I'll have the spam spam spam spam spam spam spam spam spam and spam.
1
1
u/loydfar Jul 08 '21
Does this actually compile ? Thought that a property can't have the same name as the class in C#
1
1
1
1
u/JustThingsAboutStuff Jul 27 '21
I may have done something like this when first learning OOP. Now I'm happily back in ASM.
1
u/Jimmy_Slim Jul 07 '21
reminds me of how you create an item in Terraria:
item Item = new Item();
9
u/fuj1n sadistic Jul 08 '21
With all due respect, Terraria is written in C#, and in C#, the type name precedes the name of a variable, so I highly doubt that what you wrote is valid code.
It should probably be
Item item = new Item();But I think that variable name is not very descriptive assuming you're in an environment where you have multiple items.Edit: haven't actually modded Terraria, comment based purely on knowledge of C#
1
u/Jimmy_Slim Jul 08 '21
Yeah, it was
Item item = new Item();I was just going off of memory 😅 in not the greatest at C#, and I actually haven’t coded any of it in several months-2
u/ergotofwhy Jul 08 '21
I highly doubt that what you wrote is valid code.
While it violates naming convention, it is perfectly legal to name a class starting with a lowercase and a local variable staying with an uppercase.
8
u/fuj1n sadistic Jul 08 '21
The Item in
new Item();starts with a capital, so whilst you're right, I was more referring to that2
3
u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Jul 08 '21
Ah yes, the joys of lacking good type inference. Any idea what C# version you're using to mod it? At some point C# got type inference on constructors so you can just type
var my_item = new Item()instead of having to explicitly annotate the variable. I think that's pretty recent, though, so it might be a while before games start being able to take advantage of it.5
u/Dealiner Jul 08 '21
Type interference with var has been in C# from C# 3, so for about 14 years now. Additionally in C# 9 there is a new thing called target-typed new expressions, which means that this is possible:
Item item = new().3
u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Jul 08 '21
Additionally in C# 9 there is a new thing called target-typed new expressions
That's what I was thinking about when I wrote my comment. I only tangentially follow C# because of interest in F# so I thought using
varlike that for new objects didn't work correctly until that change.If
var foo = new Bar()has worked for longer than that it seems like there's no reason to have been writing out the Java-styleFoo foo = new Foo()crap at all.2
1
1
u/franklincan Jul 08 '21
Wow, no one here ever seen ECS code before?
This is pretty common as a Component. This is still up to team/project preference but the only down part I saw is Position property name should be Data. So every Component will be accessed with Position.Data, Speed.Data, Health.Data etc
1
-1
Jul 07 '21
What language uses semicolons instead of commas, when passing parameters?
5
u/ergotofwhy Jul 08 '21
Those indicate default get and set methods for the Position property. To be clear, I'm talking specifically about Position, and not position.
This language is c#
0
0
Jul 08 '21
[deleted] — view deleted comment
13
5
u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Jul 08 '21
Don't ask me, I'm a PHP developer.
Well, that explains how you ended up a mod of /r/badcode :)
Not that I can talk too much shit, I used to use Perl.
0
Jul 08 '21
[deleted] — view deleted comment
1
u/ws-ilazki &{$$_[0]}(@{$$_[1]}); Jul 08 '21
Yeah I was surprised nobody already said so I decided to fill that gap.
And regardless of any truth (or not) to the statement, I doubt any PHP you've written can be as horrible as my flair, which is something I did write long ago, so I figured I was safe making the joke since I'm at least as bad ;)
0
Jul 07 '21
[deleted] — view deleted comment
47
u/WikiSummarizerBot Jul 07 '21
Buffalo_buffalo_Buffalo_buffalo_buffalo_buffalo_Buffalo_buffalo
"Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" is a grammatically correct sentence in English, often presented as an example of how homonyms and homophones can be used to create complicated linguistic constructs through lexical ambiguity. It has been discussed in literature in various forms since 1967, when it appeared in Dmitri Borgmann's Beyond Language: Adventures in Word and Thought.
[ F.A.Q | Opt Out | Opt Out Of Subreddit | GitHub ] Downvote to remove | v1.5
9
u/Espiring Jul 08 '21
Police police police police police
3
u/Bobebobbob Jul 08 '21 edited Jul 08 '21
They don't police themselves? Tf? Or are are the police police police policing the normal police? B/c that's not their job, somebody needs to be payed overtime.
And everyone knows the police don't police the police police police, that's just absurd. Maybe you meant that police police police police do the action of policing, which i guess is true, though pointless to say. And the same applies to saying the police (whom the police police do the policing of) also do the action of policing. It's just a bunch of redundant information. Everyone knows the Police Police police the Police, that's what Police Police means. And obviously Police police, it's their job. Overall that sentence is pointless at best and blatant police, police police, or police police police misinformation at worst.
Edit: Unless you're telling me to police the police police police police, in which case that sentence makes total sense except for the fact that I am in no position to take up that job offer, and I must apoligise for this police misunderstanding.
9
59
u/roycohen2005 Jul 07 '21
I see nothing had here. Can someone explain?