💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.
@ProgressiveDeveloper11 ай бұрын
Hey, Arjan it's been a while now following your design guide videos. But the real problem is that, is it good to place more than once class in a single file, I have been coding in PHP where every class takes it's own file, the code is simple to refactor in that way. What are thoughts?
@asifiqbal212 жыл бұрын
Thanks Arjan for part 2 of the refactor. I really enjoyed watching the refactoring of my code.
@ArjanCodes2 жыл бұрын
Hi Asif, thank you for supplying the code and glad to hear you enjoyed it. It was a lot of fun working on your code!
@tiagovla2 жыл бұрын
Also, enumerate(list,1) starts indexing at 1.
@BLRMalcolm2 жыл бұрын
@ArjanCodes I know you are using vim shortcuts now on vscode. I realized that at 5:37 your deleting pattern were always the same. Maybe it was easier to do it once, move your cursor to the next line and press (dot) which repeats the last command. This is something I forced myself to get used to and now it's a fundamental tool in my daily coding routine. (If this didn't work because it's a complex command, then it should be done by a simple macro (press enable macros, a letter to start recording and store it on that letter ( to store it on ) then do your thing once and move down and press to stop the macro recording. Now call the macro stored in a by doing and it will automatically do what you did before). This weird things are what make vim hotkeys amazing. Just try them in the wild and it will make your brain have goosebumps for a moment. Thank you for all your videos !!!
@claudiafischering9012 жыл бұрын
That is nice to know. Thx.
@Stroid92 жыл бұрын
Love the code roast videos! One thing I was thinking of is that instead of having one player entity and one CPU you could have two abstract players that you use dependency injection to choose the type of player. This allows you to pick one player and one CPU or two players or two CPU(if that even makes sense) Hope you understand what i mean!
@ArjanCodes2 жыл бұрын
Yes! It will make the game logic more generic. I thought about doing this but in the end I decided to skip this because the video became already quite long.
@nukedoom2 жыл бұрын
Thank you for that series. I’m not a coder, but code a lot for work. I’m self taught, and I always wonder how a pro coder would write the code I’m writing. This series helps a lot my self confidence as I can identify what I’m doing right and wrong. First I write a spartan code that just works (usually a giant script that does things step by step) and I refactor it adding classes and and separate functions. This is an excellent exercise for improving coding logic
@DegenOne2 жыл бұрын
These code roasts are fun and informative! Keep it up.
@ArjanCodes2 жыл бұрын
Thank you, will do!
@tiagovla2 жыл бұрын
It's a bit suspicious how he starts winning games after "cleaning up the code" Kappa
@Ghost-Raccoon2 жыл бұрын
13:40 I feel that conceptually a scoreboard is always part of the game and not an independent object. One could argue that the scoreboard could be used for different games but a typical ingame scoreboard is part of the game.
@virtualraider2 жыл бұрын
I love that you use annotations extensively, they make code so much more readable. Around minute 10:52 you added `Optional`. While it's correct, I always advocate for the alternative ` | None`. I think it's more explicit to say ` | None`, because the word Optional is frequently misinterpreted as "the variable is optional", rather than "the VALUE is optional". I see that a lot at work. For instance, when we see a signature like this it should be obvious that the positional argument is required but it's value can be `None`, yet a lot of people read it as "the argument itself is optional" ``` def foo(bar: Optional[int]) -> Optional[bool]: ``` I think this is more explicit: ``` def foo(bar: int | None) -> bool | None: ```
@ArjanCodes2 жыл бұрын
That’s a good idea. I’ve used Optional until now because the ‘| None’ syntax was added to Python only recently, but I agree with you that it’s clearer.
@astronemir2 жыл бұрын
Hey that’s a good idea. I actually dislike the optional syntax a lot so this is a good way around it.
@dabusdruva Жыл бұрын
Hi Arjan, these videos is great. It was really difficult to find part 2 of this series after watching the first part. Could you add a link in part 1? I think it would help a lot of people. Great work, Sir.
@smanzoli3 ай бұрын
The app is really simple, so my refactoring would change from OOP to Procedural and achieve the same result with 1/4 of the coding 😅 Thanks for the video, it was great btw!
@davidlakomski39192 жыл бұрын
Riker suits you very well that's right! 😂 A great character btw
@Shr11mp2 жыл бұрын
I LOVE this series!
@ArjanCodes2 жыл бұрын
Thank you, Ryan, glad to hear you like it.
@alessandroferrari21662 жыл бұрын
great video as usual, Arjan (I've to catch up a bit with all your latest videos!). A suggestion for the future. What about refactoring code by writing tests first? In this way you know for certain that the refactoring didn't break anything, instead of having to run manually the program at any change. Ofc, surely these videos would take longer to make. Just a suggestion from a stranger on the Internet :)
@ArjanCodes2 жыл бұрын
Hi Alessandro, good suggestion that several commenters have also made. I didn't do this on purpose in these refactoring videos because I was afraid this is going to take too much time away from seeing the actual design changes, but I'll look into it.
@StevenMartinGuitar2 жыл бұрын
Commenting before I've seen it, but it would be great if you could create a second visual version of this game using your new UI interface to show/prove how useful and easy setting up classes this way can be for making further developments
@ArjanCodes2 жыл бұрын
Yes, sounds like a good follow-up, thanks!
@MScottBlake11 ай бұрын
@@ArjanCodes I think there is a lot of value in showing how you maintain code over time. There are new elements in newer versions of python, there's still another UI class you could do, etc. I'd love to see you resurrect an older project such as this one for a new video to show common tasks to modernize.
@rahulprasad23182 жыл бұрын
I disagree with how you handled the scoreboard display. now scoreboard and UI are coupled. Now you will be restricted to always have a UI to use this. What if say you are training a ML model and need this to generate training data? The correct approach is to add a get_current_scores() which results a structure ( dict or 2d array) of player and score. Now UI must parse this and display however and whatever it wants. And if someone wants to generate training data, they can just call get_current_score
@xnick_uy2 жыл бұрын
Good point. I think that a workaround for keeping the scoreboard as it is would be to implement a form of "null UI" that adheres to the protocol but actually does nothing. Then you can use it for the training model without much hassle.
@jessta3142 жыл бұрын
In this case the UI protocol is a fairly general output and doesn't include anything that would force some kind of on screen display. If you were training an ML model then it would be interested in subscribing to that output (just like a human would) and could do that by implementing the UI protocol.
@abdelghafourfid82162 жыл бұрын
I would love to see you refacoring some complex streamlit app since it's quite popular and simple to use, but thing can go out of control very easily when having multiple functionalities in the same app
@marcotroster82472 жыл бұрын
One thing: putting together the message in the rules module violates your UI abstraction. Moreover, I'd put the rules back into the game class, now that it's only 20 lines 😉 Then, you could even parameterize the rules in the Game class such that the game can be played with different sets of rules. And I'm not really convinced by the scoreboard class. It simply doesn't do much. Maybe call it GameState because it's basically bundling all the stateful stuff of your Game class. That way it becomes clearer 😉
@ArjanCodes2 жыл бұрын
Good suggestions, thank you Marco! I might revisit this code for a do over and also introduce a GUI.
@marcotroster82472 жыл бұрын
@@ArjanCodes You're welcome. All honor belongs to you because you taught me how to design software 😂 Nice to hear that you consider putting a GUI. I'm already excited!
@smalltimer666 Жыл бұрын
@@ArjanCodes YES!
@MrAndyspickle2 жыл бұрын
Hey Arjan, I was just wondering what some of your keyboard shortcuts are. Things like deleting all right with in the brackets?
@johnsonshek2 жыл бұрын
I think Arjan uses vi mode, and then can delete using "di(" or "ci(" for change
@gehbittedasgibtsned2 жыл бұрын
nice work, please add unit tests
@harshraj22_2 жыл бұрын
get_winner function at 7:56 isn't too readable anymore. any thoughts on this ?
@МихаилТерентьев-ц6в2 жыл бұрын
Could you please recommend some free exercises resources covering that topic? (I mean refactoring and optimization of code) I just don't want to lose and forget all such nice techniques 10 minutes after watching your videos. Thanks
@smalltimer666 Жыл бұрын
Hi, any ideas on how one can implement this with multiple players ? Especially if the players connect to the game from different terminals etc. ?
@sami35922 жыл бұрын
Thank you sir
@jeancerrien30162 жыл бұрын
The code @14:36 surprised me, line 4 in particular. Is the type hint really meaningful? If you changed user_name in line 2 to be an int, would something complain?
@metal5712 жыл бұрын
Only if using the mypy linter which I don't think he is in this video. Could be a good video topic all on its own
@kelthazur2 жыл бұрын
Regarding the Enumeration at the end. Why not stick to auto() and refer to the enum.name.lower()?
@Klej0aka0Klej2 жыл бұрын
What's the shortcut in VSC to change names so easly? Just like in 11:05?
@_JNotJay2 жыл бұрын
F2 to rename a variable. Works across multiples files too!
@jereziah2 жыл бұрын
what's the shortcut he was/is using for the renames? circa 11m15s
@ArjanCodes2 жыл бұрын
I use F2 to change a variable name. It also takes care of name changes across multiple files.
@ch4sethe5un2 жыл бұрын
Arjan, could you do a video on page object models (POM) in python?
@AMIRKIZER2 жыл бұрын
Any practical tips for starters?
@juanbetancourt51062 жыл бұрын
This cut down the elif portion at get_winner() ordered_tuple = tuple(set((entity1, entity2))) if ordered_tuple in RULES: return (ordered_tuple[0], "some message")
@ackrman2 жыл бұрын
Great content as always. I have a question. TL;DR VERSION - Need help in creating an api where uploads and downloads can be done via streaming mechanism for huge data sets for thousands of concurrent users. I have an application where people download and upload stuff But the issue is many people are hitting downloads and uploads and due to this 504 is becoming a common occurrence on the server. I tried increasing the specs of server but it didn't helped me much. Can you advise me how can I achieve streaming of data for downloading and uploading? So many people can do this concurrently and at the same time this operation won't horde memory. By the way I have huge datasets and I can't keep them in memory so need to do in chunks.
@sthiag02 жыл бұрын
"remove documentation because it's taking a lot of space" WRITE THAT DOWN WRITE THAT DOWN!
@claudiafischering9012 жыл бұрын
Thanks for part 2. My solution for the if elif else problem is following: [...] winner, message = get_winner(player_entity, cpu_entity) if not winner: self.ui.display_tie() else: winner_entity, winner_name = [player_entity, self.player_name] if winner == player_entity else [cpu_entity, self.cpu_name] self.ui.display_round_winner(winner_name, winner_entity, message) self.scoreboard.win_round(winner_name) [...] It is short and I think readable enough or what do you think about it? I like this series. I am happy if it continues^^
@claudiafischering9012 жыл бұрын
Video Position was on 24:40 - 24:55. I missed too add these. sorry
@Cookie-mv2hg2 жыл бұрын
How can we submit codes for you to 'Roast'? I self-taught and made my very first larger game using pygame with the puzzle "untouchable"....annnd I think is quite a mess. I'd like to refactor the code with my own but I'd also like a review from professionals. Is there any chances to?
@ArjanCodes2 жыл бұрын
You can submit your code for a roast on my Discord channel (there’s a dedicated channel for this). The invitation to join is in the description of the video.
@Cookie-mv2hg2 жыл бұрын
@@ArjanCodes Much appreciated!
@padreigh2 жыл бұрын
enumerate(Entity, 1) - will start at 1
@ArjanCodes2 жыл бұрын
Didn’t know that, thanks!
@endredimarci2 жыл бұрын
How do I submit code for this series? I'd love to be roasted and some professional input would be greatly appreciated :D
@brunosompreee2 жыл бұрын
F2 or right click > rename symbol
@ArjanCodes2 жыл бұрын
If you join my Discord server (the invite is in the description of the video), there’s a channel where you can submit your code.
@alexandarjelenic77182 жыл бұрын
6:10 who thought this was funny? I did, even though it might not have been intended to be a joke
@coldhardwick2 жыл бұрын
I can't stand the Star Trek episodes with Q. Anything with Q is just annoying. Like one long deus ex machina...
@dpgwalter2 жыл бұрын
I don't think removing redundant comments is a useful thing. A lot of times having the documentation helps build a mental idea of the function, even if it does something very simple. If anything, comments should rather be simplified than completely deleted.
@aflous Жыл бұрын
You almost never need comments
@corlevtec2 жыл бұрын
for the last refactor... if not winner: self.ui.display_tie() else: self.ui.display_round_winner(self.player_name if winner == player_entity else self.cpu_name, winner, message) self.scoreboard.win_round(self.player_name if winner == player_entity else self.cpu_name)
@Gregplex2 жыл бұрын
actually just else: self.ui.display_round_winner(winner, message) self.scoreboard.win_round(winner) I feel you could even pass None to scoreboard.win_round and ui.display_round_winner and not have any ifs in the play method.
@romulopontual62542 жыл бұрын
This reduces the code redundancy... I am not sure it is clearer! winner, message = get_winner(player_entity, cpu_entity) if not winner: self.ui.display_tie() winner_name = self.player_name if winner == player_entity else self.cpu_name self.ui.display_round_winner(winner_name, winner, message) self.scoreboard.win_round(winner_name)