Refactoring A Tower Defense Game In Python // CODE ROAST

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!

Пікірлер: 402

  • @ArjanCodes
    @ArjanCodes2 жыл бұрын

    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

    2 жыл бұрын

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

  • @MyEconomics101

    @MyEconomics101

    2 жыл бұрын

    This video is the best python tutorial ever, imho.

  • @josephvictory9536

    @josephvictory9536

    2 жыл бұрын

    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_

    2 жыл бұрын

    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

    2 жыл бұрын

    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
    @EBagattack2 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Haha, can’t agree more!

  • @rban123

    @rban123

    2 жыл бұрын

    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

    2 жыл бұрын

    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

    2 жыл бұрын

    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

    2 жыл бұрын

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

  • @macchicken98
    @macchicken982 жыл бұрын

    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

    2 жыл бұрын

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

  • @budsyremo

    @budsyremo

    2 жыл бұрын

    I second that .

  • @Firedog_Alpha

    @Firedog_Alpha

    2 жыл бұрын

    This 100%

  • @TheSpacecraftX

    @TheSpacecraftX

    2 жыл бұрын

    Game engines from scratch are absolutely gigantic in scope.

  • @DaminGamerMC

    @DaminGamerMC

    2 жыл бұрын

    I recommend a channel called The Cherno then

  • @flyingcircle526
    @flyingcircle5262 жыл бұрын

    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

    2 жыл бұрын

    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

    2 жыл бұрын

    Came looking for this comment :)

  • @NedCollyer

    @NedCollyer

    2 жыл бұрын

    There are dozens of us. DOZENS!

  • @DavidvanDeijk

    @DavidvanDeijk

    2 жыл бұрын

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

  • @BasicallySteve23

    @BasicallySteve23

    2 жыл бұрын

    @@DavidvanDeijk I did not ;)

  • @nicolabombace2004
    @nicolabombace20042 жыл бұрын

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

  • @mattduffyw99
    @mattduffyw992 жыл бұрын

    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.

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks, glad you liked it!

  • @moopoo123
    @moopoo1232 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks Jason, glad you like it and will do!

  • @Electricity0
    @Electricity02 жыл бұрын

    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!

  • @SenselessUsername

    @SenselessUsername

    2 жыл бұрын

    Also a "roast" implies Java, clearly!

  • @ractheworld
    @ractheworld2 жыл бұрын

    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

    2 жыл бұрын

    Fully agree!

  • @nwoDekaTsyawlA

    @nwoDekaTsyawlA

    2 жыл бұрын

    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.

  • @valloway
    @valloway2 жыл бұрын

    I appreciated the positive attitude in the "Overview" section

  • @gcl2783
    @gcl27832 жыл бұрын

    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.

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Great suggestion, thank you!

  • @JohnFallot
    @JohnFallot2 жыл бұрын

    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

    2 жыл бұрын

    Thanks and noted!

  • @costelinha1867

    @costelinha1867

    2 жыл бұрын

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

  • @Fevir
    @Fevir2 жыл бұрын

    I love this Code Roast format.

  • @Cookie-mv2hg
    @Cookie-mv2hg2 жыл бұрын

    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!

  • @M0r1tz02
    @M0r1tz022 жыл бұрын

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

  • @spaderkungskuk
    @spaderkungskuk2 жыл бұрын

    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.

  • @almond5560
    @almond55602 жыл бұрын

    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

    2 жыл бұрын

    Thank you and you’re welcome!

  • @newf_gg1230

    @newf_gg1230

    2 жыл бұрын

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

    2 жыл бұрын

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

  • @AlphaWatt
    @AlphaWatt2 жыл бұрын

    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!

  • @baphnie
    @baphnie2 жыл бұрын

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

  • @nathanbrown2640

    @nathanbrown2640

    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

    2 жыл бұрын

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

  • @KayOScode

    @KayOScode

    2 жыл бұрын

    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

    2 жыл бұрын

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

    2 жыл бұрын

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

  • @Dziaji
    @Dziaji2 жыл бұрын

    “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

    2 жыл бұрын

    yeah, I've noticed that one as well.

  • @Pakitoz94

    @Pakitoz94

    2 жыл бұрын

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

  • @zapazap

    @zapazap

    2 жыл бұрын

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

  • @SpecialeW

    @SpecialeW

    2 жыл бұрын

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

  • @ilyaxi

    @ilyaxi

    2 жыл бұрын

    I almost questioned my existence when I saw that

  • @manuelpineda9067
    @manuelpineda90672 жыл бұрын

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

  • @theotherjim123
    @theotherjim1232 жыл бұрын

    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.

  • @jboe9159
    @jboe91592 жыл бұрын

    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.

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks, glad you liked it!

  • @fennecbesixdouze1794
    @fennecbesixdouze17942 жыл бұрын

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

  • @Tekay37
    @Tekay372 жыл бұрын

    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.

  • @dimaspaiva193
    @dimaspaiva1932 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thank you Dimas, glad you liked it!

  • @JacinLowe
    @JacinLowe2 жыл бұрын

    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.

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thank you, Jacin!

  • @AutomatedChaos
    @AutomatedChaos2 жыл бұрын

    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.

  • @InfiniteQuest86
    @InfiniteQuest862 жыл бұрын

    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.

  • @krzysztofkwiatkowski3224
    @krzysztofkwiatkowski32242 жыл бұрын

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

  • @amir3515
    @amir35152 жыл бұрын

    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

    2 жыл бұрын

    Great to hear & glad this is helpful to you!

  • @GlitchedFailure
    @GlitchedFailure2 жыл бұрын

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

  • @jofofouj
    @jofofouj2 жыл бұрын

    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.

  • @thevoid1463
    @thevoid14632 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks, glad you liked it!

  • @mrkeyzzz
    @mrkeyzzz Жыл бұрын

    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.

  • @BartKevelham
    @BartKevelham2 жыл бұрын

    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!

  • @ryanman56
    @ryanman562 жыл бұрын

    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

  • @hso24
    @hso242 жыл бұрын

    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!

  • @andidomi4335
    @andidomi43352 жыл бұрын

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

  • @zapazap
    @zapazap2 жыл бұрын

    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.

  • @Phate777
    @Phate7772 жыл бұрын

    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)

  • @rethanon
    @rethanon2 жыл бұрын

    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! 😁

  • @Original2BBB
    @Original2BBB2 жыл бұрын

    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

  • @adamasher7301
    @adamasher73012 жыл бұрын

    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.

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thank you, glad you liked it!

  • @nonyabusiness7794
    @nonyabusiness77942 жыл бұрын

    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

    2 жыл бұрын

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

  • @iliqnew
    @iliqnew2 жыл бұрын

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

  • @EngineerAAJ
    @EngineerAAJ2 жыл бұрын

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

  • @Ferenc-Racz
    @Ferenc-Racz2 жыл бұрын

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

  • @samfosteriam
    @samfosteriam2 жыл бұрын

    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.

  • @johnday7362
    @johnday73622 жыл бұрын

    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

    2 жыл бұрын

    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.

  • @katorea
    @katorea2 жыл бұрын

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

  • @timlind3129
    @timlind31292 жыл бұрын

    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.

  • @sai1921
    @sai19212 жыл бұрын

    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

  • @jvsvogler
    @jvsvogler Жыл бұрын

    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!

  • @ArjanCodes

    @ArjanCodes

    Жыл бұрын

    Glad you liked it! ☺️

  • @Wqube
    @Wqube2 жыл бұрын

    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!

  • @simmonslucas
    @simmonslucas2 жыл бұрын

    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"

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thank you, glad you like them!

  • @drooten
    @drooten2 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks Andrew, glad you liked it!

  • @gingergiant89
    @gingergiant892 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Glad it was helpful!

  • @deez_gainz
    @deez_gainz2 жыл бұрын

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

  • @apefu
    @apefu2 жыл бұрын

    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

    2 жыл бұрын

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

  • @xaro6132
    @xaro61322 жыл бұрын

    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.

  • @iliqnew
    @iliqnew2 жыл бұрын

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

  • @TheRolfFR
    @TheRolfFR2 жыл бұрын

    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!

  • @alessandroferrari2166
    @alessandroferrari21662 жыл бұрын

    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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks Alessandro!

  • @EduardoRodriguez-hz9re
    @EduardoRodriguez-hz9re2 жыл бұрын

    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

    2 жыл бұрын

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

  • @leocrapart6521
    @leocrapart65212 жыл бұрын

    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.

  • @BLSchaf
    @BLSchaf2 жыл бұрын

    Great to see how it's properly done!

  • @atenleggedninja
    @atenleggedninja2 жыл бұрын

    Finally, ASMR for getting better at coding

  • @omidgholami2594
    @omidgholami25942 жыл бұрын

    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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks Omid, great suggestion!

  • @JoseSilva-lf1ve
    @JoseSilva-lf1ve2 жыл бұрын

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

  • @cod-newbie9166
    @cod-newbie91662 жыл бұрын

    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

  • @davidmente8700
    @davidmente87002 жыл бұрын

    Love the code roast format. Very enjoyable

  • @wwijsman
    @wwijsman2 жыл бұрын

    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.

  • @Atropos148
    @Atropos1482 жыл бұрын

    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?

  • @bertrodgers2420
    @bertrodgers24202 жыл бұрын

    9:58 I agree that looks better, but it's not always correct. If you agree with the idea of structured programming, you shouldn't have to read the above indentation to continue with yours.

  • @viniciusraphaeldasilva3593
    @viniciusraphaeldasilva35932 жыл бұрын

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

  • @Insomnia_Wins
    @Insomnia_Wins2 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks Andrew, glad you like the content!

  • @badrequests8942
    @badrequests89422 жыл бұрын

    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.

  • @johns1307
    @johns13072 жыл бұрын

    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

    2 жыл бұрын

    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.

  • 2 жыл бұрын

    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!

  • @pudicio
    @pudicio Жыл бұрын

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

  • @UmbraAtrox_
    @UmbraAtrox_2 жыл бұрын

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

  • @corentincaspers8229
    @corentincaspers82292 жыл бұрын

    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

    2 жыл бұрын

    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.

  • @tamassmahajcsik-szabo6408
    @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

    Жыл бұрын

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

  • @kristjanjonsson3843
    @kristjanjonsson38432 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks! Glad you like the videos.

  • @maxwell2201
    @maxwell22012 жыл бұрын

    This was great. Thank you!

  • @shizueigaki702
    @shizueigaki7029 ай бұрын

    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.

  • @ArjanCodes

    @ArjanCodes

    9 ай бұрын

    Thanks for the idea!

  • @barhamd
    @barhamd2 жыл бұрын

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

  • @ChrisOkay
    @ChrisOkay2 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks Christian!

  • @ZantierTasa
    @ZantierTasa2 жыл бұрын

    13:17 I think you want to use a copy of the list: for projectile in projectiles[:]: # ... When you modify a list while iterating through it, apparently the behaviour is undefined. e.g. Try removing every element, and it won't remove them all.

  • @KayOScode

    @KayOScode

    2 жыл бұрын

    Correct, removing elements from a list while iterating forward through it is generally a bad idea. What you want to do is iterate through it backwards. Removing element i when moving backwards doesnt mess up indexing. Making a copy of the list is unnecessarily slow, but then again, if youre using python, clearly speed isnt your top priority

  • @quinndirks5653

    @quinndirks5653

    2 жыл бұрын

    The refactored code stays true to the original programming done by the author. It's possible to conceive that the author intended that when an element in the array is removed, processing of the next element should be skipped. Or it could be one of those happy little bugs that the author wanted to keep. In either case, if you change it, you may be changing the desired function of the program. The main takeaway is that you should iterate over the elements directly rather than iterating over a range in order to index into the array of elements. edit: Actually, to stay true to the original, he should have left the try/except block, because we don't know what exceptions the author intended to catch. Arjan says it's because elements are being removed from the array, but it could be something else beyond Arjan's knowledge. For instance, we don't know for sure that the author isn't raising exceptions and handling them somewhere within the update method, and sometimes they bubble up to this outer scope where they are always passed on.

  • @atomspalter2090
    @atomspalter20902 жыл бұрын

    youtube algorythm now recommends me Refactorigs xd

  • @randomneo4538
    @randomneo45382 жыл бұрын

    w8ing for next part. and game engine videos. subbed

  • @budsyremo
    @budsyremo2 жыл бұрын

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

  • @korn6657
    @korn66572 жыл бұрын

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

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

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

  • @jwjwjw1990
    @jwjwjw19902 жыл бұрын

    Nice series! I have an old working Windows Forms game project written in C# for a game called 'The Game'. There is a physical card game with the same name, and I figured the logic in that game was easily converted into code, so I challenged myself. Any chance you can use it for a Code Roast?

  • @ingframin
    @ingframin2 жыл бұрын

    Yes! Make a game programming series please!

  • @Sausytime
    @Sausytime2 жыл бұрын

    Came in expecting the typical "omg this code is so bad, what was this guy thinking" type of comments but I was thankfully relieved at around 1:10 I don't think CODE ROAST is a great thing to name a series as it immediately implies you're going to be dissing code rather than improving it and providing a learning opportunity. Great video nonetheless!

  • @jomafica13
    @jomafica132 жыл бұрын

    Learn a lot, keep going!

  • @errodememoria
    @errodememoria2 жыл бұрын

    This is just incredible

  • @chromosundrift
    @chromosundrift2 жыл бұрын

    Very good idea and example. Props to the original author; as you said, it shows courage. One suggestion: While not always easy to do, refactoring often results in broken intermediate states. If you make sure the software is still working after each incremental change, it is easier to ensure you don't bite off more than you can chew. You clearly have no trouble here but less experienced developers may struggle to follow unless they verify smaller refactoring steps and can fix smaller problems that may arise. Anyway nice work and good advice.

  • @ArjanCodes

    @ArjanCodes

    2 жыл бұрын

    Thanks! Actually, I had those testing bits in there between each major change, but due to the length of the video I mostly removed them. I'm going to experiment a bit more with the format for these code roasts. I think I'll try to split the next one into multiple parts so I can keep the more in-depth stuff in there.

  • @zapazap

    @zapazap

    2 жыл бұрын

    @@ArjanCodes An valuable video for me would be how to introduce unit tests to a game. So many chances in refactoring to introduce bugs that manifest only during play which I would not know how to unit test. This is probably a major testing issue from the start, harder still for post facto testing. But this I would like to know how to do. A brutishly inelegant safeguard might be to have a virtual game run as a part of the test suite? I see issues there too. It is unclear to me how to exactly reproduce user input in a real time game. Use of random numbers in the code would need to be reproducible as well. For the test to be useful n refactoring the clock for the engine will have to be sped up. All of this would be a nightmare if the code was not already designed with this in mind, I know. How would you go about inspecting working (but ugly) code to see if it would be worth grafting on some such testing framework before refactoring? Or equally valuable, how would you go about coding a realtime with such issues in mind, with proper hooks (say) for testing that the state of the game through a game run satisfies regression testing? These are hard parts of coding for me. I am a stickler for provability y background is mathematics) but this steers me away from some projects I might otherwise find interesting. I'm probably describing a series of videos, not a single video, to do this justice. But you might in one video introduce us to these issues and point the way. I think the feedback you would receive from this audience would be encouraging. I think many of us would be interested. And you seem to have the skill to bring such issues down to earth. Cheers! eplicate user input exactlyut brutishly egf

  • @chromosundrift

    @chromosundrift

    2 жыл бұрын

    @@zapazap great question. Unit testing strategies, especially adding them to an existing codebase is often difficult. We intuitively know that some tests are more valuable than others because some things are more likely to break and / or go unnoticed during human play testing. Also, some bugs have a very high cost while others are a mild inconvenience. Then, some tests are difficult to code while others are easy. With this you have the start of cost-benefit analysis. Something surprising is tests can often improve the design of code because it encourages decoupling such that the test doesn't have too much setup and teardown in order to exercise the unit under test. The catch 22 is that you can't easily do large refactoring without breaking something unless you have tests to give you confidence that the system works, and yet, in order to add tests you often find refactoring is more obviously warranted. As they say, if it's not testable code, then it's detestable code. So it's not easy. Working incrementally is often a good idea, but having said all of that, the answer is very situation dependent. Start with tests for bugs that have really happened, especially if they keep reappearing and are high severity, and prefer tests that are less difficult to write but which don't require a lot of refactoring to add. If you find such cases, congratulations, this is the low-hanging fruit. Another thing worth saying, while you are refactoring, you want to pick changes that help make invalid states less likely. For example, if you have things that "shouldn't happen", try to make them really impossible by having invariants guarded by types, scope/accessibility, devmode conditional assertions or other implementation measures and keep these invariants lexically close to the code that relies on that illegal state not happening. Then you can potentially exclude certain tests from even needing to be written. It's also valuable to have performance tests so you can use empirical measurement to ensure that you don't get fooled into worrying about supposed performance hits that come from refactoring the code. Measure that performance because it may not be a problem and modern hardware keeps making it harder to guess correctly. Always make sure unit tests are nonrandom and immediately fix reliability, reproducibility and incorrectness problems in the tests. Especially in a team because otherwise the whole investment in the tests is at risk.

  • @zapazap

    @zapazap

    2 жыл бұрын

    @@chromosundrift All good advice. Thank you. But the takeaway of the hour is 'code that is not testable is detestable'. That made me chuckle!