#Clean code thread

1 messages ยท Page 1 of 1 (latest)

drifting hinge
#

It's time to move this to a thread

pearl arch
viscid flint
edgy wind
#

repetition is fine as the only justification for a method. you don't have to make up these extra reasons

pearl arch
#

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

woeful cape
#

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)

pearl arch
#

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

errant quarry
#

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.

edgy wind
#

dude ive literally been saying your solution isn't bad, your justification is

#

have you been reading

drifting hinge
#

One of my favourite classes is a ~1000 lines and it's just a big array of numbers as strings ๐Ÿ˜„

pearl arch
#

wait this whole thing stemmed from a translation thing?

winged wharf
#

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.

errant quarry
#

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

pearl arch
#

whats the code

errant quarry
#

And a universally acknowledged

edgy wind
#

yeah at this point you're just self-absorbed

pearl arch
#

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

edgy wind
#

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

errant quarry
woeful cape
#

I thought he had to go

winged wharf
drifting hinge
#

That was someone else iirc

errant quarry
# edgy wind yeah at this point you're just self-absorbed

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.

edgy wind
edgy wind
errant quarry
#

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

winged wharf
errant quarry
#

It's gonna be default big spaghetti code that 'good' according to you

#

But not according to leading programmers

edgy wind
errant quarry
viscid flint
#

aight, didn't get any examples so

#

i'll just find them myself

pearl arch
#

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

edgy wind
viscid flint
#

btw did we ever get an answer to the original question that started this?

pearl arch
edgy wind
#

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

viscid flint
#

i joined a bit after, may have been stuff before

edgy wind
#

do i really want to participate in this dick-measuring contest (programmer's edition)โ„ข๏ธ though thonk

errant quarry
viscid flint
errant quarry
#

Literally

errant quarry
#

At least someone acknowledges

viscid flint
#

"my" being the keyword there

#

i haven't actually said anything except jokes or questions

pearl arch
#
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?
errant quarry
#

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.

edgy wind
#

I can post mine, too, we can compare. Post bigger ones, the bigger the better.

edgy wind
errant quarry
#

It can always be better, but it's better than code of most people, I'd say, and I have good reasons for it.

pearl arch
#

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)

edgy wind
woeful cape
#

You just did it for the V3 instead of the Translate

pearl arch
#

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

placid minnow
#

#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.

pearl arch
#

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

edgy wind
#

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

edgy wind
pearl arch
edgy wind
#

or both, mayhaps ๐Ÿ˜‚

pearl arch
#

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

pearl arch
#

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

edgy wind
errant quarry
#

Instead of addressing the points on the subject.

pearl arch
#

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

errant quarry
#

You were saying how I'm spewing buzzwords and following my idol

edgy wind
#

...are you saying you disagree with that?

errant quarry
#

If that's not personal attacks, I don't know what is

edgy wind
#

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

errant quarry
#

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

edgy wind
errant quarry
#

Yeah and that's what you said

#

Which is a personal attack

edgy wind
#

uh you sure that's a personal attack?

#

im attacking your claims, not your person or way of speaking or anything

errant quarry
#

And now you're telling me "do I want to join this measuring contest", but you started it when you said it

edgy wind
#

lmao yeah ok this is getting ridiculous

errant quarry
viscid flint
drifting hinge
#

Everyone can just move on at this point, it's very clearly going nowhere

pearl arch
#

whats it with gamedev servers and incessant bickering notlikethis

edgy wind
#

*programming servers

pearl arch
#

programmers love to bicker

pearl arch
edgy wind
#

*community servers, maybe

errant quarry
#

@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:

edgy wind
#

or just, *servers lol

errant quarry
#

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

icy sluice
#

just kiss and move on

errant quarry
#

I don't mind people disagreeing, but I linked some of the attack above here:

#

Yet they're afraid to post their code

pearl arch
woeful cape
#

This server isn't for you if you dislike them tbh

edgy wind
woeful cape
#

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

errant quarry
woeful cape
#

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

errant quarry
#

idk why did they have talk down to me and do personal attacks instead of addressing the points.

errant quarry
pearl arch
#

imma press this funny looking button, I wonder what it does!

errant quarry
#

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.

icy sluice
#

the real question is, does this discussion solved your problem or made you waste 1,5h on unproductive stuff?

errant quarry
#

Which is how you probably write code: whatever feels better today goes.

errant quarry
#

And "you don't understand what you're doing"

#

I was dragged into this.

viscid flint
errant quarry
#

@viscid flint why are you even in this thread, other than to troll and antagonize?

viscid flint
#

good point

#

cya

icy sluice
#

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.

errant quarry
#

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

viscid flint
#

everything everyone has said so far is advice not fact

#

anyway thats all, cya, again

errant quarry
#

All you did so far is doxxed me and trolling, that's all you did.

viscid flint
#

doxxed kek

#

ok ok final thing

#

cya

icy sluice
#

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

errant quarry
placid minnow
#

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.

icy sluice
errant quarry
#

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

icy sluice
#

its the same, you should be familar with matrix transformations

woeful cape
errant quarry
errant quarry
#

So like List.Count == 0 is worse than List.IsEmpty()

#

And you can see those in many libraries

viscid flint
woeful cape
#

I have absolutely now idea how you are not able to understand what Count == 0 means

errant quarry
#

Like in C++ library: vector::empty

woeful cape
#

The idea of magic number is that they don't tell you what they mean.
Please explain how 0 is hard to understand

errant quarry
# woeful cape I have absolutely now idea how you are not able to understand what `Count == 0` ...

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.

icy sluice
#

hows is a 0 in Transformation method which perform matrix transformation of transform Vector3 considiered as magic number

#

simply mean, no transofrmation applied

errant quarry
# icy sluice 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.

woeful cape
#

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

errant quarry
woeful cape
#

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

errant quarry
#

I don't remember the implementation in List

woeful cape
#

How else would I know the inner array's size?

placid minnow
# errant quarry Meanwhile, in `TranslateY(CharacterHeight)`, there is no question to be asked

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.

errant quarry
#

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.

errant quarry
icy sluice
placid minnow
woeful cape
#

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

errant quarry
#

Anyway, as much as I'd like to continue, I gtg

placid minnow
#

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.

viscid flint
#

at this point, this just feels like a question of preference

woeful cape
#

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

viscid flint
placid minnow
#

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."