Professional Code Refactor! (Cleaning Python Code & Rewriting it to use Classes)

preview_player
Показать описание
In this video we take the code from my “How to Program a Game (in Python)” tutorial and refactor it to be of a more professional quality. To do this we abstract out similar parts of the code into their own classes & files. Once the new code is written, we go through some examples of how we can extend its functionality in fun ways. We make a couple more difficult levels of the game which is made very easy by the new code architecture. The final product is a lot more similar to code you would write as a full time software developer at a company like Google, Facebook, etc…

As always I left a video timeline in the comments! If you enjoy this video please consider giving it a like & subscribe for future content :). If you have any questions let me know in the comments!

Follow the homies!

Source code for Game (original & refactored):

Link to original How to Program a Game (in Python) Tutorial:

Link to video on Classes & Object Oriented Programming:

Additional information on Getters & Setters:

Some great resources if you want to write better/cleaner code! (affiliate links)

Join the Python Army to get access to perks!

---------------------

Follow me on social media!

---------------------

Video Timeline! (& some additional resources)
0:00 Video overview & code setup
3:04 Creating a Player Class
10:43 Creating subclasses for our Enemy & HumanPlayer
11:26 Creating a Color class
14:35 Creating a screen class or all our game visuals
27:00 Creating a game class for all our game logic
32:54 Information on Getters & Setters in Python
43:36 Testing our code & Debugging issues
47:20 if _name_ == "__main__" information
48:26 Creating more difficult game levels using our new class structure!
54:00 Fixing the "cheat" where you can go off the screen
55:44 Loading in custom images as the enemy blocks

*I use affiliate links on the products that I recommend. I may earn a purchase commission or a referral bonus from the usage of these links.
Рекомендации по теме
Комментарии
Автор

Video Timeline! (& some additional resources)
0:24 - Video overview & code setup
3:04 - Creating a Player Class
10:43 - Creating subclasses for our Enemy & HumanPlayer
11:26 - Creating a Color class
14:35 - Creating a screen class or all our game visuals
27:00 - Creating a game class for all our game logic
32:54 - Information on Getters & Setters in Python
38:09 - Bringing it all together in our main.py file!
43:36 - Testing our code & Debugging issues
47:20 - if __name__ == "__main__" information
48:26 - Creating more difficult game levels using our new class structure!
54:00 - Fixing the "cheat" where you can go off the screen
55:44 - Loading in custom images as the enemy blocks


Additional resources to write good clean Python code!



Hope you guys enjoyed this video! :)
Please like & subscribe if you did!!

KeithGalli
Автор

I feel that most coding channels never get the respect they are due, shunned by the algorithm, for more colorful, braindead, and clickbaity videos. I hope that people realize your skill and your videos. keep up the good work!

luvmydawg
Автор

My Man has done it again. This channel aint popular but in future the upcoming programmers will be checking in here for more releases and more information. Thank you Keith Galli you are on the right part of the journey.

GeopoliticsExplained
Автор

Haven't watched the whole thing yet, but the intro is so funny hahaha!!! I'll have another interesting thing to watch for this upcoming week!:)

jenn
Автор

The way you used super is truly amazing. Very clean and efficient code.

abdullahraihanbhuiyan
Автор

Brilliant Explanation and shows the importance of clean code from the beginning :) Keep going mate

abdallahwallyallah
Автор

Did you do the refactoring on the fly by just looking at your previous code? I was able to understand everything as the video went on ( thanks to your awesome explanation ). But I can't imagine me coming up with the big picture of 5 separate files along with the functions in each class while starting such a task from scratch.

anoubhav
Автор

Finish learning 6 tutorials in your channel, LOVE IT! CAN'T STOP! from zero knowledge about python to be able to code my assignment that requires data analysis alone! Thank you so much! By the way, do you have a tutorial about statistics analyzing using python? Like drawing a normal distribution pdf, etc. <3

lorraineli
Автор

3 minutes in and I can already tell this is a good video with quality advice. Way too many poor quality videos from novice programmers out there.

kitsurubami
Автор

Great content 👍 Unittests tutorial would make a great addition as a future video in this series.

laurentzerah
Автор

Sou fã da sua didática - e dessa metadidatica, sobre a importancia do aprendizado correto

brunomerola
Автор

This was a really useful video. Really helps drive home the point of classes and oop

gmorf
Автор

37:45 it is redundant to return True inside the if and False outside the if because the detect_collision is already returning them like that, you can return directly the collision detection. Do you agree?
Or did you use the "Explicit is better than implicit." from the Zen of Python ?

NNThinking
Автор

Muchas gracias. Ver este tipo de videos donde se ve el trabajo me es muy útil.

ErdosainNueve
Автор

Ok, now take it one step further and really refactor it. I see so many improvements you can make. Anyhow, make a video on using @datatype

tobeypeters
Автор

Please Do More of these awesome python videos !!!

sainath
Автор

thank you Keith for this wonderful method of teaching (sorry not teaching but educating)

moussamoise
Автор

The detect_collision looks bit too complicated to me. I would prefer having explicitly named variables keeping each part of the logic. Even something like x_overlap=(some logic), y_overlap=(some logic) and then using them helps.

anindya_manna
Автор

hey guys welcome back to my channel 🤠🤠

realneosi
Автор

very good bro...
i also created one game!!

shabdyadav
join shbcf.ru