Тёмный

5 tips for CLEAN Python code 

Carberra
Подписаться 18 тыс.
Просмотров 2,2 тыс.
50% 1

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

Опубликовано:

 

26 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 18   
@pythonwithjames
@pythonwithjames 9 дней назад
I really agree with the idea of splitting up complex functions, makes testing a lot easier too!
@Carberra
@Carberra 8 дней назад
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.
@gardnmi
@gardnmi 9 дней назад
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 9 дней назад
Thank you! Honestly that's a pretty good rule.
@squishy-tomato
@squishy-tomato 9 дней назад
enums are classes with immutable data though
@largewallofbeans9812
@largewallofbeans9812 9 дней назад
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 8 дней назад
@@largewallofbeans9812if you are worried about performance you are using the wrong language
@justtil6749
@justtil6749 8 дней назад
Classes allow for dependency inflection, and therefore better testing
@ronalddebruijn613
@ronalddebruijn613 9 дней назад
Thanks, I like your practicality!
@rivencooler1951
@rivencooler1951 9 дней назад
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 9 дней назад
Thank you! And I already have! There's a link in the description.
@KavyanshKhaitan
@KavyanshKhaitan 9 дней назад
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 9 дней назад
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.
@squishy-tomato
@squishy-tomato 9 дней назад
depending on the linter rule set you're using, it'll actually complain if you leave the "else" keyword there - it's the "no-else-return" rule in pylint
@KavyanshKhaitan
@KavyanshKhaitan 6 дней назад
@@squishy-tomato yeah thats prob why. Since I never read code in that manner, it looks wierd.
@synchro-dentally1965
@synchro-dentally1965 9 дней назад
"y" no love?
Далее
5 Tips for Writing Clean Python Code
25:59
Просмотров 16 тыс.
Игровой Комп с Авито за 4500р
01:00
Monster shops mini mart 👻🛒 #shorts
00:49
Просмотров 9 млн
Вечный ДВИГАТЕЛЬ!⚙️ #shorts
00:27
Просмотров 2,5 млн
Python's contextlib is a HIDDEN GEM
14:55
Просмотров 9 тыс.
Will Python SKIP these versions?
9:58
Просмотров 2,9 тыс.
Python's 5 Worst Features
19:44
Просмотров 100 тыс.
Extending Phoenix LiveView with Hooks
19:11
What Makes A Great Developer
27:12
Просмотров 146 тыс.
5 Useful Python Decorators (ft. Carberra)
14:34
Просмотров 89 тыс.
God-Tier Developer Roadmap
16:42
Просмотров 6 млн
`const` was a mistake
31:50
Просмотров 121 тыс.
Игровой Комп с Авито за 4500р
01:00