7 Python Code Smells to AVOID at All Costs

preview_player
Показать описание
This video shows 7 code smells that point to poor design decisions, as well as how to fix them. I'm pretty sure you're guilty of at least one of these smells (as I was in the past :) ), and knowing these will help you write much cleaner, more robust code.

🎓 Courses:

A few interesting links to articles and books:

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

👀 Channel code reviewer board:
- Ryan Laursen
- Sybren A. Stüvel

🔖 Chapters:
0:00 Intro
1:27 Explaining the example
3:12 Code smell #1: imprecise types
5:52 Code smell #2: duplicate code
7:31 Code smell #3: not using available built-in functions
8:53 Code smell #4: vague identifiers
10:05 Code smell #5: using isinstance to separate behavior
13:40 Code smell #6: using boolean flags to make a method do 2 different things
15:58 Code smell #7: catching and then ignoring exceptions
17:29 Code smell #8 (BONUS): not using custom exceptions
21:30 Final thoughts

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!
Рекомендации по теме
Комментарии
Автор

Don't store monetary amounts in a float! Rounding errors and money don't mix. You should use a decimal type or integer (with the latter getting divided by 100 for display).

andrew_ray
Автор

First time here. I gotta say: I'm in love with the way you explained why these changes had to be made. They're not just out of "because I say so" great job mate.

yeagerdd
Автор

This man explains stuff so calmly and I love his accent.

Corporal-Clegg
Автор

0:00 Intro
1:27 Explaining the example
3:12 Code smell #1: imprecise types
5:52 Code smell #2: duplicate code
7:31 Code smell #3: not using available built-in functions
8:53 Code smell #4: vague identifiers
10:05 Code smell #5: using isinstance to separate behavior
13:40 Code smell #6: using boolean flags to make a method do 2 different things
15:58 Code smell #7: catching and then ignoring exceptions
17:29 Code smell #8 (BONUS): not using custom exceptions
21:30 Final thoughts

yt-sh
Автор

SMH I finally learned what enum does. This quickly turned from a code fragrance video into a level up the code video for me.

ighsight
Автор

thanks for doing refactor walk-throughs of implementing concepts, it really does a nice job of reinforcing how it should be after refactor, a lot of tuts just stop at "do this and it will be better" and you going the extra mile is really nice!

proudbeme
Автор

Did you notice that the refactoring at 5:52 "Code smell #2: duplicate code" is the exact reverse operation of the refactoring at 13:40 "Code smell #6: using boolean flags to make a method do 2 different things" ?
In the first case we combine multiple functions into a single one by adding a parameter.
In the second case we remove the parameter and split the function in two.
In one case it's better to combine to avoid duplication and in another it's better to split to avoid complicated code.

Goes to show programming is not about blindly memorizing language features and rules but there is a sense of 'taste' involved.

thomasburette
Автор

I was putting away a large refactoring job for days, but after getting this in my feed I got more confidence in myself seeing these incredibly well explained refactor examples. Managed to finish it in a few hours. Really enjoying your content.

thatone
Автор

Thanks for this enjoyable Python code refactoring video. Just FYI, “code smell” is much older than that refactoring book (1999]. The first time that I encountered “code smell” was in 1978 in a code comment, “This code stinks; hold your nose while you read it!” I’m sure it is even older than that.

bevintx
Автор

Honestly, the best python YouTube channel out there for non-beginners! Incredible! Thank you for everything, I'm learning so much from you

ShanilPanara
Автор

I think it's important to know when one should or should not use list comprehensions. Just because something can be done as a nifty one-liner doesn't mean it's always the ideal solution. I see too many mid-level developers try and get fancy cramming logic into them to reduce characters at the expense of readability, which is just another code smell. If the two methods perform the same and one is significantly harder to read by the next developer, I'd argue that's worse. Your example does not fall into this category, but when you see people start chaining ternary logic operations in a comprehension it can get ugly quick. List comprehensions are usually a bit faster than implementing via a for loop though due to the time appending each item rather than initializing the full list with the comprehension results. Great video.

coltonmccormack
Автор

i love how you sped up the parts where you type. usually these videos where people write code in real time get boring quickly because you have to wait for them to type something out. not you however, you're making this really entertaining to watch :D

jemand
Автор

Great video as always! I think another thing to mention is maybe to think through what responsibilites each class has and/or should have, for example moving the pay() method to the Employee class as you did in the video, maybe move that responsibility back to the Company class with maybe an abstract payment handler that handles it, as it seems kind of weird for an Employee to have the responsibility to pay themselves. Nevertheless, thumbs up and great work!

quantumjolt
Автор

There are countless amazing resources to learn python, but as far as going from there and bettering existing skills I don't think any other resource online has given me more practical tips (in one place, with place, easy to digest content) than this channel. Thanks Arjan!

unsuspicious_youtuber
Автор

I'm still new to Python programming and I just learned a ton in these 20 minutes!

JeremiKress
Автор

I found you from reddit post and I'm glad I did, this video was superb. Amazing work!

sebastiansoto
Автор

The custom Exceptions bit was actually really helpful for me! Thank you Arjan!

Sciencedoneright
Автор

The algorithm brought me here. Love the instruction and examples. Great work!

grrsa
Автор

This video felt like a senior developer 1 on 1 reviewing my code, it was really helpful, thank you :)

SzaboB
Автор

I like how you're like
Good code => nice smell
Bad code => bad smell
Lmao

Sciencedoneright