6 Code Smells REFACTORED to Patterns!

Поділитися
Вставка
  • Опубліковано 20 січ 2025

КОМЕНТАРІ • 133

  • @git-amend
    @git-amend  7 місяців тому +16

    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 7 місяців тому +36

    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 7 місяців тому +2

      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  7 місяців тому +1

      Thanks for the comment! Glad you enjoyed the vid!

  • @thehuggz-i9k
    @thehuggz-i9k 7 місяців тому +8

    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  7 місяців тому +1

      Glad you like them!

  • @sima19995
    @sima19995 7 місяців тому +20

    Ever since I started watching your videos my programming skills have literally skyrocketed. Your videos are a godsend. Unfortunately UA-cam 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  7 місяців тому +4

      Thanks for the comment! Great tip too, I totally missed that optimization while refactoring, good catch!

    • @ryaz4704
      @ryaz4704 7 місяців тому +1

      ​@@git-amenda part 2 video incoming?

  • @NinjaPodslash
    @NinjaPodslash Місяць тому

    I AM SO HAPPY I STUMBLED UPON YOUR CHANNEL! I recently made a game during a game project for my school that took 3 weeks, and i was pretty happy about with how it went. When I then came back to the project, I realized that everything was a complete mess. Every component was soo tightly coupled to eachother that every change i made meant i needed to change 10 other scripts. We slightly touched on design patterns in school but not enough to really make a difference in how i code. I did some research on different patterns and after stumbling upon your channel and watching almost all of your videos i realized i would need to break my baby (the game) and put it back together for the better.
    For the longest time i've been looking for a channel that teaches good coding practices and standards but all i've ever found are videos that are either too beginner friendly or don't touch on certain topics because they're "too complicated". YOU ARE DOING GODS WORK HERE! THANK YOU FOR THESE AMAZING VIDEOS!

    • @git-amend
      @git-amend  Місяць тому +1

      I'm very happy to hear that. Actually the video I'm working on right now for Sunday is very similar to this one, it's all about refactoring, so stay tuned!

  • @MarushiaDark316
    @MarushiaDark316 7 місяців тому +9

    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  7 місяців тому

      Glad it was helpful!

  • @franciscooteiza
    @franciscooteiza 7 місяців тому +8

    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  7 місяців тому

      Great to hear! Thanks for the comment!

  • @Fitz0fury
    @Fitz0fury 7 місяців тому +2

    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  7 місяців тому

      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.

  • @MaximumAxiom
    @MaximumAxiom 7 місяців тому +1

    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  7 місяців тому +1

      Thanks! Will probably do a few more like this in the future

  • @notkieran2259
    @notkieran2259 7 місяців тому

    10/10 you always knock these videos out of the park! good practices for audio sounds like a fun topic to explore!

  • @jeffreyhersh908
    @jeffreyhersh908 7 місяців тому

    Thank you for your videos. There is a dearth of intermediate to advanced tutorials for Unity on UA-cam. 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  7 місяців тому +1

      You're very welcome!

  • @owencoopersfx
    @owencoopersfx 7 місяців тому

    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  7 місяців тому

      Glad you like it!

  • @techdave99
    @techdave99 7 місяців тому

    Worth watching multiple times. The flyweight pattern used here helped me understand where it can be used.

    • @git-amend
      @git-amend  7 місяців тому

      Thanks! Maybe next time we'll tackle something a bit more complex as well.

  • @cloudPvP
    @cloudPvP 7 місяців тому

    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

  • @donmacsween2842
    @donmacsween2842 7 місяців тому

    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  7 місяців тому

      Glad it was helpful!

  • @k3ln
    @k3ln 7 місяців тому

    this is one of the best videos so far and they're pretty great all of them, so congrats!

    • @git-amend
      @git-amend  7 місяців тому

      Thanks for the kind words!

  • @danielruppert9585
    @danielruppert9585 24 дні тому

    Love refactoring, please more of these ❤

    • @git-amend
      @git-amend  23 дні тому

      Lots more to come, in fact tomorrow's video will have some refactoring in it!

  • @OskGame
    @OskGame 7 місяців тому

    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  7 місяців тому +1

      Glad it was helpful!

  • @4rcant
    @4rcant 7 місяців тому

    Most valuable channel on youtube for me right now

    • @git-amend
      @git-amend  7 місяців тому

      Thank you so much!

  • @TheArghnono
    @TheArghnono 7 місяців тому

    You really help me push my Unity programming to the next level.

    • @git-amend
      @git-amend  7 місяців тому +1

      Great, glad to hear that!

  • @shrimpindustries
    @shrimpindustries 7 місяців тому

    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  7 місяців тому

      Thanks for the comment, I appreciate that! Lots more to come!

  • @techdave99
    @techdave99 7 місяців тому

    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  7 місяців тому

      Awesome, glad to hear that!

  • @melipefello
    @melipefello 7 місяців тому

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

  • @darrencook7168
    @darrencook7168 7 місяців тому

    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  7 місяців тому +1

      I’ve got a video on that topic coming soon!

  • @MarkRiverbank
    @MarkRiverbank 7 місяців тому

    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  7 місяців тому

      Thanks for that! I know exactly what you mean! Glad to have you here.

  • @successor0
    @successor0 7 місяців тому +1

    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  7 місяців тому

      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.

  • @bromanguy
    @bromanguy 7 місяців тому

    Love the refactor vids! Great insight and examples of how to write clean and expandable code. Thanks as always!

    • @git-amend
      @git-amend  7 місяців тому +1

      My pleasure! Glad you liked it!

  • @DissolvedMotions
    @DissolvedMotions 7 місяців тому +1

    Absolutely fantastic video! 🤩 More just like this please!

    • @git-amend
      @git-amend  7 місяців тому

      Thank you! Will do!

  • @TheKr0ckeR
    @TheKr0ckeR 7 місяців тому

    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  7 місяців тому

      Thanks for the comment. That's an interesting idea for a video, I'll give it some thought!

  • @agrandcanyonoffucksgiven2776
    @agrandcanyonoffucksgiven2776 7 місяців тому +1

    This was a fantastic video. More refactoring videos with more advanced patterns. Great channel!

  • @정동우-n2x
    @정동우-n2x 7 місяців тому +1

    I like this content
    Because looking at the mechanism of code modification helps beginners like me

    • @git-amend
      @git-amend  7 місяців тому +1

      Great, glad it's helpful! I'm glad this video resonates with people who are at different levels.

  • @prometheus1100
    @prometheus1100 7 місяців тому

    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  7 місяців тому +1

      Great suggestion! I'll put that on the list!

  • @Broudy001
    @Broudy001 7 місяців тому

    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  7 місяців тому

      Great to hear! Something interesting coming next week!

  • @metsker4876
    @metsker4876 7 місяців тому

    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  7 місяців тому

      Glad it was helpful! Audio will be a topic soon for sure!

  • @TheAndyW19
    @TheAndyW19 7 місяців тому

    Amazing as always. Keep it up!

  • @rutchjohnson
    @rutchjohnson 7 місяців тому

    This is amazing! Great idea for a video.

    • @git-amend
      @git-amend  7 місяців тому

      Thanks! Glad you enjoyed it!

  • @aaatthh
    @aaatthh 7 місяців тому

    Another amazing video✅ I could guess some of the ways because of the all amazing videos before, keep up 👍

    • @git-amend
      @git-amend  7 місяців тому

      Awesome! Thank you!

  • @fokeyjo
    @fokeyjo 7 місяців тому

    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  7 місяців тому +1

      Nice... I guess in a Game Jam scenario you do what you gotta do! Sounds fun though.

  • @radishmonster2760
    @radishmonster2760 7 місяців тому

    Yep, this new format is very useful.

    • @git-amend
      @git-amend  7 місяців тому

      Glad you think so!

  • @erlexfortin3413
    @erlexfortin3413 6 місяців тому

    ohhh! I love this content. so juicy. thank you!

  • @techdave99
    @techdave99 7 місяців тому

    Yay! Another refactoring video! Hope this video does well.

  • @MrOfearos
    @MrOfearos 7 місяців тому

    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  7 місяців тому +1

      Not a bad idea, I'll write that one down!

    • @MrOfearos
      @MrOfearos 7 місяців тому

      @@git-amend legend!

  • @TheKr0ckeR
    @TheKr0ckeR 7 місяців тому

    How would you approach that if you have different enemy prefabs? Would you create new factories like RangedEnemy etc?

    • @git-amend
      @git-amend  7 місяців тому

      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.

  • @carnagebfr
    @carnagebfr 7 місяців тому +8

    Bro, I just found gold in form of your channel

    • @git-amend
      @git-amend  7 місяців тому +2

      Welcome aboard! Thanks for the comment!

    • @Thomas-yz3ny
      @Thomas-yz3ny 7 місяців тому

      Agree, it's way underrated! Love this channel! I'm a professional developer and it's a blessing to watch his content.

  • @Wanderlust_Duo
    @Wanderlust_Duo 7 місяців тому

    You are awesome, dude!😎

    • @git-amend
      @git-amend  7 місяців тому +1

      Thanks! Glad you liked the vid!

  • @ewwitsantonio
    @ewwitsantonio 7 місяців тому

    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  7 місяців тому

      Mostly it comes from experience in software engineering. One good place I can recommend is refactoring.guru/

    • @ewwitsantonio
      @ewwitsantonio 7 місяців тому

      @@git-amend Thanks for the link! Appreciate it.

  • @nixonscherbarth1974
    @nixonscherbarth1974 7 місяців тому

    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  7 місяців тому

      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 7 місяців тому

      @@git-amend I value your reply a lot. I owe you a coffee :)!

    • @git-amend
      @git-amend  7 місяців тому

      @@nixonscherbarth1974 Haha cheers!

  • @iliqnikushev3820
    @iliqnikushev3820 7 місяців тому

    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  7 місяців тому

      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.

  • @lordfrazao1026
    @lordfrazao1026 7 місяців тому

    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  7 місяців тому +1

      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.

  • @AngersFiction
    @AngersFiction 7 місяців тому

    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  7 місяців тому

      Haha awesome, glad to hear that!

  • @-Engineering01-
    @-Engineering01- 6 місяців тому

    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  6 місяців тому +1

      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.

  • @inkofthedragon
    @inkofthedragon 7 місяців тому

    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  7 місяців тому +1

      Yeah, I'd probably make a strategy that exposed a list of transforms that could be configured in the editor.

    • @inkofthedragon
      @inkofthedragon 7 місяців тому

      @@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  7 місяців тому

      @@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 7 місяців тому

      @@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  7 місяців тому

      @@inkofthedragon You'll likely have to save the waypoints as a prefab to use this approach.

  • @damonfedorick
    @damonfedorick 7 місяців тому +1

    Nice.

    • @git-amend
      @git-amend  7 місяців тому

      Thank you! Cheers!

  • @RafaelAzriaiev-kv9qm
    @RafaelAzriaiev-kv9qm 7 місяців тому

    Amazing vids man love theam

    • @git-amend
      @git-amend  7 місяців тому

      Thank you! I appreciate that!

  • @Hazzel31337
    @Hazzel31337 7 місяців тому

    good video thank you

    • @git-amend
      @git-amend  7 місяців тому

      Glad you enjoyed it

  • @tst2648
    @tst2648 7 місяців тому

    audio systems "sounds" great :D

  • @crazyfox55
    @crazyfox55 7 місяців тому

    The flyweight and strategy design patterns seem like a good fit. However, is the command pattern really needed?

    • @git-amend
      @git-amend  7 місяців тому +2

      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.

  • @Anerisian
    @Anerisian 7 місяців тому

    Hi Adam, how about Blackbord pt2.

    • @git-amend
      @git-amend  7 місяців тому +1

      Maybe… what would you like to see in that?

    • @Anerisian
      @Anerisian 7 місяців тому +1

      @@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 7 місяців тому

      also how to combine/interface with the Ipredicates and such, I think there are probably some neat tricks

    • @git-amend
      @git-amend  7 місяців тому +1

      @@Anerisian Hmm, yes that's a good idea.

  • @justlama0
    @justlama0 7 місяців тому

    nice