A Quick Code Simplification Trick // Python Tips

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


👍 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!

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- Sybren A. Stüvel
- Dale Hagglund

#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!
Рекомендации по теме
Комментарии
Автор

Maybe also worth mentioning cached_properties that work exactly the same, but are only computed once when you first access them. If you have a lot of immutable classes that have expensive calculations in properties, this can be a quick and easy way to increase performance

dylanrobins
Автор

I keep checking your videos. Often, they don't apply to the project I'm working on, but they seep in like some sort of penetrating oil. The concepts then emerge later on when I'm figuring out how to fix some problem or other, or how to approach a novel situation when coding.

Keep up the good work!

YoutubeHandlesSuckBalls
Автор

I very like that shorts that are perfect for the smartphone and to watch in between!
Thanks also for your other content.

nilshamacher
Автор

Cool video, and good advice on keeping property functions simple. It typically isn't a good idea to hide the fact that actually a function is being called, due to unexpected side effects being a possibility.

voxelfusion
Автор

God I love it when youtubers make videos straight to the point.

friday
Автор

I'm not a python dev but I feel like something gets lost for the consumer when its not explicitly clear they are calling a function; but maybe this is not an issue in python practice.

sfulibarri
Автор

Nice short video.. and videos!
Keep them coming... just signed up to the software designer mindset yesterday, very happy!

stifferdoroskevich
Автор

I love this format! Easy to follow, and not abstract at all. Keep it going, at least for the tips this format can support!

antonindejesus
Автор

Properties can be writable, too. I often use them when I write a Python binding for some lower-level C-based API, to wrap getter/setter function pairs. Tip: it is often helpful to set ﹍slots﹍ in this situation, to guard against typos. (Ask me how I know.)

Properties are just an instance of a more general Python concept, known as “descriptors”. Now there is a language feature that can do your head in ...

lawrencedoliveiro
Автор

I have a couple questions based on other code I've read, if you ever get a chance to weigh in with your opinion:

- Is there a good reason not to call the property 'get_circumference'?
- Alternatively, is there a good reason not to separate them like this:

def
# do stuff here

@property
def circumference(self):
return

Thanks, love your vids!

RabidHobbit
Автор

Or just turn it into a variable with a value of 2 * radius * pi instead of making it a function, it also saves computational time as the computer doesn't have to calculate it every time you check the property.

DKaldes
Автор

I love properties, they remind me of computed columns in relational databases

kellymoses
Автор

so its less expensive then a normal function call? or just a syntactic sugar.

fusn
Автор

what does x: float = 0 and radius: float = 1
I didn't see thus anywhere and I particularly didn't understand why use :
Can I use = instaed of : ?

wasimgamer
Автор

Hmm, I could definitely have used this for accessing certificate thumbprints on a project I just wrapped up a couple months ago.

Great tip!

NicholasSandar
Автор

why shoot it like that (portrait mode) . Can't really see the code !

ramshastri
Автор

Then, How do u tell property apart from function? Hover over?

rabinzx
Автор

Which is the difference with __postinit__ ?

nicolameoli
Автор

I don't think making properties and methods look exactly the same makes the code easier to read.

MostafaZeinali