#Clean code thread
1 messages ยท Page 1 of 1 (latest)


repetition is fine as the only justification for a method. you don't have to make up these extra reasons
re what FusedQ said, the question of whether X is faster than Y, isnt wrong. Its a valid concern.
the problem is simply saying "X is faster than Y" or "dont use X, its slower than Y" doesnt really give any metric of what "fast" is
say X is 100 times slower than Y, on the surface that sounds pretty bad
No, often you really should not have to worry about this
This also applies to the "make the code work, then make it pretty" point, same for performance (with a grain of salt, obviously, but not aggressive performance improvements like this)
but then it turns out X takes 100ns to finish, Y takes 1ns
with such a stupidly fast speed for both, theres just not much need to worry. Especially when its a function to make your player drink a health potion
Ok, I gotta go, I didn't come here to argue, I only asked a question on how to simplify the translating the position. idk why you guys had to start "your solution bad" convo, when I know what I'm doing and my reasons and I didn't ask for the code review.
@edgy wind @wintry creek let's see one of your classes(pick a bigger one, please) and see what framework you guys are following.
Then I can tell you how your code is bad, according to me and my school of thought.
dude ive literally been saying your solution isn't bad, your justification is
have you been reading
One of my favourite classes is a ~1000 lines and it's just a big array of numbers as strings ๐
wait this whole thing stemmed from a translation thing?
To reply to the post on the main channel
@errant quarry The very code you posted shows you did not know what you were doing and by asking for simplifications you are asking for code review.
I mean you could say how you don't agree, but don't give people this "your code bad" and "spewing buzzwords" when someone is following an alternative approach to programming, that's probably better than yours, too:
At least I have a solid one
whats the code
And a universally acknowledged
yeah at this point you're just self-absorbed
I dont see how a translation function could cause such a debate, especially when it sounded like its just that it was a case of trying to work out how to get the XYZ component in the correct configuration
you're repeating the same points even when given explanations about how they don't really matter
you're giving rebuttals for things that aren't really in question
I know what I was doing and I knew how to write it "the default way", I just didn't know that the Translate function existed at time when I asked.
I asked for improvements not for code review of my posted solution.
I thought he had to go
you also did not know that transform.position was a property and a value type
That was someone else iirc
I'm not self-absorbed, I just wanna see your classes now, how good you really are. I can post mine, too, we can compare. Post bigger ones, the bigger the better. I wanna see one of those 2000-line ones that are "good" according to your framework, because SOLID and DRY doesn't apply to gamedev apparently.
yeah that was the uh guy starting with r
fuck sorry misinput
wtf class-measuring contest ๐
And I'm always open for actually good approaches
But I doubt you guys will present a good one
From what I've read so far
my bad, I thought this was a continuation of the same conversation
It's gonna be default big spaghetti code that 'good' according to you
But not according to leading programmers
and nowhere did i claim solid/dry don't apply to gamedev lol
i said they don't apply universally
you're just antagonizing everyone now ๐
I'm not antagonizing, you went with personall attacks first
also re: clean code and patterns, its interesting that people seem to develop a mindset where patterns are an "exact science", like they think the only way to write a builder would be https://refactoring.guru/design-patterns/builder/csharp/example and thats the only way a builder can be written.
when the reality is patterns are literally just some sort of abstract idea that just says how you implement certain behaviour in the code
even if i did: doesn't mean you aren't antagonizing.
and ive already clarified i didn't mean that as an attack lmao
btw did we ever get an answer to the original question that started this?
what actually was the question
shoot, doesn't seem like any of my games are public on gh
guess ill have to wait to get on pc so i can properly send one
#archived-code-general message i think
i joined a bit after, may have been stuff before
do i really want to participate in this dick-measuring contest (programmer's edition)โข๏ธ though 
You guys started it with "your code bad" and "you don't understand what you're talking about"
im just watching from the sidelines, all of my code is trash but works 
Literally
Exactly
At least someone acknowledges
"my" being the keyword there
i haven't actually said anything except jokes or questions
public static Vector3 AddPosition(this Vector3 vec, float x, float y, float z)
{
return vec += new Vector3(x, y, z);
}```no idea if it would work but I guess this?
im just watching from the sidelines, all of my code is trash but works :kek:
And my code is good: it follows a solid acknowledged framework and also often TDD'd and tested.
You don't have to agree with me and the approach, absolutely not. But don't tell me that my code is bad and I don't understand what I'm talking about, that's just rude and also simply false.
I can post mine, too, we can compare. Post bigger ones, the bigger the better.
you guys
yeah idk where you're getting this
It can always be better, but it's better than code of most people, I'd say, and I have good reasons for it.
cause if youre going to do myvector.AddX(1) or myvector.AddY(4) you already know which value your changing, so just do myvector.AddPosition(0, 4, 0)
my code is good
fake programmer spotted
This is what Translate does pretty much
You just did it for the V3 instead of the Translate
yeah
I dont think its necessarily bad to write your own method even when unity already has one
if you do something that makes it easier for you to work, then no matter what anyone says, you are doing the correct thing
#archived-code-general message #archived-code-general message
I have no horse in this race, but I really do encourage you to think about the points I've raised about working with others, and how writing (subjectively) best code does not necessarily mean it's the best for the project.
And on a higher level, it's not about "the best" it's about solving problems. Patterns exist to solve problems, principles exist to solve problems, and these are potential solutions rather than gospels. You don't need to use a crutch if you don't have a broken leg, using one when you can walk perfectly fine will cause more troubles to you and everyone working with you.
its like if you named your properties something like public Vector3 mYvEcToR_uSeS_wAcKyCaSe and for some odd reason using that naming style helps you personally work better, so be it
yeah imma repeat my stance to contrast what kula is saying about me
i think the method is fine, but the justfication that was presented isn't
it's fine to have a utility method like that to reduce repetition or whatever
but it's not really correct to claim that the utility method is way better because of readability or maintainability or what have you, and i think this justification is misled from a misunderstanding of how to practically, properly apply the referenced principles
they stand out more so you use them for important stuff, or they're hard to read so you use them for unimportant stuff?
the mind of the wackycase user, is a mystery
or both, mayhaps ๐
I find my naming style evolves every so often
when I notice it makes it easier for me to parse the code if I name something a certain way, I tend to pick it up as a habit
public BoxShapeV2(float _x, float _y, float _width, float _height) I used to use underscore only on argument names, never anywhere else
helped me know when im in a method, whether some property was given as an argument or if it existed elsewhere in the class
then for whatever reason, I stopped doing it at some point
wow discord is broken those links are not scrolling correctly
ill check back on this later
You can't tell me I'm antagonizing and that you didn't start it, when you kept writing stuff like:
Instead of addressing the points on the subject.
naming is one of those clean code things people seem to think matters a huge amount, not that a consistent naming convention is bad or anything
You were saying how I'm spewing buzzwords and following my idol
...are you saying you disagree with that?
If that's not personal attacks, I don't know what is
uhh perhaps the age comments?
im not sure why you think both sides can't be antagonistic lol
maybe i am; i probably wouldn't know
but you're saying you aren't also doing that? who started it doesn't really matter does it
That was my answer to you. An answer after you wrote "spewing buzzwords"
As if I don't understand what I'm talking about
And just echoing what I watched on YT
Which is a personal attack
Which "OK" but don't tell me you didn't do it
yes that's how i interpreted your comments, tbh
uh you sure that's a personal attack?
im attacking your claims, not your person or way of speaking or anything
And now you're telling me "do I want to join this measuring contest", but you started it when you said it
lmao yeah ok this is getting ridiculous
You did attack my person when you said that I'm spewing buzzwords and not understanding what I'm saying as you just acknowledged yourself

Everyone can just move on at this point, it's very clearly going nowhere
whats it with gamedev servers and incessant bickering 
*programming servers
programmers love to bicker
true
*community servers, maybe
@edgy wind now, after we agree on that you did attack my person with your original comment, acknowledge, that you started it and not joining:
or just, *servers lol
And then we can move on
And maybe don't do it to people
And treat them more of as equals and not lower than you
just kiss and move on
I asked a question and was talking in good faith and started being accused of spewing buzzwords and not understanding what I'm talking about and now of starting all this when all I asked is how to simplify a solution and then showed my solution and then defended it, without doing any personal attacks or talking down to people or anything. They started it and continued.
I don't mind people disagreeing, but I linked some of the attack above here:
Yet they're afraid to post their code
there needs to be a #fight channel just to let everyone burn off the pent up nerd rage
Half of these is valid criticism
This server isn't for you if you dislike them tbh
we kinda make threads for each fight don't we
Like, any server where you ask a valid question can very likely net you a response like "you have completely misunderstood the situation" or something similar
There is no nerd rage here, go to the start of the convo and see how it started:
Not as a personal attack, or a way to make you feel bad, but as genuine criticism to get you to understand an issue
It's more important what comes after
idk why did they have talk down to me and do personal attacks instead of addressing the points.
I don't mean you. You didn't do any of that. And you can see how I was answering to you.
And it's cool to disagree, it's just very annoying when people start to talk down to you like that.
imma press this funny looking button, I wonder what it does!
Also it's engineering, you can't just tell someone they're wrong and their solution is bad without presenting a solid foundation and reasoning.
Like I presented mine: it's Uncle Bob's Clean Code.
So far other people haven't presented here anything other than "Because I feel like it"
I posted links with references to defending what I did with my solution.
Yet I haven't seen a single thing so far from you guys with an alternative approach to programming.
the real question is, does this discussion solved your problem or made you waste 1,5h on unproductive stuff?
Which is how you probably write code: whatever feels better today goes.
It absolutely did. All I did is asked a question and posted my solution, I didn't ask for a code review on my solution and to be told "your solution bad"
And "you don't understand what you're doing"
I was dragged into this.

@viscid flint why are you even in this thread, other than to troll and antagonize?
Solid principles should apply always, DRY only if you repeats something more than 2/3 times, patterns are used to solve common problems in scalable way, if your solution doesnt scale this is the way to go. Creating new utility methods may be good but for something simple like manipulating one Axis its just no more than unnecessary bloating your project.
It's not. You can confuse the axes. I did that in the past.
You know you can confuse things if you worked long enough on anything other than trivial projects.
So you do anything to minimize the ability to confuse things, repeat things, etc.
So I get rid of magic numbers like Translate(0, 10, 0)
An turn them into TranslateY(CharacterHeight)
It's one of the Clean Code rules that worked very well for me so far, it results in good high quality code that's easy to write, easy to understand and extend
if it works for you then just keep doing it
everything everyone has said so far is advice not fact
anyway thats all, cya, again
Not everyone.
All you did so far is doxxed me and trolling, that's all you did.
those are not a magic numbers, the order its always x y z, and its UnityEngine method so you should memorize how the axis are represented in the engine you working with
The 0s are magic numbers. What are the 0s for there?
You are still thinking in terms of right or wrong rather than tradeoffs. Everything has a cost to its benefits, this includes not just your TranslateY but also things like list.IsEmpty(), patterns and principles (yes even DRY). You've been in the conversation for a long time so I feel like you've missed a lot of good points that some people have brought up and instead too busying fighting off people.
calculating matrix transformation, 0 gives no transformation on that axis
Well, you had to tell me this information just now, didn't you?
And I had to ask it
So it's not present in the computation there
In calling the function
Meanwhile, in TranslateY(CharacterHeight), there is no question to be asked
Because it's explicitly stated
its the same, you should be familar with matrix transformations
The whole idea of magic numbers is that they are unclear and possibly change in the future, so therefore they should be constants. 0 is not a magic number because "zero" or "nothing" will always be 0
It is not the same. I am familiar with matrix transformations for many, many years now. Thank you.
The idea of magic number is that they don't tell you what they mean.
If I have to read it and try to reason about them and go back, it's a magic number.
There is no reasoning and going back with TranslateY(CharacterHeight), also no need to spam the 0s everywhere in the codebase and repeat myself everywhere.
So like List.Count == 0 is worse than List.IsEmpty()
And you can see those in many libraries
i really want to leave this thread but, i cant not send this 
I have absolutely now idea how you are not able to understand what Count == 0 means
Like in C++ library: vector::empty
The idea of magic number is that they don't tell you what they mean.
Please explain how 0 is hard to understand
I understand what it means. I'm talking about the approach to write your code. We're examining simple examples. It's about the approach to writing your code, if you follow the Count == 0, it explodes extremely badly in a real code base, meanwhile the List.IsEmpty() approach keeps the code clean and clear to the reader.
Like, we'd have to examing real code examples with bigger(say, 20+ lines, 50+ lines would be better) methods and see how we can refactor them in smaller methods.
hows is a 0 in Transformation method which perform matrix transformation of transform Vector3 considiered as magic number
simply mean, no transofrmation applied
Yes, this is how it is a magic number: you have to separately state it like you just did and as a reader have to read and reason about it.
You want to do everything you can, so you don't have to explain anything to the reader and it's clear right there in the code.
It's not possible realistically to do everything, but you can minimize the number of places you have to do it.
I maintain real code bases. I don't even use Unity but .NET projects that span 10+ years. I can assume you that I would much prefer simply cases like Count == 0 over bloat like IsEmpty because these projects are already massive enough and I don't need some shady aliases that might or might not hide more behaviour behind them
The Count is a shady alias with methods behind it, no? It's a property.
Also, the average company is not going to accept weird extensions like IsEmpty and they are going to want you to just use a simplified syntax
I don't remember the implementation in List
Except this is a genuine property in the class and not an extension, this is irrellevant
How else would I know the inner array's size?
There are lots of questions to be asked, which Y direction does it translate positive or negative, does it modify the position or does it return a new one, and similar to list.IsEmpty() when there are existing ways to do the same thing why does this extension method exist?
You like talking about DRY a lot, and even that should be universally applied. Two pieces of code that could happen to have the same implementation right now but very likely to change and diverge later, refactoring them now for the sake of DRY will cause more refactoring work later.
Again the most important point is tradeoffs, there's no absolute right or wrong. In cases where you feel like there is an absolute right or wrong, it's very likely that you have made some hidden assumptions about which tradeoffs are not applicable to the situation, and thus the solutions that carry those tradeoffs suddenly appear to be "absolute right."
If you instead think in terms of tradeoffs, list.IsEmpty() has some very clear tradeoffs: the code is very descriptive, but it may cause confusion to others who read the code ("Why not just list.Count == 0? If I want to contribute to this project, should I always write list.IsEmpty() or is it okay to write list.Count == 0") and inconsistencies to the code base ("If I come across a piece of code that is currently written as list.Count == 0, should I send a PR to fix it?"). And if you think a bit more about almost everything, you will see there are plenty tradeoffs.
Well, let's not see "the average". Let's look at the good ones:
https://cplusplus.com/reference/list/list/empty/
https://www.geeksforgeeks.org/list-isempty-method-in-java-with-examples/
It's implemented in many languages.
There are lots of questions to be asked, which Y direction does it translate positive or negative
This question can then be asked about the normal Translate, too.
But now it's a question about the coordinate system, not about the function.
does it modify the position or does it return a new one
Again, same for the normal Translate. But you can see it if you see the function declaration.
and similar to list.IsEmpty() when there are existing ways to do the same thing why does this extension method exist?
I'm not following this one.
Your approach is simply more confusing than applying Vector3 transformations on a Vector3, and thats not something its required to explain to user, its basic knowledge if you want to work with any space related code
If you see code like 1.Add(2), you will be confused "why doesn't the person just write 1 + 2, what's so special about the extension method .Add?"
I don't see the point in comparing against other languages. Their conventions are way different and it probably does not apply here.
Also, I believe in Java's case it might be different collection types, in which case it is the same as IEnumerable.Any in C#'s case
So then just use Any if you're so keen in using a written approach, just note it's worse for performance
You're missing the point about magic numbers. 1.Add(2) is around as not clear as 1 + 2, because there are 2 magic numbers. But I like the 1+2 more, because it's a clearer operator.
I said at the start I'd prefer to write transform.position.y += CharacterHeight instead of transform.TranslateY(CharacterHeight)
Anyway, as much as I'd like to continue, I gtg
You are completely missing my point which is about thinking in terms of tradeoffs rather than absolute right or wrong, and instead picking apart word by word.
If you are just here to be defensive about yourself, then I see no point in continuing the conversation.
at this point, this just feels like a question of preference
Writing all these extensions methods for specific cases just cause unnecessary bloat which really hurt the application so I think this is something you'll just have to figure out yourself
if your team (or whoever is reading the code) cant read your code than they'll probably just tell you. at that point you may as well just use whatever they tell you to make things easier
I'm not even here to talk about translate or list.IsEmpty(), to me that's such a minor issue that you do whatever you like. What I'd like to bring attention to is the idea that "there is an absolute right and wrong" and "patterns and principles are applicable and should always be used," that is far more important of an issue than any of these stuffs, because rightfully who cares about TranslateY, if you hate it you can regex the entire code base and fix it in a second. Having the wrong mindset and approach to programming is a far bigger issue that leads to way more troubles than something that can be fixed with a regex.
But I see that this has more or less become "me vs everyone else."
