Refactoring A Tower Defense Game In Python // CODE ROAST

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • This video is a refactoring of a Tower Defense Game written in Python. In particular, I cover a few game architecture aspects and apply them to reduce the coupling in the example code. Get 20% off the Pro version of Tabnine, this video’s sponsor: bit.ly/ARJAN20. If you're a student, you can get Tabnine Pro for free here: www.tabnine.com/students.
    The code I worked on in this example is available here: github.com/ArjanCodes/2021-co....
    💡 Here's my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
    🎓 Courses:
    The Software Designer Mindset: www.arjancodes.com/mindset
    The Software Designer Mindset Team Packages: www.arjancodes.com/sas
    The Software Architect Mindset: Pre-register now! www.arjancodes.com/architect
    Next Level Python: Become a Python Expert: www.arjancodes.com/next-level...
    The 30-Day Design Challenge: www.arjancodes.com/30ddc
    🛒 GEAR & RECOMMENDED BOOKS: kit.co/arjancodes.
    🚀If you want to take a quantum leap in your software development career, check out my course The Software Design Mindset: www.arjancodes.com/mindset.
    💬 Join my Discord server here: discord.arjan.codes
    🐦Twitter: / arjancodes
    🌍LinkedIn: / arjancodes
    🕵Facebook: / arjancodes
    👀 Channel code reviewer board:
    - Yoriz
    - Ryan Laursen
    - Sybren A. Stüvel
    🔖 Chapters:
    0:00 Intro
    0:47 Overview of the original code
    3:39 Code analysis
    7:38 A few quick minor fixes
    14:34 About game engines
    16:22 Creating a simple game engine
    23:46 Game object structure
    27:12 Creating the Tower Defense game subclass
    31:28 Communication between game objects
    35:57 Final thoughts
    #arjancodes #softwaredesign #python
    DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!

