Step-By-Step Chess Game Refactoring | Code Roast

Sdílet
Vložit
  • čas přidán 9. 07. 2024
  • It’s been a while, but I am back with a new code roast video! Today I'm refactoring a Chess game. By practicing code reviewing you greatly improve your own coding abilities, become more critical of your own code and open up your mind.
    👉🏻 The code I worked on in this video is available here: github.com/ArjanCodes/2022-ch...
    👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis
    💻 ArjanCodes Blog: www.arjancodes.com/blog.
    🎓 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 enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!
    💬 Discord: discord.arjan.codes
    🐦Twitter: / arjancodes
    🌍LinkedIn: / arjancodes
    🕵Facebook: / arjancodes
    📱Instagram: / arjancodes
    👀 Code reviewers:
    - Yoriz
    - Ryan Laursen
    - James Dooley
    - Dale Hagglund
    🎥 Video edited by Mark Bacskai: / bacskaimark
    🔖 Chapters:
    0:00 Intro
    2:03 Example code explanation
    5:03 Analysis of the current code
    5:10 Wildcard imports
    6:30 Hardcoded values
    7:19 Initialising issues
    7:57 CommandHandler misplacement
    9:30 Precise type hints
    10:30 Reuse buttons and images
    17:20 Law of Demeter violations
    18:38 Refactor 1: Guard clauses
    20:59 Refactor 2: Change the Piece inheritance hierarchy to a single class
    24:18 Refactor 3: Create a Board class that has useful methods
    26:55 Refactor 4: Fill the board from a FEN string
    29:07 Refactor 5: Split out the valid moves functions
    30:35 Abstraction with Protocol class
    30:50 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 • 138

  • @ArjanCodes
    @ArjanCodes  Před 9 měsíci

    👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis

  • @yousofthelord
    @yousofthelord Před rokem +119

    This format is better for highlighting the new concepts overall but I think the old format, even if its longer, takes u through the process of thinking and not just the result of the thinking. Still its good content for sure. Overall, I find that code roasts is the best content on this channel Arjan. Real Problem with real solutions.

  • @janjaapvdv
    @janjaapvdv Před rokem +102

    Love the code roasts. They've inspired me to refactor a lot of my 'hobby' code.
    I would love watching a multi hour video of you completely refactoring a program.

    • @ArjanCodes
      @ArjanCodes  Před rokem +22

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

    • @addcoding8150
      @addcoding8150 Před rokem +2

      The end result will probably still be reasonably long, but how about not the whole thing and instead making it like a vlog. So we get the initial reaction on the code base and then, for each subsequent change he decided to make, we get a "So, I just changed that to this, because ...".
      This reduces the number of time lapses he has to make in the current style of much of the content he does. - Similar to this video

    • @thomasjones5649
      @thomasjones5649 Před rokem +1

      New programmer here, seconded. Big seconded.

  • @adam100022
    @adam100022 Před rokem +73

    Hey, thanks a lot for taking time to make a roast of my code. :D I'm not sure why, but the square coloring method doesn't seem to work on MacOS. Great video as always, I learned a lot from it.

    • @ArjanCodes
      @ArjanCodes  Před rokem +28

      Thank you so much, Adam, for sharing your code - it takes a lot of guts to have your code publicly scrutinized, so hats off to you. It was a really nice project to work on, and I hope the refactoring ideas are helpful to you.

    • @bocckoka
      @bocckoka Před rokem +1

      I hope you're taking notes, Adam, these are important points.

    • @superscatboy
      @superscatboy Před rokem +5

      Respect for submitting your code for such a public review like this. It's one thing to put things in a public repository, another thing to get it reviewed, and a whole other thing to get it reviewed on a channel with over 100k subscribers!

    • @robinpipslayertekprofitsfa2644
      @robinpipslayertekprofitsfa2644 Před rokem

      You’re a G!! Brap!! 🎉🎉🎉🔥🔥🔥💯💯💯💯
      Cool game tho!!
      I can see where a lot of that clean has me re-thinking my own codes!! Especially as Chess was high on the list of #TestApps gonna see if I can get around your macOS problems 🤔🧐 #StayCool #TeamGenius 🤓

  • @jampk24
    @jampk24 Před rokem +25

    I really like these types of videos and find them very helpful. I do prefer the longer versions where we actually see all the changes being made though. I think the new format has a little more disconnect between the old code and the new code because you don't see it all being updated.

  • @MaycolTeles
    @MaycolTeles Před rokem +30

    Arjan, you could do a series about “Clean Architecture” and actually implement a whole (simple, but complete) application using Clean Arch and also some Design Patterns as well, giving advices on how to use the best practices while doing it!
    I’d love to watch something like this, as I haven’t found it anywhere. Also, appreciate your videos, thank you!

    • @ArjanCodes
      @ArjanCodes  Před rokem +11

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

    • @swapnilchavan7076
      @swapnilchavan7076 Před rokem

      Everybody will agree with you Maycol.

  • @houterm
    @houterm Před rokem +6

    I also really enjoyed the old video format where you performed the actual refactoring steps, those moments where you were refactoring gave the viewer time to think and process what you had just said. Predicting how you would perform the refactoring was also a great learning practice from my perspective.
    I do agree though that if I was more experienced this format is nicer because of the higher information density.

    • @ArjanCodes
      @ArjanCodes  Před rokem +1

      Thanks for the feedback! I'm going to experiment more with the format to find the best solution.

  • @frost3281
    @frost3281 Před rokem +6

    Like before viewing! The best CZcams channel for learning Python at the intermediate-advanced level! Thank you for your job, Arjan!

  • @ocnyoura6803
    @ocnyoura6803 Před rokem +1

    You just can't get instructions like this anywhere else without paying a ton of money. I've learned so much from your videos I am able to apply your teachings to my own code in production.

  • @scrope
    @scrope Před 3 měsíci

    Personally I prefer the more detailed code refactor videos. I feel I learn more and it's more satisfying to watch. I do appreciate your issue with longer videos or splitting them. One possible solution is to film and edit the entire series of videos but release them all at once. I don't mind having longer videos but I can see the appeal of breaking them up into convenient stopping places. All of your videos are extremely educational but for some reason I really like the code roasts and get a lot of joy from them. I hope you continue this series regardless of the format.

  • @tanjt107
    @tanjt107 Před rokem +5

    I love the old format more. Seeing ten lines of codes turning into one or two lines is really satisfying.

    • @astronemir
      @astronemir Před rokem

      Missing the satisfaction of deleting dozens of lines of code 😂

  • @xiggywiggs
    @xiggywiggs Před rokem

    I'm back to watch this one again, and I just wanna say that while the coding is my favorite part of the channel, the b-roll and the gags are a **strong** second!
    And to anyone who feels differently you need to - ahem- opeeeen your miiiiiiind :D

  • @acatch22
    @acatch22 Před rokem +9

    I wait for these code roasts because they are always informative and interesting!
    Regarding the format, this particular example was fine for me because it was easy to follow and I already knew the reasons behind most of the changes from watching your other videos, even if I wouldn't have thought of them myself. Would be good to know what someone unfamiliar with design principles thinks
    In saying that, i definitely appreciate the previous in-depth analysis format as you work through the code. I personally wouldn't mind watching a single long video instead of multi-part if that helps the yt algorithm
    Maybe a best of both worlds approach would be to copy-paste code segments as you go through, instead of typing it as you go along (like old format) or showing the completed code (like new format), and a quick explanation of what is happening to make it abit faster/shorter?

  • @rakesha9176
    @rakesha9176 Před rokem +5

    I've been waiting exactly for this 🔥🔥. And single video is really helpful ✨

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thank you Rakesh, glad you liked the video!

  • @SylvioGuedes
    @SylvioGuedes Před rokem

    Code roasts are the best, hope you continue the serie and find the proper format.

  • @dallinyauney3131
    @dallinyauney3131 Před rokem

    This is my first video of yours I've seen, so I'd say the new format is working well!
    loved the video, by the way

  • @raccoonteachesyou
    @raccoonteachesyou Před rokem

    Straight to the point, that's very pleasant to watch, thanks for your work!

  • @simmonslucas
    @simmonslucas Před rokem +4

    love the cheesy opening!
    I love the roasts I pick up a lot of tricks from seeing you improve existing code.

    • @ArjanCodes
      @ArjanCodes  Před rokem

      The cheesier the better! (I'm Dutch 😁)

  • @akarlska
    @akarlska Před rokem +1

    Great video, tons of info! I would really enjoy a longer version where you go through a complete rewrite as well :)

  • @MrTomkan
    @MrTomkan Před rokem +1

    Very satisfying to watch, its like these videos where people clean their room

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks Tom, happy you’re enjoying the content!

  • @BulletproofOutlaws
    @BulletproofOutlaws Před rokem

    This was so educational! Even though it’s satisfying to watch you delete huge sections of code as you go, I think this experiment is a good balance! The first part where you just point out little fixes you’d make like consistent Snake_Case, moving consts to the top, entry point location, etc we don’t really need to see you actually change those things…just your explanation of how/why you would make those changes is enough. And for the more complicated refactoring, just mentioning that “we’ll get to that later” like you did is a good way to give us a preview of what the rest of the video is going to cover in the first few minutes
    This format probably let’s you pick out specific topics easier and the brief code examples force us to connect some dots on our own about how to keep applying or extrapolating from what you’re demonstrating, which is ultimately good for learning!
    I don’t even code in Python myself but your videos have made such a difference in how clean and organized my code is these days, and how I approach solving problems!

  • @sergiojimenez4595
    @sergiojimenez4595 Před rokem

    I learned a lot watching this video even though I do not work with Python, but Java. The reasoning behind it is what I find really interesting. Also, I really like your calm manner throughout the video. I could watch this type of format for hours. You got yourself a new sub! Keep it up!

  • @gulubidulu
    @gulubidulu Před rokem +1

    Hi there !
    I am currently working as a developper in the VFX industry, in which pretty much all devs are artists who eventually learned python in a not-very-academic way. Not gonna lie, the quality of the average module is not great ^^
    Thank you so much for you work, I learn a lot from your videos, and I really love how you keep them accessible by explaining why you use classes, dataclasses, abstract classes and so on. Now i'm better at recognising where and when I should use them in my own code.

  • @thisoldproperty
    @thisoldproperty Před rokem

    Even at the ten minute mark I felt you’d given great suggestions!
    I like this format, too btw. Refactoring in a single video is a pretty mammoth task, so any individual idea is well appreciated.

  • @rollinas1
    @rollinas1 Před rokem +3

    Lol, I love how Arjan gets visibly triggered at tuples and lists usage 🤣🤣

  • @12valmirjr
    @12valmirjr Před rokem

    Simply beautiful, Arjan!! Thank you so much for the content, unbelievable how good it is.

    • @ArjanCodes
      @ArjanCodes  Před rokem +1

      Thanks so much Valmir, glad the content is helpful!

  • @Mattamue
    @Mattamue Před rokem +1

    Awesome stuff. I've been struggling with my own tkinter project and this was a great help!

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks so much Matt, glad the content is helpful!

  • @loic1665
    @loic1665 Před rokem

    Great video!! thank you very much, I really like code roasts and videos really focused on SW design!
    Concerning the format, I think that it's good! I think that you focused on what is important: diagnosting where the problems are, and then presenting a solution and showing how it makes things easier! If you want to save time on "live coding", no problem for me! :)

  • @shalip
    @shalip Před rokem

    i love code roasts. make them as long & detailed as possible.. Thanks !!

  • @silkogelman
    @silkogelman Před rokem

    COOODE ROOAST!! 🤘👹🎸🎉
    Thank you Arjan!

  • @AessamL
    @AessamL Před rokem +2

    Thank you love the "Code Roast" Videos!

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thank you Ahmed, glad you liked the video!

  • @nisheetpatel2654
    @nisheetpatel2654 Před rokem

    If this helps the CZcams algorithm, go for it! Personally, I love the older format as it is much easier to follow and a lot more satisfying. Would appreciate if you continue to put that up somewhere though, either in CZcams playlists or on the software designer mindset course. Can't get enough of your refactoring wizardry!

  • @sprajosh
    @sprajosh Před rokem +1

    This was very informative. I’d love to see more of these

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks Siddharth, happy you’re enjoying the content!

  • @talwald1680
    @talwald1680 Před rokem +1

    First - great video!
    Secondly, about the format, I think that you could do a short video like this for those who want to learn from the results, but also link a more detailed multi part explanation of thought process for those who want to see it.
    About the moving, when I was thinking about coding a chess game, I also thought to do a get valid moves function, but it requires to much, so I started off with check is valid move which got a start and an end. This turned out to be a whole lot simpler, but you can't show all the valid moves without looping on all the squares.

  • @kristjanjonsson3843
    @kristjanjonsson3843 Před rokem

    Amazing roast as always! Getting access to long code roasts through something like Patreon would be awesome and a big incentive to join.

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thank you Kristjan, glad you liked the video!

  • @MrGMattia
    @MrGMattia Před rokem

    Hi Arjan, thanks very much. Great video as always! Have you got any plan to cover the process you follow to go from requirements definition to deployment and maintenance?

  • @filippopisello
    @filippopisello Před rokem

    Nice video as always!
    I personally really liked the full length roasts as they did a great job in translating theory to practice, showing how real problems are handled.
    Maybe something you did not consider is following the 2 videos approach where instead of structuring as a part 1, 2 and so on, you could make the first video standalone, like this one. No need to call it "part one". Maybe then have a follow up with the low level implementation for the hardcore followers who want to see the details!
    I see that this is quite a lot of work, but it could help giving both audiences their content.

  • @Magnus_E
    @Magnus_E Před rokem +2

    CODE ROAST YEAH. a day of celebration!

    • @ArjanCodes
      @ArjanCodes  Před rokem +1

      Thank you Magnus, glad you liked the video!

  • @danny_petrov
    @danny_petrov Před rokem +1

    Hey Arjan,
    Love the new style. It seems to fit perfectly with more casual viewers like myself, but what I was thinking is, if it is possible for you to just create the content in a stream for example and then go over the decisions you've made in a short video like this one. It's something that some more mainstream CZcamsrs are doing and I think it might work for you too.
    Also, I noticed you are playing around with the effects of the camera when in full screen (haven't watched the content for a while so I am not sure if you have tried this), but you can try reflecting the frame when editing and changing the zoom at the same time. It makes for a greater variety in frames and keeps audiences engaged. For reference, you can check Graham's show (just search something about credit cards or the market and you should find him).
    Sorry for the long post, hope it's helpful.

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Hi Daniel, thanks for the suggestions! I'll consider the stream idea, it's interesting. Regarding adding more variety, yes, that's always good. I've recently started recording a second angle for some segments, so I think that will also help. Thanks again for your points!

  • @rollinas1
    @rollinas1 Před rokem

    Yessss, it's back!!!

  • @riccardopalleschi
    @riccardopalleschi Před rokem

    Great content as always 🔥

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks so much Riccardo, glad the content is helpful!

  • @grimshawr
    @grimshawr Před rokem

    Awesome! I'm currently refactoring my chess game, so this was a really nice pairing with my morning coffee.

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks so much Ross, glad the content is helpful!

  • @dmytrokorbanytskyi1586

    great work! As usual )

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks so much Дмитрий , glad the content is helpful!

  • @xnick_uy
    @xnick_uy Před rokem

    Great video. Great choice of shirt.
    I've always wondered how the code of a chess engine would look, and now I have 2 ideas. That's fantastic!
    Of course, there's the matter of creating a computer player and having it choosing the move, but that's material for another video (maybe more than one). But we've already seen some of the main ingredients present in videos such as the "rock-paper-scisors-lizard-Spock" and the "naval battle" ones.
    One thing I feel it shouldn't be hard to do is fixing the coloring of the chess board squares, that is not working here (5:04).

  • @RoamingAdhocrat
    @RoamingAdhocrat Před rokem +2

    2:15 all those red squigglies give me The Fear.

  • @camoman1000
    @camoman1000 Před rokem

    For the valid moves I would make a game and pieces rule set and pieces could have multiple rule sets like horizontal and/or vertical move rules. And game rules would be chess const config settings with name of chess for game rule set

  • @danilodrobac6151
    @danilodrobac6151 Před rokem

    Like the format of this, very informative but I think the old format is still better because you get to see everything in more detail and watch it all be pieced together.
    Maybe a longer, single video is a happy medium? It's a shame there's a dropoff but yeah it is natural I suppose.
    I'd love to see one of these code toasts for a data engineering project.
    A lot of DE projects I see don't necessarily follow great software design practices and it would be good to see your take on them!

  • @angelcaru
    @angelcaru Před rokem +1

    10:40 He somehow found a way to have a memory leak in Python

  • @PouriyaJamshidi
    @PouriyaJamshidi Před rokem +1

    It is better to have them in a single video. By the time the 2nd one comes out, I already forget what the first part was about :S

  • @romanroman4665
    @romanroman4665 Před rokem

    Finally, my favorite code roast🤗

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks Roman, happy you’re enjoying the content!

  • @mudasirulhaque4873
    @mudasirulhaque4873 Před rokem

    Hi arjan, great video keep up the series i love it🎉. Just a question can we not make the from_fen method a class method instead of static method. As python supports it?. Thank you😊❤

  • @jurgenrusch4041
    @jurgenrusch4041 Před rokem +1

    Hi Arjan, again a very, very nice code roast. Thanks! 👍
    As a side note: you hardly 'roast' 🔥 the code or author. Instead your critics are quite gentle and you remain respectful. ☺️
    Anyway, I think there is a part that I find 'tricky' when defining __str__ of a Piece: there you 'silently' rely on the value (0 or 1) of the Color enum and you use it as an index into a tuple (which is the value of the COLOR_STR dict).
    I think it could/would be better to let each value in that dict be a dict itself which maps a Color to a str. You would then have a nested dict.
    Alternatively COLOR_STR could be a dict mapping a tuple (PieceType, Color) to a str. Whatever your preference is.
    Oh, and I agree with the feedback of several viewers that the static method should better be a class method as it constructs an instance.

  • @floriandauphin735
    @floriandauphin735 Před rokem +2

    @ArjanCodes, thanks for the video! 27:30 shouldn't the `from_fen` method of your `Board` class be a `classmethod` instead of a `staticmethod` ?
    It is my understanding that classmethod is used for class creation, which seems to be the case here.

    • @ArjanCodes
      @ArjanCodes  Před rokem +2

      Indeed, I missed that, this would be better. Especially when combined with the Self type identifier coming in Python 3.11.

    • @python6367
      @python6367 Před rokem

      @@ArjanCodes this is my question too.
      Based to your answer, I can't understand which is better? classmethod and staticmethod?

    • @TheFlo624
      @TheFlo624 Před rokem +2

      @@python6367 You should use class method here, because you're creating a class. @staticmethod will break when inheriting from this class while @classmethod won't.

  • @mailonbido
    @mailonbido Před rokem

    What vscode extensions /settings do you recommend using with python code?

  • @TheMathman7
    @TheMathman7 Před rokem +2

    I don't agree with removing the inheritance from the Pieces and replacing it with a lot of dicts. That way you have to look at several different dicts just to see how one single piece looks like. Everything regarding one type of piece should be at once place. And this place should be a class that inherits from the "Piece" base class.

  • @olemew
    @olemew Před rokem

    Design principles speak for themselves.

  • @ramimashalfontenla1312

    Like new format so much!

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

    27:20 Should the static method be class method as it return a Board?

  • @23koook
    @23koook Před rokem

    I don't think the piece should know it's position on the board. It's just complecting the two things: a board and a piece. A piece could have a method like "where can I move on a board b", but then the piece has to know how the board works, and we haven't achieved any kind of separation of the two.
    I'd recommend simply removing the x and y instance variables from the piece. That should make refactoring the logic much easier.
    Oh and kudos for an excellent review. Feels like it should be very helpful.

  • @gshan994
    @gshan994 Před rokem

    Thanks for this amazing video.
    I was wondering how can we add knight moves method since it moves horizontally and vertically

    • @ArjanCodes
      @ArjanCodes  Před rokem +1

      Thanks so much, glad you liked it!

  • @swapnilchavan7076
    @swapnilchavan7076 Před rokem

    This video is so much Informative but I would love to watch video on kubernetes. I like your docker video so much. Please prepare one video on kubernetes for container orchestration.
    Thank you in advance. Lots of love from India.🙏

  • @allo5668
    @allo5668 Před rokem +1

    Arhan, shouldn’t the “from_fen()” initializer function actually be a class method instead of a static method?

    • @allo5668
      @allo5668 Před rokem

      Also, instead of needing a fenmap dictionary, I think enums can support a built-in mapping using strings!

  • @AW0348
    @AW0348 Před rokem

    Very nice code analysis !
    I was just wondering, isn't it a bit risky to have the arbitrary piece type (KING, QUEEN, etc...) in each of the hardcode dictionaries (PIECE_STR, FEN_MAP, MOVE_LIST) ? For instance, if a new type of piece needs to be added, it is possible to forget to add it to one of the dictionaries
    Of course, this demand would be unlikely considering the game and the error would certainly be caught in the tests. I don't really see how to improve it unless by creating a class for each piece, which does not seem a good option. I guess the best solution is to have a test that confirms that each of these dictionaries has the same keys. Do you think there is a way to make sure the keys are correct by modifying the code structure ?
    Once again great code roast !

  • @Seawolf159
    @Seawolf159 Před rokem

    7:49 i was told that super() is a bad idea, because when you inherit from multiple things you don't know what super is. Is this wrong?

    • @ArjanCodes
      @ArjanCodes  Před rokem

      IMO the bad idea is not calling super, it’s multiple inheritance.

  • @DogeMultiverse
    @DogeMultiverse Před rokem

    Wow. They asked for a roast, but got a Bbq instead. Well done

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Haha Thanks, happy you’re enjoying the content!

  • @meilich_m
    @meilich_m Před rokem

    Since it's long already, I would rather sit through an hour of more detailed refactoring and showing the exact solution to the issue, than just addressing the issues.

  • @user-ut1oq8xf6q
    @user-ut1oq8xf6q Před rokem

    I think you should've named the Board's class method somewhat like "is_empty" to clarify it's intended behaviour to readers

  • @michaelbrenner2087
    @michaelbrenner2087 Před rokem

    Code roasts are what I love best about your channel, Arjan! I understand your motivation for the new for the new format, although this roast feels a bit "hectic" compared to the old ones.
    One question I'd have loved to hear you discuss in the video: Why did you decide not to go for *polymorphism* for the pieces (especially during a refactoring as compared to a complete reimplementation)? All the isinstance() calls are a classic code smell for not making full use of OO, aren't they? Although I love dicts instead of ifs as much as you do, you could, for instance, have kept the black/white icons as a simple 2-tuple in each subclass, which seems clearer and more cohesive to me. I'm sure you thought about and decided against this - could you fill us in on the why? (Promotion to queen is the one example I can see where your approach works super nicely. Are there more?)

  • @conconmc
    @conconmc Před rokem +3

    Awesome stuff Arjan, I love the new format! I think it is much more concise and helps highlight the key concepts.

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks so much Connor, glad the content is helpful!

  • @alphenit
    @alphenit Před rokem

    @ArjanCodes, I know it's a code roast but 11:35 shows that the minimap of vscode is not happy about anything.
    Is that because the code is that bad not following best practices or a vscode feature ? (if this is a vscode feature how useful is it, seeing red EVERYWHERE ? :) )

    • @ArjanCodes
      @ArjanCodes  Před rokem +1

      It's actually my type checker that's complaining since I set it to "strict" in this video. In my upcoming videos, I've switched it off to increase readability.

    • @alphenit
      @alphenit Před rokem

      @@ArjanCodes Good stuff Arjan, love your videos, I'm still a semi-beginner so watching your stuff always feels like I'm lifting weights that are a bit too heavy for me but always learn a lot. Maybe one day I can also become a buff pythonista like you (or whatever those people are called) keep going Sir, you are much appreciated!
      Heard you say you might start publishing stuff/looking into Rust. Maybe you'll reconsider and turn to Golang because from what I'v read its learning curve is less steep compared to Rust so might be easier for people to join you on that journey.

  • @scottblake2332
    @scottblake2332 Před rokem

    I really enjoyed this video, but I don't like this format for refactors. I do like the extra time taken to explain the issues with the code as you analyze it, and I can see the value in performing the refactor off-camera, but I found it much harder to follow the reasoning and watched that second part twice (still not fully understanding).
    Maybe if you were to link to an unlisted video with the full refactor as well? Maybe a 2 part series, but they are released together? I'm not really sure how to appease the great algorithm while still getting into the details of the code.

  • @ayhaneyikan7842
    @ayhaneyikan7842 Před rokem

    What’s the reasoning behind utilizing a Protocol instead of importing those two Board class methods?

    • @ArjanCodes
      @ArjanCodes  Před rokem

      It removes a dependency. This is useful for example if you want to write tests. You can then easily replace the board object by a mock object.

    • @marcotroster8247
      @marcotroster8247 Před rokem +1

      And not to mention Python has cyclic import bugs when two classes import each other (or even transitive imports) 😅
      So if your codebase grows, you'll end up with really weird bugs that can waste whole days to decouple the code again 😅

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Good point, Marco!

  • @marcotroster8247
    @marcotroster8247 Před rokem +1

    I think there's still lots of things to improve, especially if you want better performance. And I'm saying that because you'll need it for AI trainings or other heuristics like minimax.
    You may have noticed that the piece position can be stored implicitly if you store it in an array of 64 bytes, one byte for each piece (although 5 bits would suffice). Index from 0-63, use pos AND 0x7 for x and pos >> 3 for y coordinate, it's a lot faster.
    Next thing is caching. Lots of popular approaches cache most of the move patterns such that it's just an array lookup. This can be computed on program startup such that it's only done once upfront.
    Also if you wanna crunch even harder, make use of bitboards consisting of 64-bit integers to represent the board. Each bit stands for "there's a piece at this index", and you create a bitboard for each piece type and color, so everything is covered. Then you can do lots of fancy bithacks and stuff. Shifting by 8 is moving one forward, etc. It's quite funny to rehearse bitwise ops that way 😂

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Great suggestions regarding performance! I didn't focus on that in this code roast at all.

  • @Andrumen01
    @Andrumen01 Před rokem

    I really like your videos, the problem that I find is that most of the code is underlined with errors (maybe not recognized paths?). I understand that sometimes paths are not recognized, but it's very annoying to watch most of the code squiggled....it's really a turnoff.

    • @ArjanCodes
      @ArjanCodes  Před rokem +1

      Thanks for the feedback. I also noticed this is distracting, so for my next batch of videos, I've turned this off.

  • @costelinha1867
    @costelinha1867 Před rokem

    It feels so weird, cuz it's been such a while since the last time I've read, let alone write Python code. (I'm still coding, just using a different language now.)

  • @ChrisM541
    @ChrisM541 Před rokem

    Does this use an external chess engine (e.g. Stockfish) or is it attempting that task itself?

  • @mad_vegan
    @mad_vegan Před rokem

    I would add that the comments should be in English and the author should consider following PEP 8 guidelines if the code is meant to be shared.

  • @vishalkarda4396
    @vishalkarda4396 Před rokem

    This is good, but please go back to the previous detailed process. It's important to understand the why then just where and how !!
    I don't mind even a hour video for the same.

  • @j.z.b90
    @j.z.b90 Před rokem

    this new format is a bit to hectic. I liked the former format better. Maybe in this code roasts you could start not with the original code, but whith an already partially refactored version and do the important refactorings in the video. For people with more interest and time, you could provide the original code, some intermediate refactoring steps and the final refactoring in a repo, including the main points of issues and refactoring as commit comments

  • @genie9262
    @genie9262 Před rokem

    :)

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thank you Genie, glad you liked the video!

  • @alexandrodisla6285
    @alexandrodisla6285 Před rokem

    Do not devalue the content. Stay truth to the right way. The attention span needs to be going back up.

  • @manishjha3413
    @manishjha3413 Před rokem

    i really like brо, thank you

    • @ArjanCodes
      @ArjanCodes  Před rokem

      Thanks so much, Manish, glad the content is helpful!

  • @jacquesbabaud3610
    @jacquesbabaud3610 Před rokem

    Too bad in my opinion that you have to take shortcuts in your thought and implementation process because some of us watchers do not have the patience and commitment to follow you from one week to the next. I understand your concern for maximizing views and video tracking so that people can access to your content, but in a sub-10-min-concentration era it has its consequences on overall quality. In one word: I prefer the old format, you might split into 5 videos I would still go through all of them. Continue the great content creation, I enjoy your weekly release as a new star wars mini episode. All the best!

  • @guillaumef657
    @guillaumef657 Před rokem +1

    Hi Arjan. I think this version of code roast break the "show don't tell" principle. I understand that if you put so much effort in a 3 parts serie and it doesn't pay, you want to change the formula. But I feel code roast was a good complementary format to your more "abstract" videos. I learned a lot just watching you working on the code, how you proceed, how you build your new version, step by step. Just my 2 cents. And after all, the old versions are still here and the channel should move on. Thank you for what you bring to the python community.

  • @nomadvagabond1263
    @nomadvagabond1263 Před rokem

    I would prefere watching a longer video while you actually fix the code rather than just talking

  • @WilliamDean127
    @WilliamDean127 Před rokem +3

    Why not use a classmethod in a few of those staticmethod locations? i.e. Piece.from_fen

  • @surajkadel8762
    @surajkadel8762 Před rokem

    Uncle Aryan ( just like uncle Bob 😅)
    Thank you.