5 tips for CLEAN Python code

  Рет қаралды 2,827

Carberra

Carberra

Күн бұрын

Sign up to Codecrafters for free, and get 40% off ANY plan when you upgrade!
app.codecrafters.io/join?via=...
(I mentioned your first year in the video, but the discount actually applies for any plan.)
-
One thing I always say to new developers is that it's easier to get into good habits than it is to break out of bad ones. In this video I give you my 5 top tips to keep your code as clean as possible -- just make sure you stick to the good habits!
00:00 - Intro
01:24 - Reduce nesting within statements
04:46 - Reduce code redundancy (ft. mixins)
09:08 - Split up complex functions [1]
13:11 - Maintain a good file structure [1-2]
16:46 - Follow PEP 8 (ft. Black, Isort, & Ruff) [3-6]
18:39 - Outro
[1] • Implementing OAuth 2.0...
[2] github.com/parafoxia/analytix
[3] peps.python.org/pep-0008
[4] pypi.org/project/black
[5] pypi.org/project/isort
[6] pypi.org/project/ruff
-
If you want to see more of me, join my Discord server!
/ discord
I get a lot of people asking, so here's my setup!
• Visual Studio Code: • My Visual Studio Code ...
• Terminal: • Make your terminal loo...
• Desk/recording gear: kit.co/Carberra
• PC build: uk.pcpartpicker.com/list/TmzGYN
Affiliations (I may earn a commission):
• Codecrafters -- 40% off any plan: app.codecrafters.io/join?via=...
• Keeper Password Manager -- 30% off your first year: keeper.io/r/EX4FB1C
-
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #howto

Пікірлер: 16
@ronalddebruijn613
@ronalddebruijn613 Ай бұрын
Thanks, I like your practicality!
@pythonwithjames
@pythonwithjames Ай бұрын
I really agree with the idea of splitting up complex functions, makes testing a lot easier too!
@Carberra
@Carberra Ай бұрын
Oh yeah testing for sure. There is actually something called cyclomatic complexity that can be used to measure the complexity of a piece of code. I intentionally chose to not mention it, but now kinda wish I had. Oh well lmao.
@rivencooler1951
@rivencooler1951 Ай бұрын
Good stuff and you got me idea on how to write the clean code. I have a request, can you make a view on your VS code setup/cnfiguration?
@Carberra
@Carberra Ай бұрын
Thank you! And I already have! There's a link in the description.
@gardnmi
@gardnmi Ай бұрын
Good stuff, one rule I have is to never use classes unless you have mutable data where you need to track it's state. Even then you may not need a class. It's easier to test, debug, and maintain function vs classes.
@Carberra
@Carberra Ай бұрын
Thank you! Honestly that's a pretty good rule.
@largewallofbeans9812
@largewallofbeans9812 Ай бұрын
I must disagree with you on this. Using classes means that you can handle a bunch of objects that have predefined operations rather than big if-elif trees with the same operations that may take a while to select. It's hard to explain in writing but in the project I'm working on, it makes performance slightly better.
@epicmoofish3726
@epicmoofish3726 Ай бұрын
@@largewallofbeans9812if you are worried about performance you are using the wrong language
@justtil6749
@justtil6749 Ай бұрын
Classes allow for dependency inflection, and therefore better testing
@KavyanshKhaitan
@KavyanshKhaitan Ай бұрын
At 3:16 In my opinion, shifting the return False to the next line makes it less readable, and it should stay in an else block. BUT, the part after that makes it more readable.
@Carberra
@Carberra Ай бұрын
Yeah it wasn't the best example for that specifically, but I just wanted to show off that's generally how it would work. It would work best where there were multiple negative cases you needed to pick off.
@KavyanshKhaitan
@KavyanshKhaitan Ай бұрын
@@squishy-tomato yeah thats prob why. Since I never read code in that manner, it looks wierd.
@synchro-dentally1965
@synchro-dentally1965 Ай бұрын
"y" no love?
Liked Pydantic? You'll LOVE Msgspec
15:53
Carberra
Рет қаралды 10 М.
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 20 МЛН
БАБУШКИН КОМПОТ В СОЛО
00:23
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 17 МЛН
Женская драка в Кызылорде
00:53
AIRAN
Рет қаралды 500 М.
Python's contextlib is a HIDDEN GEM
14:55
Carberra
Рет қаралды 10 М.
Python itertools - The key to mastering iteration
20:03
mCoding
Рет қаралды 30 М.
8 Python Coding Tips - From The Google Python Style Guide
17:12
ArjanCodes
Рет қаралды 156 М.
7 Functional Programming Techniques EVERY Developer Should Know
21:35
5 Tips To Organize Python Code
12:16
Tech With Tim
Рет қаралды 225 М.
5 Useful Dunder Methods In Python
16:10
Indently
Рет қаралды 56 М.
Tower Defense Against ChatGPT
7:03
TheVimeagen
Рет қаралды 21 М.
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 122 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 377 М.
Modern Python logging
21:32
mCoding
Рет қаралды 167 М.
Little girl's dream of a giant teddy bear is about to come true #shorts
00:32