Step-By-Step Chess Game Refactoring | Code Roast

  Рет қаралды 49,149

ArjanCodes

ArjanCodes

Күн бұрын

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!

Пікірлер: 138
@ArjanCodes
@ArjanCodes 8 ай бұрын
👷 Join the FREE Code Diagnosis Workshop to help you review code more effectively using my 3-Factor Diagnosis Framework: www.arjancodes.com/diagnosis
@janjaapvdv
@janjaapvdv Жыл бұрын
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 Жыл бұрын
Thanks for the suggestions, I've put it on the list.
@addcoding8150
@addcoding8150 Жыл бұрын
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 Жыл бұрын
New programmer here, seconded. Big seconded.
@yousofthelord
@yousofthelord Жыл бұрын
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.
@pasqualebuonocore1302
@pasqualebuonocore1302 Жыл бұрын
I agree
@lbb2rfarangkiinok
@lbb2rfarangkiinok Жыл бұрын
Yep, this is easier to follow, harder to learn from.
@mesaber86
@mesaber86 Жыл бұрын
Hell yeah.. I could watch Arjan code for hours.
@nitzan3984
@nitzan3984 Жыл бұрын
Well written, I totally agree
@hoseynamiri
@hoseynamiri 10 ай бұрын
I need more detailed roasting
@adam100022
@adam100022 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
I hope you're taking notes, Adam, these are important points.
@superscatboy
@superscatboy Жыл бұрын
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 Жыл бұрын
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 🤓
@MaycolTeles
@MaycolTeles Жыл бұрын
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 Жыл бұрын
Thanks for the suggestions, Maycol, I've put it on the list.
@swapnilchavan7076
@swapnilchavan7076 Жыл бұрын
Everybody will agree with you Maycol.
@jampk24
@jampk24 Жыл бұрын
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.
@houterm
@houterm Жыл бұрын
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 Жыл бұрын
Thanks for the feedback! I'm going to experiment more with the format to find the best solution.
@scrope
@scrope 3 ай бұрын
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.
@frost3281
@frost3281 Жыл бұрын
Like before viewing! The best KZbin channel for learning Python at the intermediate-advanced level! Thank you for your job, Arjan!
@ocnyoura6803
@ocnyoura6803 Жыл бұрын
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.
@rakesha9176
@rakesha9176 Жыл бұрын
I've been waiting exactly for this 🔥🔥. And single video is really helpful ✨
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you Rakesh, glad you liked the video!
@acatch22
@acatch22 Жыл бұрын
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?
@xiggywiggs
@xiggywiggs Жыл бұрын
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
@tanjt107
@tanjt107 Жыл бұрын
I love the old format more. Seeing ten lines of codes turning into one or two lines is really satisfying.
@astronemir
@astronemir Жыл бұрын
Missing the satisfaction of deleting dozens of lines of code 😂
@SylvioGuedes
@SylvioGuedes Жыл бұрын
Code roasts are the best, hope you continue the serie and find the proper format.
@simmonslucas
@simmonslucas Жыл бұрын
love the cheesy opening! I love the roasts I pick up a lot of tricks from seeing you improve existing code.
@ArjanCodes
@ArjanCodes Жыл бұрын
The cheesier the better! (I'm Dutch 😁)
@akarlska
@akarlska Жыл бұрын
Great video, tons of info! I would really enjoy a longer version where you go through a complete rewrite as well :)
@raccoonteachesyou
@raccoonteachesyou Жыл бұрын
Straight to the point, that's very pleasant to watch, thanks for your work!
@rollinas1
@rollinas1 Жыл бұрын
Lol, I love how Arjan gets visibly triggered at tuples and lists usage 🤣🤣
@dallinyauney3131
@dallinyauney3131 Жыл бұрын
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
@MrTomkan
@MrTomkan Жыл бұрын
Very satisfying to watch, its like these videos where people clean their room
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Tom, happy you’re enjoying the content!
@sergiojimenez4595
@sergiojimenez4595 Жыл бұрын
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!
@BulletproofOutlaws
@BulletproofOutlaws Жыл бұрын
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!
@thisoldproperty
@thisoldproperty Жыл бұрын
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.
@12valmirjr
@12valmirjr Жыл бұрын
Simply beautiful, Arjan!! Thank you so much for the content, unbelievable how good it is.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Valmir, glad the content is helpful!
@gulubidulu
@gulubidulu Жыл бұрын
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.
@Mattamue
@Mattamue Жыл бұрын
Awesome stuff. I've been struggling with my own tkinter project and this was a great help!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Matt, glad the content is helpful!
@AessamL
@AessamL Жыл бұрын
Thank you love the "Code Roast" Videos!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you Ahmed, glad you liked the video!
@shalip
@shalip Жыл бұрын
i love code roasts. make them as long & detailed as possible.. Thanks !!
@silkogelman
@silkogelman Жыл бұрын
COOODE ROOAST!! 🤘👹🎸🎉 Thank you Arjan!
@loic1665
@loic1665 Жыл бұрын
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! :)
@sprajosh
@sprajosh Жыл бұрын
This was very informative. I’d love to see more of these
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Siddharth, happy you’re enjoying the content!
@nisheetpatel2654
@nisheetpatel2654 Жыл бұрын
If this helps the KZbin 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 KZbin playlists or on the software designer mindset course. Can't get enough of your refactoring wizardry!
@talwald1680
@talwald1680 Жыл бұрын
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.
@riccardopalleschi
@riccardopalleschi Жыл бұрын
Great content as always 🔥
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Riccardo, glad the content is helpful!
@dmytrokorbanytskyi1586
@dmytrokorbanytskyi1586 Жыл бұрын
great work! As usual )
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Дмитрий , glad the content is helpful!
@filippopisello
@filippopisello Жыл бұрын
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.
@rollinas1
@rollinas1 Жыл бұрын
Yessss, it's back!!!
@ArjanCodes
@ArjanCodes Жыл бұрын
You bet!
@Magnus_E
@Magnus_E Жыл бұрын
CODE ROAST YEAH. a day of celebration!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you Magnus, glad you liked the video!
@kristjanjonsson3843
@kristjanjonsson3843 Жыл бұрын
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 Жыл бұрын
Thank you Kristjan, glad you liked the video!
@danny_petrov
@danny_petrov Жыл бұрын
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 KZbinrs 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 Жыл бұрын
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!
@MrGMattia
@MrGMattia Жыл бұрын
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?
@RoamingAdhocrat
@RoamingAdhocrat Жыл бұрын
2:15 all those red squigglies give me The Fear.
@grimshawr
@grimshawr Жыл бұрын
Awesome! I'm currently refactoring my chess game, so this was a really nice pairing with my morning coffee.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Ross, glad the content is helpful!
@romanroman4665
@romanroman4665 Жыл бұрын
Finally, my favorite code roast🤗
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Roman, happy you’re enjoying the content!
@xnick_uy
@xnick_uy Жыл бұрын
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).
@ramimashalfontenla1312
@ramimashalfontenla1312 Жыл бұрын
Like new format so much!
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks Rami, glad you liked it!
@23koook
@23koook Жыл бұрын
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.
@danilodrobac6151
@danilodrobac6151 Жыл бұрын
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!
@PouriyaJamshidi
@PouriyaJamshidi Жыл бұрын
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
@camoman1000
@camoman1000 Жыл бұрын
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
@TheMathman7
@TheMathman7 Жыл бұрын
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.
@angelcaru
@angelcaru Жыл бұрын
10:40 He somehow found a way to have a memory leak in Python
@olemew
@olemew Жыл бұрын
Design principles speak for themselves.
@AW0348
@AW0348 Жыл бұрын
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 !
@jurgenrusch4041
@jurgenrusch4041 Жыл бұрын
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.
@mudasirulhaque4873
@mudasirulhaque4873 Жыл бұрын
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😊❤
@floriandauphin735
@floriandauphin735 Жыл бұрын
@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 Жыл бұрын
Indeed, I missed that, this would be better. Especially when combined with the Self type identifier coming in Python 3.11.
@python6367
@python6367 Жыл бұрын
@@ArjanCodes this is my question too. Based to your answer, I can't understand which is better? classmethod and staticmethod?
@TheFlo624
@TheFlo624 Жыл бұрын
@@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.
@michaelbrenner2087
@michaelbrenner2087 Жыл бұрын
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?)
@swapnilchavan7076
@swapnilchavan7076 Жыл бұрын
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.🙏
@meilich_m
@meilich_m Жыл бұрын
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.
@mailonbido
@mailonbido Жыл бұрын
What vscode extensions /settings do you recommend using with python code?
@DogeMultiverse
@DogeMultiverse Жыл бұрын
Wow. They asked for a roast, but got a Bbq instead. Well done
@ArjanCodes
@ArjanCodes Жыл бұрын
Haha Thanks, happy you’re enjoying the content!
@user-ut1oq8xf6q
@user-ut1oq8xf6q Жыл бұрын
I think you should've named the Board's class method somewhat like "is_empty" to clarify it's intended behaviour to readers
@alexandarjelenic2880
@alexandarjelenic2880 9 ай бұрын
27:20 Should the static method be class method as it return a Board?
@conconmc
@conconmc Жыл бұрын
Awesome stuff Arjan, I love the new format! I think it is much more concise and helps highlight the key concepts.
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much Connor, glad the content is helpful!
@gshan994
@gshan994 Жыл бұрын
Thanks for this amazing video. I was wondering how can we add knight moves method since it moves horizontally and vertically
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, glad you liked it!
@allo5668
@allo5668 Жыл бұрын
Arhan, shouldn’t the “from_fen()” initializer function actually be a class method instead of a static method?
@allo5668
@allo5668 Жыл бұрын
Also, instead of needing a fenmap dictionary, I think enums can support a built-in mapping using strings!
@alphenit
@alphenit Жыл бұрын
@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 Жыл бұрын
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 Жыл бұрын
@@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 Жыл бұрын
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.
@Seawolf159
@Seawolf159 Жыл бұрын
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 Жыл бұрын
IMO the bad idea is not calling super, it’s multiple inheritance.
@Andrumen01
@Andrumen01 Жыл бұрын
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 Жыл бұрын
Thanks for the feedback. I also noticed this is distracting, so for my next batch of videos, I've turned this off.
@costelinha1867
@costelinha1867 Жыл бұрын
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.)
@ayhaneyikan7842
@ayhaneyikan7842 Жыл бұрын
What’s the reasoning behind utilizing a Protocol instead of importing those two Board class methods?
@ArjanCodes
@ArjanCodes Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
Good point, Marco!
@vishalkarda4396
@vishalkarda4396 Жыл бұрын
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.
@ArjanCodes
@ArjanCodes Жыл бұрын
Great suggestion, thank you!
@marcotroster8247
@marcotroster8247 Жыл бұрын
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 Жыл бұрын
Great suggestions regarding performance! I didn't focus on that in this code roast at all.
@mad_vegan
@mad_vegan Жыл бұрын
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.
@j.z.b90
@j.z.b90 Жыл бұрын
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
@alexandrodisla6285
@alexandrodisla6285 Жыл бұрын
Do not devalue the content. Stay truth to the right way. The attention span needs to be going back up.
@genie9262
@genie9262 Жыл бұрын
:)
@ArjanCodes
@ArjanCodes Жыл бұрын
Thank you Genie, glad you liked the video!
@manishjha3413
@manishjha3413 Жыл бұрын
i really like brо, thank you
@ArjanCodes
@ArjanCodes Жыл бұрын
Thanks so much, Manish, glad the content is helpful!
@jacquesbabaud3610
@jacquesbabaud3610 Жыл бұрын
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!
@ChrisM541
@ChrisM541 Жыл бұрын
Does this use an external chess engine (e.g. Stockfish) or is it attempting that task itself?
@guillaumef657
@guillaumef657 Жыл бұрын
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 Жыл бұрын
I would prefere watching a longer video while you actually fix the code rather than just talking
@WilliamDean127
@WilliamDean127 Жыл бұрын
Why not use a classmethod in a few of those staticmethod locations? i.e. Piece.from_fen
@alexandarjelenic7718
@alexandarjelenic7718 Жыл бұрын
thats what i would like to know as well
@surajkadel8762
@surajkadel8762 Жыл бұрын
Uncle Aryan ( just like uncle Bob 😅) Thank you.
Refactoring Conway's Game of Life | ArjanCodes Code Roast
31:49
ArjanCodes
Рет қаралды 28 М.
Refactoring A Tower Defense Game In Python // CODE ROAST
36:49
ArjanCodes
Рет қаралды 256 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 85 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 2,5 МЛН
The child was abused by the clown#Short #Officer Rabbit #angel
00:55
兔子警官
Рет қаралды 12 МЛН
Sigma Girl Past #funny #sigma #viral
00:20
CRAZY GREAPA
Рет қаралды 23 МЛН
How much faster has Mojo's dictionary gotten?
7:40
EKB PhD
Рет қаралды 832
I’m going to cry…
0:28
GothamChess
Рет қаралды 1 МЛН
5 Tips To Achieve Low Coupling In Your Python Code
18:30
ArjanCodes
Рет қаралды 94 М.
Coding Adventure: Chess
29:22
Sebastian Lague
Рет қаралды 3,7 МЛН
3 Simple Ideas From Functional Programming To Improve Your Code
22:49
Protocol Or ABC In Python - When to Use Which One?
23:45
ArjanCodes
Рет қаралды 197 М.
Python Logging: How to Write Logs Like a Pro!
11:02
ArjanCodes
Рет қаралды 155 М.
The day of the sea 🌊 🤣❤️ #demariki
00:22
Demariki
Рет қаралды 85 МЛН