More Python Code Smells: Avoid These 7 Smelly Snags

preview_player
Показать описание

These are 7 code smells to avoid plus a bonus smell. I describe each smell using a Python example and then show you how to fix it. At the end of the video, I have a few general tips to help you avoid introducing code smells in the first place in your design.

🔖 Chapters:
0:00 Intro
0:31 Explaining the example
2:45 What is a code smell?
3:04 #1 Too many parameters
5:03 #2 Too deep nesting
10:01 #3 Not using the right data structure
12:19 #4 Nested conditional expressions
13:39 #5 Using wildcard imports
15:33 #6 Asymmetrical code
16:58 #7 Using self when it's not needed
18:31 #8 (BONUS): Not using a main() function
19:02 Tips for avoiding code smells

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

Really good content, I would recommend this channel to anyone who wants to make their code cleaner.

jamesrea
Автор

For example, one code smell I purged from my project recently was over-using
from <module> import thing1, thing2, thing3, thing4, thing5, ..., thing10
It added a lot of useless noise and made it tedious to swap out objects for something else from the same method.
This is a gui project with pyside6, so importing all those widgets was messy until I just used
import PySide6.QWidgets as Qw
To simply refer all things by prefixing Qw. rather than all those explicit imports.

The video you made on pydantic also helped a lot, making the way I store data much, much clearer and easier. Before, I had been using a massive, deeply nested dictionary, and remembering how to spell all those key strings was so prone to bugs. It still gives me shivers.
Thanks!

voxelfusion
Автор

The first programming YouTube who can actually code!!! Wtf! 😂😂 love the videos, keep it up, I’m learning a ton!

rd
Автор

Regarding your first code smell: I feel that having meaningful, but possibly inaccurate, default values is smelly. A programmer who neglects to provide a car's fuel type by mistake should get an error, not an electric car. I would support using `None` or some enum value that represents an invalid value.

For a developer using your code base as an API, the same amount of mental effort would be needed to determine whether a parameter can be excluded because the default is the correct value as would be needed to simply include the value.

moomoocow
Автор

Really appreciated the time you invested in to create this content. Videos beyond basic stuff is hard to find.

Fitri-mnje
Автор

Hey Arjan, fellow developer here, this is a very nice list of refactors and is cool to already have an idea on what you are going to suggest while you are describing the problem.
Keep it coming! It's very valuable content

AR-lyzt
Автор

This channel is pure gem. Your way of explaining, speaking and use of examples as well as visualizations is simply awesome!
Thank you und keep it up!

ArberAboow
Автор

Thank you so much for doing these videos! They are helping me IMMENSELY on my journey to become a better developer. I have to watch and rewatch a lot of them, but over time stuff starts to stick, and it makes a huge difference.

maxwell
Автор

This channel is a hidden gem for me as a data scientist who’d love to learn more about how to make my code cleaner and adhering to best practices. Thank you for the awesome content!

AlejandroLamKhoa
Автор

I love your content because I targets the niche of people who know Python, aren't beginners and want to take their knowledge to a more polished level

billywang
Автор

replacing 2021 with current year was quite unexpected :) a good refactoring to have a happy new year %)
In code smell 4 you don't need else because of return early pattern.

itnabigator
Автор

Marvellous videos. This is my favourite python channel.

Regarding the refactoring to put the conditions that must be satisfied first, and returning an error if they are not satisfied, I have heard that called ‘guard conditions’ which makes sense to me.

In python they may be a list of ‘try’ ‘except’ which if they all pass, then the function returns a value, if any of them fail, it returns an error or none or whatever.

IterativeTheoryRocks
Автор

Great content! Impatiently waiting for a video on design patterns for production-level machine learning projects.

abdullahmobeen
Автор

Legend!!! What a great content, presented in such an easy to follow along. And with a sense of humor! Huge fan of the work you are developing!

Victorinoeng
Автор

I know comments are important for YT, but I can't help but say Thank you again. I know it takes a lot of work to produce at YT video and your hard work is much appricated! I installed pylance and black by the way.

mauisam
Автор

I love your videos!! Coming from a barely intermediate level knowledge of software design and few years experience coding, these videos showing code the whole time and putting the theoretical ideas in practice are fantastic! I prefer to watch your refactoring videos over TV any day! Thank you very much for the awesome content!

iChrisBirch
Автор

I will love to see a video regarding managing application configuration in Python, like taking configuration values from environment variables, text files, etc.

mihaimyh
Автор

Excellent content, I think this is the only channel that I get excited when a new video appears. I’m looking forward to more of your podcast, left a 5 start review there as well!

_mactastc
Автор

just watch your videos for fun but that fun making me more better
software developer

fashionvella
Автор

Thanks Arjan, you explain well. Goed bezig. I received your content through the Python Weekly news letter.

wspek
visit shbcf.ru