Cohesion and Coupling: Write BETTER PYTHON CODE Part 1

Cohesion and Coupling: Write BETTER PYTHON CODE Part 1

ArjanCodes

3 года назад

214,581 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

David Cueter
David Cueter - 15.11.2023 16:26

Best explanaition, thanks

Ответить
Harish B
Harish B - 22.10.2023 20:16

Great Lessons!

Ответить
Jake Bersabe
Jake Bersabe - 19.08.2023 06:46

Thanks, Arjan!

Ответить
DeepFriedOreo
DeepFriedOreo - 25.07.2023 02:10

"Can you think of a software library that's badly designed in terms of coupling and cohesion?" - Mine? 🤣

Ответить
mordeth
mordeth - 05.06.2023 10:44

you look similar to john green

Ответить
Kerreber
Kerreber - 22.04.2023 17:51

Top dank je🎉

Ответить
SMC GPRA
SMC GPRA - 20.04.2023 08:46

Arjuna of programming

Ответить
Hans Dietrich
Hans Dietrich - 18.04.2023 14:03

Thumbs up for leaving all the little typos etc. in the video. Everyone runs into that :) Great video! Though, my two cents about naming, as it's all about refactoring anyways: I guess the class names could have been chosen a bit better. VehichleInfo is not descriptive. It doesn't tell me immediately, that it e.g. doesn't include a license number or der thumber of wheels on the car. A bit better would be VehicleType. And the same for Vehicle. VehicleRegistration would be more precisely describing, what it actually does.

Ответить
Erik Eriksson
Erik Eriksson - 25.03.2023 10:10

Your variable names are wrong. The tax_percentage is not percentage, then it would be e.g. 5, not 0.05. The variable should be named something like tax_fraction. Also "Tesla model 3" is not a "brand", it is a model, the brand is just "Tesla".

But you are right about the exampel. Programming teaching used to start with "Algorithms and data structures". Now many people think that just creating some classes for things and passing objects back and forth is the solution. For most conventional types of applications and software, organizing our data into proper data structures to enable clean and efficient processing is the key.

Ответить
Philipp Holl
Philipp Holl - 01.03.2023 23:47

Your presentation of cohesion and coupling was very clear! However, I noticed that the refactored code is about 50% longer than the original. We also went from 2 classes and 3 methods to 4 classes and 11 methods (counting constructors). I believe the pure amount of code is also an important factor in maintainability.

Ответить
bluefanta
bluefanta - 25.02.2023 18:07

I think I have to think through my Django application which is a headache.

Ответить
E Nsk
E Nsk - 17.02.2023 10:48

You call them metrics, but cannot compute them? 🤔

Ответить
Jordi
Jordi - 14.02.2023 18:44

Unfortunately you perpetuate the habit of declaring instance fields in outside of your init method. This is a bad habit IMO since this kind of declaration suggests that these variables are actually class fields instead of instance fields. Todays Arjan would probably use dataclass anyway.

Ответить
Soul Weaver
Soul Weaver - 05.02.2023 12:18

I just got a pretty project idea, how about visualizing a code to see it's degree of cohesion and depth of coupling chains?
Any idea if something similar to this already exists?

Ответить
Alvaro C
Alvaro C - 03.02.2023 18:51

I hate python but I watched the video anyways because nowadays almost nobody talks about cohesion and coupling. As you stated, the concepts shown apply to any language since they are abstract, language independent ones. Grats!

Ответить
John Morrison
John Morrison - 20.12.2022 16:56

cohesion -> "atomicity of purpose"

Ответить
Anthony
Anthony - 08.12.2022 22:38

You are the best!!!

Ответить
Jakub Parcheta
Jakub Parcheta - 06.12.2022 14:36

Thank you Arjan for sharing your knowledge in such easy and clear way, appreciate

Ответить
Magnus Anand
Magnus Anand - 30.11.2022 07:07

Great video Arjan.
One question:

1. def create_vehicle():
return Vehicle(id, license_plate, self.vehicle_info[brand])

2. def add_vehicle_info(self, brand, electric, catalogue_price):
self.vehicle_info[brand] = VehicleInfo(brand, electric, catalogue_price)


Aren't this classes/methods too coupled with Vehicle and VehicleInfo?

Thanks 😜😜

Ответить
Kanwar Adnan
Kanwar Adnan - 13.11.2022 16:20

Sir, you are really amazing teacher. Your teaching style is very explicit and clear. But there are several other parts of the programming world I would like to learn from you, and these are (mentioned based on my interests)

1) Data Structure and Algorithms
2) Programming along with any GUI Library (I prefer tkinter)
3) Also teach us about Databases (SQL , NoSql (mongoDb etc))

Thank you Sir, I hope, We'll be blessed with these videos in future.

Ответить
Mr. Sith
Mr. Sith - 11.11.2022 10:46