Komentáře • 402

  • @ArjanCodes
    @ArjanCodes  Před 2 lety +154

    This video was still a bit longer than I intended. I didn't really discuss this in the video, but if you know any good game engines for Python, feel free to share them here!

    • @reddit7372
      @reddit7372 Před 2 lety +12

      This is pure gold! This approach definitely brings out a different and interesting approach in talking about code. Thanks!

    • @MyEconomics101
      @MyEconomics101 Před 2 lety +10

      This video is the best python tutorial ever, imho.

    • @josephvictory9536
      @josephvictory9536 Před 2 lety +21

      Really, i wish it was even longer. This is to me a decoupling masterclass.
      You are a gifted instructor and i felt like as it finished i was now getting into it more thoroughly and was waiting to see how you refactored the remaining globals. I felt that it would be as straightforward as adding them into the game function as a configuration with defaults since they will only have one instance.
      What i love about this series is the application for things like event handlers, classifiers and abstractions in creating more general game classes. I am only a bit better than a beginner and I have a hard time imagining the efficient usecase for abstract classes like Enum even though i can understand how much more efficient it is to use it. I learn much more from this type of application even though i know it represents more work on your end. So thank you very much.
      It is honestly some of the best instruction i have seen, with very calm delivery and overall i really love this series.
      What i took away was these four things around decoupling:
      1) Use gamestates or event handlers instead of global variables (i have a Tk project right now that could use this desperately)
      2) Config is for when behavior is the same but attributes are different whereas inheritance is for when behavior is different
      3) Reduce indentation level when possible by establishing basecases
      4) Localize __name__ = '__main__'

    • @Tawnos_
      @Tawnos_ Před 2 lety +14

      The video could have been 2-4x longer and it still would have been engaging. You have a great pace and way of explaining decisions and tradeoffs that come up in program architecture and refactoring while not getting overly bogged down. Only engine I've encountered is Pygame/Pygin (Pygame Engine), but I haven't played with it.

    • @andydataguy
      @andydataguy Před 2 lety +3

      This is gold. You're amazing. Seriously make a serious that puts you in position to be the "Decoupling Master."
      Inspired to donate. Thanks for making these videos!
      You're much, much more than that. I just use it as an example as I don't know if you realize just how special your content really actually is

  • @EBagattack
    @EBagattack Před 2 lety +465

    Nothing more satisfying than deleting dozens of lines of code during a nice refactor. Warms the soul.

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +23

      Haha, can’t agree more!

    • @rban123
      @rban123 Před 2 lety +4

      so true! last week at work I deleted I shaved like 20 or 30 unecessary lines from my API code and it's so much cleaner now

    • @IceBoltGamingIBG
      @IceBoltGamingIBG Před 2 lety +7

      i refactored an old tower defense game once. it went from 2800 lines to 1500, i had to delete over one hundred lines at once
      honestly cant believe i coded like that back then

    • @Golgafrincham
      @Golgafrincham Před 2 lety +3

      Haha, so true...! I remember a couple of years back when working on with C. When I started working with this specific software the code base was one file with about 6000 lines of code, when I finished the whole code base was about 3000 lines and was using several different source-files... I felt so got damn pleased... :D

    • @nobodythenobody9779
      @nobodythenobody9779 Před 2 lety +4

      Dude what, I always feel bad deleting a lot of code, wasted time, good bye little code friends

  • @macchicken98
    @macchicken98 Před 2 lety +656

    I think a Game Engine Design series would be extremely valuable to learn about design patterns. I‘d even pay for that when done by you

    • @piyh3962
      @piyh3962 Před 2 lety +16

      Yandere dev code review is really great if you like this type of content

    • @budsyremo
      @budsyremo Před 2 lety +2

      I second that .

    • @Firedog_Alpha
      @Firedog_Alpha Před 2 lety +1

      This 100%

    • @TheSpacecraftX
      @TheSpacecraftX Před 2 lety +5

      Game engines from scratch are absolutely gigantic in scope.

    • @DaminGamerMC
      @DaminGamerMC Před 2 lety +9

      I recommend a channel called The Cherno then

  • @mattduffyw99
    @mattduffyw99 Před 2 lety +99

    These are so great. As a self-taught dev who is always striving to improve, it's incredibly helpful to see "working" code being refined like this.

  • @flyingcircle526
    @flyingcircle526 Před 2 lety +184

    Haven't watched the whole thing but at 9:55 you actually change the meaning of the code in the update function and do the exact opposite. I hope you catch that later on!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +35

      Well spotted! Indeed the ‘not’ should not be there. In the final version that’s on Git, I think I actually used the game state for this.

    • @BasicallySteve23
      @BasicallySteve23 Před 2 lety +42

      Came looking for this comment :)

    • @NedCollyer
      @NedCollyer Před 2 lety +9

      There are dozens of us. DOZENS!

    • @DavidvanDeijk
      @DavidvanDeijk Před 2 lety +4

      @@BasicallySteve23 did you also watch to the end to see if he mentions it himself before going to the comments?

    • @BasicallySteve23
      @BasicallySteve23 Před 2 lety +2

      @@DavidvanDeijk I did not ;)

  • @Fevir
    @Fevir Před 2 lety +52

    I love this Code Roast format.

  • @nicolabombace2004
    @nicolabombace2004 Před 2 lety +17

    Seasoned C++ dev here. Came here to see some real life Python, stayed for the refactoring and showing the value of good architecture. Great work! I second all the comments about a game engine series :)

  • @moopoo123
    @moopoo123 Před 2 lety +57

    This is so useful. More videos with detailed code reviews like this please. I think you might have found an interesting niche.

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +7

      Thanks Jason, glad you like it and will do!

  • @ractheworld
    @ractheworld Před 2 lety +48

    A game engine series would be great. Game engines cover so much ground that once you're comfortable with them 'Enterprise Software' seems like a walk in the park.

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +7

      Fully agree!

    • @nwoDekaTsyawlA
      @nwoDekaTsyawlA Před 2 lety +3

      I also agree, games are inherently complex and lots of things happen at once. Lots of programming tutorials have toy examples, but with a working game examples are closer to the "real thing" and also easier to teach.

  • @JohnFallot
    @JohnFallot Před 2 lety +33

    A video series on game development with python would be fantastic!
    I’ve had some successes with pygame, but I’ve seen nothing on how to handle player levels and what in some other games might constitutes evolutions, upgrades, or tiers). The same goes for keeping player movement fluid and camera tracking.
    Happy to dive into it on your dedicated Discord channel!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +6

      Thanks and noted!

    • @costelinha1867
      @costelinha1867 Před 2 lety

      @@ArjanCodes Indeed, it would be valuable to me since I'm currently working on a simple space shooter on pygame as my first real project in it. Right now: I'm focusing on improving the structure, it's still probably not as good as it could be, but at least it's way better than having all sorts of classes in a single python file, making it a complete nightmare to navigate through said script and find what you want.

  • @Cookie-mv2hg
    @Cookie-mv2hg Před 2 lety +6

    This is the my favourite series! I always has trouble "reading" others code as a beginner.
    Being able to have an expert explain the reading process by cutting all parts apart is very, very helpful!

  • @valloway
    @valloway Před 2 lety +8

    I appreciated the positive attitude in the "Overview" section

  • @gcl2783
    @gcl2783 Před 2 lety +8

    You know what would be cool? A short playlist for building games. A rewrite the 1980s might be interesting: Making a text based game (e.g. Zork), top down rpg (e.g. Dragon Quest or Legend of Zelda), and a side scrolling platformer.

  • @Electricity0
    @Electricity0 Před 2 lety +4

    I"m a JS/TS/C# developer and don't even know how to write Python but these principles seem to be language agnostic. Very pleasing to watch!

  • @spaderkungskuk
    @spaderkungskuk Před 2 lety +13

    The game engine’s Update() and Paint() are concepts nicely covered by The Coding Train, Coding Math, and One Lone Coder who makes a cpp game engine. I think Decoupling is the most valuable lesson because of the complexity, size and typical “need” of globals from beginners.

  • @AlphaWatt
    @AlphaWatt Před 2 lety +3

    I would absolutely love to see your take on more gaming, complicated, types of projects. Thanks for the walk through of this one! And thanks/great job to the person who submitted their code for review!

  • @almond5560
    @almond5560 Před 2 lety +28

    Everything you said in 14:34, in the "About game engines" section, I am trying to juggle in my own game. Especially coupling and event handling. If you could make a video dealing with these, or a whole series about game engines, it would be so helpful.
    Your videos have been a great source of help thus far. Thanks for the great content, Arjan!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +1

      Thank you and you’re welcome!

    • @newf_gg1230
      @newf_gg1230 Před 2 lety +1

      @@Borgilian Modernization happens for a reason. Even with low level programming you'll still want to decouple your code as much as possible. The irony of your statement is that these "experienced" programmers all retire in the next decade and all of the forward thinking people will have the tools to use their "high level" languages in virtually the same capacity as a low level language with some outlier exceptions.
      Accept forward change, or be left in the dust.
      The fact that a basic python refactor video has triggered you this hard speaks bundles about your state of mind. Go get help, you need to be medicated (I mean this with no sarcasm, it's abnormal).

    • @zapazap
      @zapazap Před 2 lety

      @@Borgilian Woah... easy on the scare quotes son.
      Are you contending that our host is a crappy programmer? And if so, on what grounds?

  • @thevoid1463
    @thevoid1463 Před 2 lety +3

    Loved the last video, was genuinely excited when I saw this one - keep them coming!

  • @manuelpineda9067
    @manuelpineda9067 Před 2 lety +1

    Arjan makes these coding videos as exciting as they can be. This is amazing.

  • @M0r1tz02
    @M0r1tz02 Před 2 lety

    Really nice of you to not just flame the hell outta the programmer but positively criticise the code!

  • @amir3515
    @amir3515 Před 2 lety

    This is huge! I am amazed at how much value just this one video provides. First of this kind of series I've come across. It's game changing and a lot more helpful than the typical tutorial or language feature review channels. Really appreciate it!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Great to hear & glad this is helpful to you!

  • @jvsvogler
    @jvsvogler Před 2 lety

    Just stumbled upon this video, and I gotta say that this is SO HELPFUL! Hope you get your 100k subs soon and many more!!
    Thank you so much!

  • @Ferenc-Racz
    @Ferenc-Racz Před 2 lety

    This code roast series the best! I just subscribed. Thank you for these interesting and professional videos.

  • @krzysztofkwiatkowski3224

    Awesome video. Seeing refactoring a real world example is priceless. I'm looking forward to the continuation of this.

  • @andidomi4335
    @andidomi4335 Před 2 lety +1

    Oh my gosh yes! A code review and improvement! More of these please if it is possible !!!

  • @jofofouj
    @jofofouj Před 2 lety

    Arjan Thank you for doing this series. It's fun to watch and your explanations are easy to understand. I'm learning quite a bit from it.

  • @GlitchedFailure
    @GlitchedFailure Před 2 lety

    Well done! Really enjoyed watching the refactor and hearing your explanations. Looking forward to more - keep up the effort!

  • @Dziaji
    @Dziaji Před 2 lety +55

    “If not done” is the same as “if done == False”, so you didn’t change the condition and flipped the logic to run the block if done instead of doing nothing if done.

    • @Gunth0r
      @Gunth0r Před 2 lety +4

      yeah, I've noticed that one as well.

    • @Pakitoz94
      @Pakitoz94 Před 2 lety +1

      @@Gunth0r me too...at 9:45 for those who wonder

    • @zapazap
      @zapazap Před 2 lety +3

      That's why we have unit tests, and run them as we refactor.

    • @SpecialeW
      @SpecialeW Před 2 lety +1

      I was yelling at my screen just now... 😅

    • @ilyaxi
      @ilyaxi Před 2 lety

      I almost questioned my existence when I saw that

  • @InfiniteQuest86
    @InfiniteQuest86 Před 2 lety +1

    Nice! Thanks for doing these! I'm getting ready to do a massive overhaul myself of a Python project. It's all research code doing some mathy things written by a bunch of people of differing experience levels. This provides me with some motivation and good ideas.

  • @jboe9159
    @jboe9159 Před 2 lety +1

    This is awesome! As a Jr. engineer seeing you refactor a decent size project is massively useful. Your refactoring of his if statements was a real eye opener for me.

  • @BartKevelham
    @BartKevelham Před 2 lety

    Hey Arjan, didn't know you made videos like this! Absolutely awesome. I can see that being helpful to many.
    The only thing I'd recommend doing (or rather would recommend to anyone else attempting a big refactor) is to frequently test that things still work. It wouldn't be the first time I've gotten ahead of myself, only to have a hard time figuring out where in the process I broke stuff.
    Subscribed :) Keep it up!

  • @zapazap
    @zapazap Před 2 lety +6

    It might be hard to find a well unit-tested project to refactor, but if you do: I would love to see a continual-test refactoring.

  • @dimaspaiva193
    @dimaspaiva193 Před 2 lety +12

    That was amazing!
    Please make a series about game dev!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +2

      Thank you Dimas, glad you liked it!

  • @theotherjim123
    @theotherjim123 Před 2 lety +8

    I've been trying to get better at python for a while now and I am always amazed when I learn something cool that I wish I knew about before. like at 11:02 where you show how python supports more complex comparisons like xmin < x < xmax.

  • @Phate777
    @Phate777 Před 2 lety

    Thank you Arjan. Love your voice really calm and easy to listen to.
    Learned a lot. Looking forward to other refactoring for something maybe not game related. (Web Development, Bigger Backend, Service)

  • @iliqnew
    @iliqnew Před 2 lety

    Thank you for this really practical example. Thank you Arjan and Gooshrlific so much

  • @Wqube
    @Wqube Před 2 lety

    This is great, I think the guy who sent this code in realized how poorly organized it was and knew that a lot of people can learn from his early mistakes! Great job!

  • @rethanon
    @rethanon Před 2 lety +1

    Great video as always, I always feel like I learn a lot (thanks to you I learned about type hinting), would’ve liked to see you test the game was still working after all the refactoring though! 😁

  • @alessandroferrari2166
    @alessandroferrari2166 Před 2 lety +3

    Cannot care less about game development but you're such a good teacher that made this so interesting! Thank you for these videos, Arjan! Again, groetjes uit Den Haag :P

  • @adamasher7301
    @adamasher7301 Před 2 lety +1

    This video is amazingly helpful as someone relatively new to coding looking for ways to improve. Even though I have no intention to make any games, I can see how these tips can be applied in my own projects. Thank you very much for this.

  • @nonyabusiness7794
    @nonyabusiness7794 Před 2 lety +18

    Can you explain Protocols more? I'm not seeing much information about them when I search and I didn't understand the benefit in this video. Thanks!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +11

      Absolutely! There’s a video coming very soon where I spend more time on Protocol classes.

  • @Insomnia_Wins
    @Insomnia_Wins Před 2 lety

    I found your channel because of this video. Keep up the good work; I really enjoy your content!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Thanks Andrew, glad you like the content!

  • @mrkeyzzz
    @mrkeyzzz Před rokem

    I just found your channel today. Great videos! I agree with the past commenters, a game engine series would be very beneficial. You're an exceptional instructor.

  • @JacinLowe
    @JacinLowe Před 2 lety +6

    This video was awesome. Please finish the refactor in a part 2. I need a tutor like you to teach me design patterns and strategy.

  • @BLSchaf
    @BLSchaf Před 2 lety

    Great to see how it's properly done!

  • @EduardoRodriguez-hz9re
    @EduardoRodriguez-hz9re Před 2 lety +3

    It will be very interesting and informative to see a video covering game engines from your experience. Thanks for sharing you knowledge. Im particularly learning a lot to code in an efficient and ordered way fron your videos. Thanks again. 👍

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Hi Eduardo, you’re most welcome - I’m happy the videos are helping you.

  • @fennecbesixdouze1794
    @fennecbesixdouze1794 Před 2 lety

    I haven't watched this video yet but my god, this format might have finally discovered an actual way to present code on CZcams in a way that isn't mid-numbingly boring.

  • @ryanman56
    @ryanman56 Před 2 lety

    I loved your explanation of including a game state which can trigger certain dependant events. I've been working a lot with React lately, so that really connected the web dev and game dev worlds for me. I'd love to see a game engine series from you, I bet there are many more design patterns that I'm overlooking

  • @sai1921
    @sai1921 Před 2 lety

    Game Engine and Framework design would be a great series. Even if it's talked above my head, seeing how more professional coders tackle problems can be in the back of my head when hobby shopping some of my own code

  • @hso24
    @hso24 Před 2 lety

    I would love to see you teaching design patterns in game dev
    You are a very good teacher! Keep up the good work!
    You might also consider streaming a full refactor. I would totally watch it!

  • @Original2BBB
    @Original2BBB Před 2 lety

    Very nice video! I have not coded in python in years but the concepts are universal and well explained, plus I enjoyed the 'real time' feeling

  • @apefu
    @apefu Před 2 lety

    This is a super nice format! Got this in my recommended feed after watching your exception videos.
    What I really enjoyed the most was the explanations. I do developer support in my team and I feel that succinctly explaining why something is not a good idea is where I struggle the most. This really helped in pointing out what I do wrong. Also, it was very entertaining :)
    Thanks for the great content!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +1

      Thanks, glad to hear you enjoyed this. I have more code roasts in the pipeline.

  • @kristjanjonsson3843
    @kristjanjonsson3843 Před 2 lety

    These videos are amazing! The more the merrier of code roasts

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Thanks! Glad you like the videos.

  • @baphnie
    @baphnie Před 2 lety +6

    I *really* appreciate you checking the cringe response at the beginning. I get so tired of this attitude out in the wild.

    • @nathanbrown2640
      @nathanbrown2640 Před 2 lety +2

      Completely agree - I'm realising I'm guilty of this with newer Devs, but remembering that they are learning and that I am also still learning makes a massive difference. Currently trying to therefore make the focus of my code reviews and pair programming focus on how they grow in knowledge, not just do we end up with code that I like.
      Wow, just reading how self-aggrandising that is when I say/type it out loud...

    • @baphnie
      @baphnie Před 2 lety

      @@nathanbrown2640 It’s not self aggrandizing to know you’re good at what you do. 😉

    • @KayOScode
      @KayOScode Před 2 lety +1

      As a new dev who is entering the industry with a lot of prior programming experience, I am learning new things every day. But one thing that confuses me still is this. I was given the assignment to load and save to a file format called HDF5. The api to interact with the library distributed by the developers of the format is horribly unintuitive so I made a series of abstractions to make it much easier for my serializer code to work with so as to not repeat code that could potentially do horrible things like buffer overflow. The whole abstraction set was only about 1.5k lines and I set it up to be extensible if we ever need more functionality from hdf5 in the future, you could just derive a class, slightly modify the functionality, and use it. During my code review to check in the entire serializer, my reviewer had issues with it because the abstractions were relatively complex and apparently all I needed to do was parse the format. So I ended up spending hours explaining the abstractions I made and why only to eventually have it accepted. But the main complaint I got is that I an thinking about a million things at once. Id be talking about one thing and Id say I made a different choice because it was faster, or I made a different choice because I wanted the abstractions to ensure there were no buffer overflows rather than the user of the library. Then when I add failsafes to the abstractions like bounds checking, I had to fight hard to get that accepted because apparently "the way I use the library in the serializer that condition wont be hit." The thing is, I wrote it such that I wanted arbitrary code to be able to use it safely so I dont understand why bounds checking is something I have to fight for. Oh well, sorry about the rant, I just dont get that about the industry so far. Apparently its bad to think ahead and cover all my bases because it makes my code harder to explain.
      Edit: I guess I just want each function to be correct for any given set of parameters unless the caller 100 percent knows that their parameters have to be checked before the function call. In the case of my code, they were checked before the call, but that doesnt stop an arbitrary caller from giving it bad parameters which could break the code. So I only exclude those checks if the code was called by an internal caller which verified the parameters for it

    • @DrewCocker
      @DrewCocker Před 2 lety

      @@KayOScode ​ Sounds like you might be over-engineering your code. Whilst it's great to make your code fail safe and extensible, you have to be mindful of how long this extra work takes and whether the time would be better spent elsewhere. Also, it will be harder for someone else to read and maintain your code.

    • @KayOScode
      @KayOScode Před 2 lety

      @@DrewCocker you might be right. Before I started industry work, I just wrote the code and pushed without much thought. It led to simpler code than that pull request. Maybe theres value in simplicity. Something about doing it for a job makes me want to write perfect code

  • @EngineerAAJ
    @EngineerAAJ Před 2 lety

    I would like to praise youtube algo for finally showing me an usefull recomendation

  • @drooten
    @drooten Před 2 lety +2

    It may be long, but you made it worth watching every minute!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Thanks Andrew, glad you liked it!

  • @omidgholami2594
    @omidgholami2594 Před 2 lety +4

    These series are very instructive and well structured. Thank you so much. BTW you have a video about your stack in NodeJS and TypeScript. It would be nice if you compare them with Python from your experience in web development. your channel deserves and gets 100k soon

  • @maxwell2201
    @maxwell2201 Před 2 lety

    This was great. Thank you!

  • @gingergiant89
    @gingergiant89 Před 2 lety +1

    Already at 6 mins into this video I've learned some great tips on how to think more like a professional developer - great vid!

  • @davidmente8700
    @davidmente8700 Před 2 lety

    Love the code roast format. Very enjoyable

  • @katorea
    @katorea Před 2 lety

    I've learnt a lot from this video alone, thank you for this. Also, i'd love those videos about creating a game engine!

  • @AutomatedChaos
    @AutomatedChaos Před 2 lety

    This video is a great example why you should not manually refactor without tests: The error around the 9:40 mark that others already pointed out and the changed behavior after deleting the try/catch statements later on. You made an implicit Finally of the code that was after this block, while it was originally only hit in the catch.
    Write tests first, refactor later. You don't need to create the tests yourself: there are unit test generators and in combination with code coverage tooling you can see if every line is covered (or at least the lines you want to refactor.)
    Speaking about tooling; refactoring can (and should) be done with tools too. All IDEs support refactoring patterns (like the switch conditional) that can be used while guaranteeing not to break anything. You can even go wilder with tools like Sourcery that have very clever refactorings.
    While it is good to do refactorings by hand (to learn how they work and why they exist), don't do this with production code without tools or tests.

  • @samfosteriam
    @samfosteriam Před 2 lety

    I enjoyed this, and that was some really effective and satisfying refactoring. You mentioned that people are at different stages on their learning journey. I think its true to say the same of projects and code. The game you started with reached the working prototype stage in its journey. It was cobbled together, iterated on a little - all focusing on the game play. It seemed to play well and if the goal was to accomplish that, then it was a success and "good" code by that definition. To allow it to evolve further, maybe build some more levels, or monsters etc, or to stand as an open source example to learn and build on - then it needs to move further on its journey with the kind of refactoring you did.
    When inspiration strikes and you want to make something from nothing, taking the most direct route from start to something that works is absolutely the right decision. Its usually impossible to know what the right structure is until you've got something that maybe almost works and the problems and their solutions start to emerge. And then, when it does work, don't stop just yet. You push on a little further to clean things up once the shape and requirements have started to become clear. I've found good code is a result of a series of discovery, testing and refinement loops. With experience you can sometimes skip some steps, but when you are learning, this process can be opaque - as people usually only commit and share the end product, not the indirect path they took to get there.
    Thanks again for such a well presented example of taking some code a little further on its journey, to become something we all can learn from.

  • @timlind3129
    @timlind3129 Před 2 lety

    You can learn more from this 30 minute video than in hours of online lessons/classes. This started to feel like Unity after you were done. Only comment is I like the subclass for Monsters, even though it was just different attributes, is probably a good forward looking design.

  • @TheRolfFR
    @TheRolfFR Před 2 lety

    Very cool video! I wasn't expecting the video to be so constructive because of the name but you spent most of the time helping and giving advices! Not really a roast but good content!

  • @simmonslucas
    @simmonslucas Před 2 lety

    Love these refactoring videos. I find them very informative. "Here's the way you probably wrote your code, Here's how not to do it stupidly"

  • @Tekay37
    @Tekay37 Před 2 lety +1

    That's some confident way of working with legacy code if I've ever seem one. I think I would try hard to back all my changes up with unittests before I'd even get going on the refactoring.

  • @jomafica13
    @jomafica13 Před 2 lety

    Learn a lot, keep going!

  • @atenleggedninja
    @atenleggedninja Před 2 lety

    Finally, ASMR for getting better at coding

  • @JoseSilva-lf1ve
    @JoseSilva-lf1ve Před 2 lety

    I would love a game engine series. Also, amazing videos. Keep the great work. Cheers from Portugal

  • @randomneo4538
    @randomneo4538 Před 2 lety

    w8ing for next part. and game engine videos. subbed

  • @pudicio
    @pudicio Před rokem

    Would love to see a game design series!!!❤

  • @viniciusraphaeldasilva3593

    You really know what you're talking about, great vid!

  • @errodememoria
    @errodememoria Před 2 lety

    This is just incredible

  • @johnday7362
    @johnday7362 Před 2 lety

    Arjan,
    Before coming to the point of this comment, I would like to compliment you on the style and the information in most of your videos. It is interesting and informative to see a developer's viewpoint on software (especially his/her viewpoint on the underlying code).
    Now for the constructive criticism; You mention that you would not be refactoring the 'Tower Defense' completely due to time constraints. I would like to point out that not all of your viewers have an attention span of only a few minutes.
    In fact, I regularly skip any video under 15 minutes that I would view to learn from. The previous refactoring video was very informative in its completeness.
    Thank you for this inside look into the steps used by a professional software developer.

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Hi John, thanks for your comment - much appreciated! I've been playing around with the format of these code roast videos. In more recent episodes, I've stuck to longer roasts, but split into a few different parts. I think that's a reasonable balance between keeping the videos to the point, but still providing a full refactor.

  • @budsyremo
    @budsyremo Před 2 lety

    Hi , just discovered your channel . Just a thought that what do you generally look for in refactoring?

  • @johns1307
    @johns1307 Před 2 lety

    Sounds like there's a ton of value in generalizing commands instead of directly referencing individual events. I have been interested in learning about coding for so long now but I get intimidated by how specific everything seems to be, but seeing this really puts it into a different perspective.

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +1

      Knowing how to code is a really valuable skill to have, I highly recommend you dive into it! Start with a simple project that's fun to work on. For example, you could create a classic text-based adventure game, or write a small application that does currency conversion. From there on, introduce new things to broaden your skillset.

  • @deez_gainz
    @deez_gainz Před 2 lety

    Yeah, architecture for a game engine or some sort of simulation environment would be really awesome to see from you!

  • @iliqnew
    @iliqnew Před 2 lety

    YES PLEASE! Game engines and GameDev architectures! Definitely the architectures

  • @tamassmahajcsik-szabo6408

    This is a really useful and fun series. As you mentioned in the video, please consider doing a series on game engines! Great work.

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks for the suggestions, Tamas, I've put it on the list.

  • @xaro6132
    @xaro6132 Před 2 lety

    Good Video : ) I would like to see more of this series. You can implement one of the design principles you created a video about and reference that in the same video. I started reading SOLID principle books since I started watching your videos about them. But maybe seeing someone thinking about what design principle they should apply when refactoring might improve the series.

  • @7353.
    @7353. Před 2 lety

    This type of Video is great and super educational

  • @atomspalter2090
    @atomspalter2090 Před 2 lety +2

    youtube algorythm now recommends me Refactorigs xd

  • @JoshPaulie
    @JoshPaulie Před 2 lety

    I love these. Holy moly.

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Thank you Josh, glad you liked it!

  • @UmbraAtrox_
    @UmbraAtrox_ Před 2 lety

    this is great, totally going to send in my noob project when i am done

  • @korn6657
    @korn6657 Před 2 lety

    I'm learning so much, thank you for doing god's work!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety +1

      Thank you, I’m happy the videos are helping you!

  • @ChrisOkay
    @ChrisOkay Před 2 lety

    Very instructive video, per the usual. Thanks for sharing. I second the idea of a video on game engine development.

  • @barhamd
    @barhamd Před 2 lety

    I would very much so be interested in more videos about game engine architecture.

  • @leocrapart6521
    @leocrapart6521 Před 2 lety

    Totally on with this game design pattern serie !
    Really interests me since i'm trying to create a game from scratch (without a game engine), in a python-like language.
    Also would like to ear if you have some suggestions about a functionnal approach to game design. Most of the patterns I see on the web are about OO and not FP.

  • @ingframin
    @ingframin Před 2 lety

    Yes! Make a game programming series please!

  • @wwijsman
    @wwijsman Před 2 lety

    Hell yeah, I would watch a video on game engine architecture. I contribute to multiple open source games based on just SDL and architecture is the hardest thing to get right in projects of some size.

  • @cod-newbie9166
    @cod-newbie9166 Před 2 lety

    This is wonderful content, thank you so much. It would be very helpful if you say how much time it takes you to go through the code, understand and then refactor the code so we have somewhat of a realistic timeline

  • @tobi5465
    @tobi5465 Před 2 lety

    Amazing, even if i dont code games, ive learnd a lot from this!

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Thanks Tobi, glad to hear it was useful!

  • @corentincaspers8229
    @corentincaspers8229 Před 2 lety

    That's actually very interesting.
    Of course, the refacto is very far from finished, but you introduced the different concepts mandatory for a proper game engine.
    Also I feel like you started with C or C++ looking how you code is definitely refreshing.
    Cause I definitely feel like my eyes are burning whenever I look at some python, but not here.

    • @ArjanCodes
      @ArjanCodes  Před 2 lety

      Thanks, glad you liked it! Actually, I started out in Basic but I'm quite happy you don't see that back in the code, haha. After Basic, I did move on pretty quickly to C++ though.

  • @badrequests8942
    @badrequests8942 Před 2 lety

    Please make more videos like this man! Would also be cool to watch you build an application from scratch! Like a web app with mongo or sqlite.

  • @_veikkomies
    @_veikkomies Před 2 lety

    Maybe I don't understand protocols but didn't you almost completely remove the implementations of the update and paint methods? Or did I miss something?

  • @Atropos148
    @Atropos148 Před 2 lety

    I would love to see more of this kind of video... I don't use Python3 for making games but I learned both game-design and general Python coding tricks. Do you plan on making more of these refactor videos?

  •  Před 2 lety

    Your coding is way too complicated for me to fully understand it now, but I can still learn much from your videos. I hope one day I will get everything you say!

  • @shizueigaki702
    @shizueigaki702 Před 10 měsíci

    Hi Arjan. I would love for you to go over best practices while creating games in Pygames. It would be awesome if you could plan a series regarding this in the future.

  • @FallKK
    @FallKK Před 2 lety +1

    I think a video game design series would be an awesome thing to watch