6 Code Smells REFACTORED to Patterns!

  Рет қаралды 9,635

git-amend

git-amend

Күн бұрын

Пікірлер: 131
@git-amend
@git-amend 5 ай бұрын
Happy Sunday! Would you be interested in having a system in your project reviewed and refactored on the channel? Make sure to join the Discord - in the future we may refactor more advanced examples than this simple system! Also, I've added new extension methods Vector2 and Vector3 RandomPointInAnnulus to the Utility library that ensure uniform distribution - see description for explanation!
@MagicPigGames
@MagicPigGames 5 ай бұрын
I'm betting I'm not the only one who thought about the first half, "Oh yeah, that's easy, makes sense, that's what I would have done" and the second half "Wait, pause, what's that now??" :D Great stuff.
@techdave99
@techdave99 5 ай бұрын
Great to see you watch these videos. It would be great if @git-amend would be a guest on the gamedev show. I don't know if Jason watches these videos.
@git-amend
@git-amend 5 ай бұрын
Thanks for the comment! Glad you enjoyed the vid!
@sima19995
@sima19995 5 ай бұрын
Ever since I started watching your videos my programming skills have literally skyrocketed. Your videos are a godsend. Unfortunately KZbin is full of tutorials teaching you very very wrong concepts which a beginner will gladly consume. I did at least. Realizing how misleading they were took a lot of time. I guess that's part of the learning process... One thing I noticed: When referencing the prefab in the EnemyConfig class you could actually reference the prefab as type Enemy. That way there's no need to get the component when initializing. It's less prone to human error when dragging the prefab in the inspector too.
@git-amend
@git-amend 5 ай бұрын
Thanks for the comment! Great tip too, I totally missed that optimization while refactoring, good catch!
@ryaz4704
@ryaz4704 5 ай бұрын
​@@git-amenda part 2 video incoming?
@thehuggz-i9k
@thehuggz-i9k 5 ай бұрын
Your videos are a step above the standard Unity tutorials. This series is great! What better way to show how to apply what you've already been talking about than showing it in the bad code we're already writing :D Thanks!
@git-amend
@git-amend 5 ай бұрын
Glad you like them!
@TuberTugger
@TuberTugger 5 ай бұрын
I agree. It's like an actual dev vs content creators. Just condensed, actual knowledge flowing straight into my brain.
@franciscooteiza
@franciscooteiza 5 ай бұрын
Hey Adam, Thanks to your videos, I'm getting a better handle on all these programming patterns every day. I really appreciate you teaching us how to be better programmers. Cheers,
@git-amend
@git-amend 5 ай бұрын
Great to hear! Thanks for the comment!
@MarushiaDark316
@MarushiaDark316 5 ай бұрын
Wow! This is amazing. Exactly what I've been hoping you'd make - beginner's guide to practical applications of patterns. I look forward to more of these.
@git-amend
@git-amend 5 ай бұрын
Glad it was helpful!
@TuberTugger
@TuberTugger 5 ай бұрын
This is EXACTLY the type of coding I like to watch. Refactoring is an art form. Knowing how or when to use a tool is arguably more important than knowing the tool itself. Very impressed. I can't wait for the next one of these!
@git-amend
@git-amend 5 ай бұрын
Great, glad to hear that! Thanks for the comment!
@MaximumAxiom
@MaximumAxiom 5 ай бұрын
I like this more concrete explanation for patterns, its usually hard to see where to utilize them when its more abstract
@git-amend
@git-amend 5 ай бұрын
Thanks! Will probably do a few more like this in the future
@Fitz0fury
@Fitz0fury 5 ай бұрын
This as a series is going to be awesome. Excited to see your process for reviewing and improving others code. Glad to see you're starting these.
@git-amend
@git-amend 5 ай бұрын
Thanks! Maybe we can do one of these every couple months, I'll announce a bit before hand and take some submissions on Discord I think.
@successor0
@successor0 5 ай бұрын
This was great! One thing about the command pattern part of the video though. I feel like the jump from the old implementation with the strings and likely ifs to the whole command pattern implementation is too much. Someone who did the string implementation would be overwhelmed with the sudden new rather complex approach, especially given that they were in a level that uses magic strings. I'd love the refactors to cover some alternative ways to achieve things before jumping into the related pattern, talking about the problems current implementation has and the solutions new approach will provide. For example, before writing the command patterns implementation on this video, we could switch the magic strings to enums, talking about the problems this approach solves and does not solve, then go about implementing the pattern. Also must say I especially loved the factory pattern. I always had difficutly understanding the concept for some reason but this video made it so easy to understand. Also as a last nitpick, the new spawning logic with the strategy pattern looks like it can't actually achieve the old behaviour as it required the index of the loop to be used in the positioning logic, which the SetPosition method signature does not currently allow passing. How would one achieve this with the new implementation? Thank you :)
@git-amend
@git-amend 5 ай бұрын
Thanks for the comment. In regard to the strategy, that's a good observation. I would probably suggest overloading the method in the strategy to accept optional params, perhaps a count or a ref to the List of enemies that have already been spawned.
@melipefello
@melipefello 5 ай бұрын
First video that actually doesn't teach anything new to me, and I'm extremely happy about it! It means I've improved a lot since the first videos :)
@git-amend
@git-amend 5 ай бұрын
Great to hear!
@4rcant
@4rcant 5 ай бұрын
Most valuable channel on youtube for me right now
@git-amend
@git-amend 5 ай бұрын
Thank you so much!
@darrencook7168
@darrencook7168 5 ай бұрын
Love this one! Thank you so much! You asked for video ideas so, if you haven't already done this, I would like to see a video or even a series on creating a template project. More specifically, code that you would want pre-existing for any new project so that you could quickly either copy the project or import the package(s), and start building/prototyping.
@git-amend
@git-amend 5 ай бұрын
I’ve got a video on that topic coming soon!
@jeffreyhersh908
@jeffreyhersh908 5 ай бұрын
Thank you for your videos. There is a dearth of intermediate to advanced tutorials for Unity on KZbin. Many of the examples you have made I have adapted into my own projects and it has made me a much better coder.
@git-amend
@git-amend 5 ай бұрын
You're very welcome!
@TheArghnono
@TheArghnono 5 ай бұрын
You really help me push my Unity programming to the next level.
@git-amend
@git-amend 5 ай бұрын
Great, glad to hear that!
@cloudPvP
@cloudPvP 5 ай бұрын
I loved this format, and it really show us a more hands on approach on how to refactor using patterns. If you want do more videos of this style please :D
@git-amend
@git-amend 5 ай бұрын
Thanks will do!
@owencoopersfx
@owencoopersfx 5 ай бұрын
This is a great format to show where it actually makes practical sense to implement the design patterns. I vote for more :)
@git-amend
@git-amend 5 ай бұрын
Glad you like it!
@techdave99
@techdave99 5 ай бұрын
Worth watching multiple times. The flyweight pattern used here helped me understand where it can be used.
@git-amend
@git-amend 5 ай бұрын
Thanks! Maybe next time we'll tackle something a bit more complex as well.
@MarkRiverbank
@MarkRiverbank 5 ай бұрын
Thank you so much for your content. I've been doing this a long time--I'm usually the old guy on the team shaking his fist at the clouds and saying, "why don't they teach GoF patterns to these kids?"--it's rare to find content that actually pushes me and exposes me to new things.
@git-amend
@git-amend 5 ай бұрын
Thanks for that! I know exactly what you mean! Glad to have you here.
@TheKr0ckeR
@TheKr0ckeR 5 ай бұрын
Cool concept! I love flyweight SO approach "until we upgrade values" like you said in health example. That would also required me to refactor it. To be told, I would really love to see a modular upgrade system where we upgrade heroes & save it. Thanks for the huge effort on the video.
@git-amend
@git-amend 5 ай бұрын
Thanks for the comment. That's an interesting idea for a video, I'll give it some thought!
@정동우-n2x
@정동우-n2x 5 ай бұрын
I like this content Because looking at the mechanism of code modification helps beginners like me
@git-amend
@git-amend 5 ай бұрын
Great, glad it's helpful! I'm glad this video resonates with people who are at different levels.
@donmacsween2842
@donmacsween2842 5 ай бұрын
Thank you, vey useful. Hearing your thought process as you go along is almost unique at this level of Unity tutorial and so integral in understanding why a pattern is useful and how it can fit with other patterns. Hope you do more of these across differing use cases.
@git-amend
@git-amend 5 ай бұрын
Glad it was helpful!
@OskGame
@OskGame 5 ай бұрын
It's great to learn one more pattern and apply it to simple examples, it helps me understand them and know in what situations to apply it to them. Thank you very much, hopefully there will be a DI + pattern video soon!
@git-amend
@git-amend 5 ай бұрын
Glad it was helpful!
@techdave99
@techdave99 5 ай бұрын
Yay! Another refactoring video! Hope this video does well.
@git-amend
@git-amend 5 ай бұрын
You know it!
@fokeyjo
@fokeyjo 5 ай бұрын
I'm chuffed that I at least managed to do a generator and factory for my spawners in a game jam recently. Though beyond that it got a little scrappy because of the pace! It was a sort-of RTS-cum-tower-defence, and where I got stuck was what you do with multiple things attacking a unit, and also balancing the game where things can attack from different distances
@git-amend
@git-amend 5 ай бұрын
Nice... I guess in a Game Jam scenario you do what you gotta do! Sounds fun though.
@shrimpindustries
@shrimpindustries 5 ай бұрын
Hey, just wanted to say that this is some amazing content right there. Been watching your vids for some time and these are still some of the most useful, real-world usecases of programming patterns and more advanced coding techniques. No other creators bother to teach actual programming that is used in gamedev day-jobs, but stick to solo-dev, cutting-corners BS ^^ I certainly appreciated another take on that. Keep up the good work, hope your channel keeps on growing!
@git-amend
@git-amend 5 ай бұрын
Thanks for the comment, I appreciate that! Lots more to come!
@DissolvedMotions
@DissolvedMotions 5 ай бұрын
Absolutely fantastic video! 🤩 More just like this please!
@git-amend
@git-amend 5 ай бұрын
Thank you! Will do!
@radishmonster2760
@radishmonster2760 5 ай бұрын
Yep, this new format is very useful.
@git-amend
@git-amend 5 ай бұрын
Glad you think so!
@notkieran2259
@notkieran2259 5 ай бұрын
10/10 you always knock these videos out of the park! good practices for audio sounds like a fun topic to explore!
@git-amend
@git-amend 5 ай бұрын
Thank you!
@techdave99
@techdave99 5 ай бұрын
I followed along with the video. Took a while, but in the end it helped me understand the various patterns better. Also, it gave me a start on setting up an enemy spawner. Great stuff🤩😎
@git-amend
@git-amend 5 ай бұрын
Awesome, glad to hear that!
@Broudy001
@Broudy001 5 ай бұрын
This is fantastic. This is really helpful for me. And as much as I like surprises, an Audio System would be interesting as well
@git-amend
@git-amend 5 ай бұрын
Great to hear! Something interesting coming next week!
@k3ln
@k3ln 5 ай бұрын
this is one of the best videos so far and they're pretty great all of them, so congrats!
@git-amend
@git-amend 5 ай бұрын
Thanks for the kind words!
@agrandcanyonoffucksgiven2776
@agrandcanyonoffucksgiven2776 5 ай бұрын
This was a fantastic video. More refactoring videos with more advanced patterns. Great channel!
@git-amend
@git-amend 5 ай бұрын
Thank you!
@bromanguy
@bromanguy 5 ай бұрын
Love the refactor vids! Great insight and examples of how to write clean and expandable code. Thanks as always!
@git-amend
@git-amend 5 ай бұрын
My pleasure! Glad you liked it!
@prometheus1100
@prometheus1100 5 ай бұрын
Love this! Definitely keep this series going i.m.o. As for a topic suggestion, what about an async/coroutine deep dive?
@git-amend
@git-amend 5 ай бұрын
Great suggestion! I'll put that on the list!
@metsker4876
@metsker4876 5 ай бұрын
I'd love to learn more about audio systems c: Thanks for the video, never thought of using a strategy pattern with scriptable objects, it can be very useful
@git-amend
@git-amend 5 ай бұрын
Glad it was helpful! Audio will be a topic soon for sure!
@iliqnikushev3820
@iliqnikushev3820 5 ай бұрын
What do you think about wrapping the Action instead of the command? That way the builder can still return the concrete class, not the interface BattleCommand.Build() { command.action = CommandActionDecorator.Wrap(command.action); // logging, etc return command; } for more flexibility, CommandActionDecorator has a Dictionary handlers that the user can register additional decoration for specific types. If none present - return the action
@git-amend
@git-amend 5 ай бұрын
That might work in some scenarios, and might even be an improvement. But I also envision the BattleCommand becoming more complex, even having multiple Actions such as a pre and post action. I think it would really depend on the requirements of the user, but it's definitely something to consider.
@TheAndyW19
@TheAndyW19 5 ай бұрын
Amazing as always. Keep it up!
@git-amend
@git-amend 5 ай бұрын
Thank you!
@rutchjohnson
@rutchjohnson 5 ай бұрын
This is amazing! Great idea for a video.
@git-amend
@git-amend 5 ай бұрын
Thanks! Glad you enjoyed it!
@ewwitsantonio
@ewwitsantonio 5 ай бұрын
Great video! I'm curious where you've learned most of these patterns and how you developed a sense for when to use them or not. Were there any particular learning resources that helped you guide you?
@git-amend
@git-amend 5 ай бұрын
Mostly it comes from experience in software engineering. One good place I can recommend is refactoring.guru/
@ewwitsantonio
@ewwitsantonio 5 ай бұрын
@@git-amend Thanks for the link! Appreciate it.
@MrOfearos
@MrOfearos 5 ай бұрын
Amazing! As per topics for future videos- how to handle card based games, both in terms of having many instances of cards with variations and global/local stats, and in terms of handling holders/placements etc. :)
@git-amend
@git-amend 5 ай бұрын
Not a bad idea, I'll write that one down!
@MrOfearos
@MrOfearos 5 ай бұрын
@@git-amend legend!
@AngersFiction
@AngersFiction 5 ай бұрын
Great content as usual. I swear, I'm going to use these tips and definitely not leave my code as spaghetti.
@git-amend
@git-amend 5 ай бұрын
Haha awesome, glad to hear that!
@-Engineering01-
@-Engineering01- 4 ай бұрын
The first code this dude wrote was more readable to me, I mean for solo devs it's an overkill, wasting of cpu cycles, abstraction nightmare and makes code harder to debug. I think it's like using a bazooka to kill an ant for small scale games, but good fit for big sized projects like MMOs. As backend devs we call this as abstraction hell. Big fat IAbstractionSpringBeanFactories are killing our sector that's why we are started to seeing more adaptation for golang like languages to reduce abstraction hell. Thanks ! Btw it'd be great if you could make a rewiev video on Casey Muratori's "Clean code horrible performance" video.
@git-amend
@git-amend 4 ай бұрын
I understand your perspective; for solo developers or small-scale projects, abstraction can sometimes feel like overkill. I'll have a look at that video you mentioned.
@erlexfortin3413
@erlexfortin3413 4 ай бұрын
ohhh! I love this content. so juicy. thank you!
@git-amend
@git-amend 4 ай бұрын
You're welcome!
@nixonscherbarth1974
@nixonscherbarth1974 5 ай бұрын
Thanks a lot! I really like this format a lot, yes it covers everything you have already covered on this channel, but it is a great refresher and gives us a lot of use cases. It isn’t only about understanding, but also about knowing when to use them. To be honest, If this was my project that you showed there, I would have used flyweight an that is it 🙂‍↔️. But yea thank you so much for that! I wish you a wonderful week. By the way, there is a big big discussion in my friend group. We are Dev Students studying Game Design, but we found our passion is in programming. So we want to work in the industry after finishing our bachelors. I really am in love with Unity, but I am kind of not too sure how the future will look like. Can you still recommend pushing in unity? :)
@git-amend
@git-amend 5 ай бұрын
Thanks for the comment! In regard to your question, I personally think that Unity has a bright future - but to be honest, I wouldn't worry too much about the game engine itself. Once your skill level as a programmer reaches a certain level, it won't matter what engine you want to use - in a sense you will become language agnostic - the principles of software engineering and things like programming patterns apply to everything.
@nixonscherbarth1974
@nixonscherbarth1974 5 ай бұрын
@@git-amend I value your reply a lot. I owe you a coffee :)!
@git-amend
@git-amend 5 ай бұрын
@@nixonscherbarth1974 Haha cheers!
@TheKr0ckeR
@TheKr0ckeR 5 ай бұрын
How would you approach that if you have different enemy prefabs? Would you create new factories like RangedEnemy etc?
@git-amend
@git-amend 5 ай бұрын
I wouldn't necessarily make a new factory for every enemy type, but it really depends on the context of your larger game. What I might do instead is add an additional public method for the different type of enemy if it is significantly different than the first one. Another approach is to have factory return you a Builder instead of a completely configured enemy - that way the consumer class can configure the enemy as needed.
@raghuvanshagarwal9079
@raghuvanshagarwal9079 5 ай бұрын
Bro, I just found gold in form of your channel
@git-amend
@git-amend 5 ай бұрын
Welcome aboard! Thanks for the comment!
@Thomas-yz3ny
@Thomas-yz3ny 5 ай бұрын
Agree, it's way underrated! Love this channel! I'm a professional developer and it's a blessing to watch his content.
@aaatthh
@aaatthh 5 ай бұрын
Another amazing video✅ I could guess some of the ways because of the all amazing videos before, keep up 👍
@git-amend
@git-amend 5 ай бұрын
Awesome! Thank you!
@damonfedorick
@damonfedorick 5 ай бұрын
Nice.
@git-amend
@git-amend 5 ай бұрын
Thank you! Cheers!
@Wanderlust_Duo
@Wanderlust_Duo 5 ай бұрын
You are awesome, dude!😎
@git-amend
@git-amend 5 ай бұрын
Thanks! Glad you liked the vid!
@lordfrazao1026
@lordfrazao1026 5 ай бұрын
5:56 How do you put those icons in the hierarchy? Is it an asset? In addition, great video, high quality content!
@git-amend
@git-amend 5 ай бұрын
I've added a link to that Asset into the description, it's a handy tool you can buy for cheap. Also, Warped Imagination has a video on his channel about how to do that yourself.
@RafaelAzriaiev-kv9qm
@RafaelAzriaiev-kv9qm 5 ай бұрын
Amazing vids man love theam
@git-amend
@git-amend 5 ай бұрын
Thank you! I appreciate that!
@Hazzel31337
@Hazzel31337 5 ай бұрын
good video thank you
@git-amend
@git-amend 5 ай бұрын
Glad you enjoyed it
@tst2648
@tst2648 5 ай бұрын
audio systems "sounds" great :D
@git-amend
@git-amend 5 ай бұрын
Lol +1 points
@inkofthedragon
@inkofthedragon 5 ай бұрын
How would you go about spawning the prefabs into specific locations in the game world using the strategy pattern you've setup? Would you create a list of transforms in a scriptable object? Or something else? Thanks
@git-amend
@git-amend 5 ай бұрын
Yeah, I'd probably make a strategy that exposed a list of transforms that could be configured in the editor.
@inkofthedragon
@inkofthedragon 5 ай бұрын
@@git-amend how would you expand this in order to have a list of transforms for each different enemy type in a clean way? Like a list for the ogres and for the goblins. Thanks again
@git-amend
@git-amend 5 ай бұрын
@@inkofthedragon It depends what you are doing I guess. You could just create a different spawner for each type if you need them separated.
@inkofthedragon
@inkofthedragon 5 ай бұрын
@@git-amend hmm I tried playing around using the Placement Strategy Scriptable Object approach. But because it's a SO, I can't drag transforms in the game world into it
@git-amend
@git-amend 5 ай бұрын
@@inkofthedragon You'll likely have to save the waypoints as a prefab to use this approach.
@Anerisian
@Anerisian 5 ай бұрын
Hi Adam, how about Blackbord pt2.
@git-amend
@git-amend 5 ай бұрын
Maybe… what would you like to see in that?
@Anerisian
@Anerisian 5 ай бұрын
@@git-amend Would be interesting to see how you would combine it with the state machine. How to make it a bit less boilerplate so you can more quickly set and get variables. You’ve touched on also the scriptable object, I guess that’s key to reduce some of the setup in script. Thanks for your great content, by the way!
@Anerisian
@Anerisian 5 ай бұрын
also how to combine/interface with the Ipredicates and such, I think there are probably some neat tricks
@git-amend
@git-amend 5 ай бұрын
@@Anerisian Hmm, yes that's a good idea.
@justlama0
@justlama0 5 ай бұрын
nice
@git-amend
@git-amend 5 ай бұрын
Thank you!
@crazyfox55
@crazyfox55 5 ай бұрын
The flyweight and strategy design patterns seem like a good fit. However, is the command pattern really needed?
@git-amend
@git-amend 5 ай бұрын
Well, I can't force anyone to adopt a specific implementation in their project, just offer suggestions on how I'd approach it. I certainly would not pass around actions as string values and have a series of conditional logic to handle those strings, and I also would not hard code that behaviour into the Enemy class. Of course there is always more than one way to solve a problem, and often will need to be considered in the larger context of the entire project.
The Unity HACK that the PROS know
21:27
git-amend
Рет қаралды 17 М.
Visitor: How I Mastered the Toughest Programming Pattern
12:59
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 89 МЛН
Amazing remote control#devil  #lilith #funny #shorts
00:30
Devil Lilith
Рет қаралды 16 МЛН
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН
Improve Your Unity Code with MVC/MVP Architectural Patterns
15:32
Better Singletons in Unity C#
14:08
git-amend
Рет қаралды 9 М.
UniTask: How It Replaces Coroutines, Tasks and Awaitable
24:49
Clean Code is SLOW But REQUIRED? | Prime Reacts
28:22
ThePrimeTime
Рет қаралды 322 М.
Mediator Pattern - Reduce Chaotic Dependencies
15:47
git-amend
Рет қаралды 9 М.
A few common code smells to be aware of and how to fix them
6:32
The Shaggy Dev
Рет қаралды 14 М.
The cloud is over-engineered and overpriced (no music)
14:39
Tom Delalande
Рет қаралды 691 М.
EASY Stats and Modifiers in Unity | Broker Chain Pattern
16:05
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 89 МЛН