Great video! However, I do have one question. Why do you define datatypes in the function? This does not have any meaning in Python.

Ответить
Ian Hopper
Ian Hopper - 28.10.2022 21:45

Thank you, Arjan. Superb content.

Ответить
Kwan Kim
Kwan Kim - 27.10.2022 13:31

Thanks!

Ответить
Huddeij
Huddeij - 25.10.2022 18:46

You won't find a carbrained dutch every day. Why, Arjan?

Ответить
Alexey Matveev
Alexey Matveev - 23.10.2022 18:49

great slogan: never stop explaining

Ответить
sean peart
sean peart - 08.10.2022 00:36

thank you for the great review

Ответить
Connor Kenway
Connor Kenway - 15.09.2022 08:07

Immensely helpful and well explained! Thank you so much...looking forward for more 😃

Ответить
cooliospeep
cooliospeep - 11.09.2022 12:45

Dear Arjan, thank you for sharing such a detailed and thoughtful video. I loved how you explain the though process of improvement. It's hard to find such content out there. Please keep going. I look forward to studying all of your catalogue (see what I did there!) ;)

Ответить
uniqe
uniqe - 07.09.2022 15:45

perfect

Ответить
Ahmed Ibrahem
Ahmed Ibrahem - 07.09.2022 07:35

Great content , I just saw two videos and falling in love with the channel .
Is the playlist sorted or it contains independent videos ?

Ответить
Das_Papa
Das_Papa - 03.09.2022 12:26

Excellent video. Thank you very much for this serie.

Ответить
Alex D
Alex D - 08.08.2022 12:11

Don't put things in classes when it is not needed. If you don' t use the instance 'self', then just have the function on the module level. Writing everything in classes just tells us you come from Java, and don' t yet fully understand what the purpose of Modules is in Python.

Ответить
Fredrik Mellström
Fredrik Mellström - 06.08.2022 10:28

Tack!

Ответить
Sadbhavana Bhardwaj
Sadbhavana Bhardwaj - 04.08.2022 21:09

VehicleInfo - instead of this class, we could have created a Brand class and it's subclasses with diff brands i.e. Volkswagen would be subclass of Brnad, etc., &these suclasses would have attributes like name, tax, catalogue_price, electric, etc., and in main create a function according to the brand name, create objects of that brand. is it a better option or not? sorry for asking such silly question...

Ответить
Kevin Jerome
Kevin Jerome - 31.07.2022 02:47

One interesting concept to add to this:

We could define the string we print as the return value of the _str_ method of the class instead.

Then in print method of the class put print(self).

That way we can both print the str with a call to print or get the str as an output to write somewhere else with str(instance)

Ответить
Rihhard
Rihhard - 30.07.2022 11:41

This is great for very quick drinking games. Take a shot everytime Arjan says vehicle.

Ответить
Daniel Bourke
Daniel Bourke - 19.07.2022 03:13

Absolutely outstanding video Arjan! I've been coding Python for ~5 years and always saw these techniques in play but never really knew where they were coming from. Looking forward to the rest of the series.

Ответить
Lorie Anne Castillano
Lorie Anne Castillano - 15.07.2022 17:47

Super thankful of this content!

Ответить
Amar Deep Singh
Amar Deep Singh - 09.07.2022 12:27

This is some really good quality video. You covered so many concepts , thanks

Ответить
W. Meijer
W. Meijer - 06.07.2022 17:10

What is the reasoning behind specificying types to the class attributes line 5`brand: str` VS to the instance attributes `__init__(self, brand: str, ...)`. When should you do which?

Ответить
wurly-dualach
wurly-dualach - 03.07.2022 11:35

Could you do a video on helper funcs like using a utils class or module or moving some code into a _func in a class? I've never seen any good guidance on this but I tend to feel like some of the sorting/formatting code I write is just clutter.

Ответить
Darrell Leong
Darrell Leong - 29.06.2022 13:40

Arguably, add_vehicle_info should not fall under Vehicle Registry (which is supposed to only process new registrations) but under a separate module that posts to the vehicle_info database. It would also be convention to add _ infront of generate_vehicle_id and generate_vehicle_license to indicate private methods.

Ответить
Leonardo Jaimovich
Leonardo Jaimovich - 26.06.2022 23:56

Good channel with very very good content!! Keep sharing your knowledge like this Arjan!!! Thanks so much!!!

Ответить
Ramiro Tell
Ramiro Tell - 12.06.2022 04:43

Im really happy to have found this channel, I'm really enjoying this Better Python Code playlist!, thank you!

Ответить
Lucas Simon
Lucas Simon - 07.06.2022 03:15

Nice video Arjan!

Ответить
E W
E W - 26.05.2022 16:30

Great video!
If we want to go further, we can create abstract class and give an object VehicleRegistry to the application and thus increase the decoupling
We can also create another class to compute financial stuff like prices, taxes and even reduction and thus increase coupling.

Ответить