Object-Oriented Programming (OOP) in Python – A Good Idea? 🚨🐍

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

Got this Python question from Kevin over Twitter: "Hello Dan, are you for or against object-oriented programming in Python and also in general? If against, why?"

In this video I share some of my thoughts on OOP in Python and whether or not you should invest time into learning OOP skills as a Python developer.

* * *

FREE Python Coding Tutorials & News:
Рекомендации по теме
Комментарии
Автор

Great video again, Dan! I‘m very much into web scraping/data science and have never felt the need for OOP. Still there is this nagging feeling that I‘m missing out on something by not using OOP in these areas. Would be nice to hear more on this topic from you!

christianbaier
Автор

Good video again thank you Daniel.
I've just started to lear python as a ""first"" programming language last summer, so i'm pretty much new at python and programming in general. What you described was exactly what happend to me: no mention of OOP until late in my ""training"" and than it did hit me in the face like a metheorit hit the dinosaurs.

since i'm new i probably gona say something wrong now, but the way i understand it: if i start to have many functions with many "global" in it, i think writing classes with attributes and methods makes my life much easier. And who ever can possibly read thoes code lines life easier as well.

Also GUI (ie with tkinter) for some reason makes more sense to me in OOP. But i can not explain the reason.

Gregory-F
Автор

wow I was just thinking about this topic. Thank you!

kylen
Автор

I love your balanced view. Bought your book this morning BTW. :)

amaterasu
Автор

I am going through this exact phase now, I haven't got much clue of OOP, but I am starting to learn to try and implement it, because I have to use it at work. All I would say OOP is really good for isolating functionality for specific things within your program (I.e. the objects properties and methods), but what I have begun to hate about it is the fact that it usually gets spread out into several Scripts, which can be hard to debug by others, especially when they call objects within an object call, e.g. object1 calls method of object2 > then within object2 anther call to method of object3 and going on and on.. can make things hard because most times you need to understand each of overall objects to better understand what the method is doing.

sagshah
Автор

4:07 Sometimes you have to try things and see. And then decide that it doesn’t work so well the way you first wrote it, so you have to change it. This is where you have to be ruthless about chucking away old code.

Of course, having a good version-control system like Git helps. It gives you the confidence to try things in different, possibly risky, ways, because you know you can always change your mind and go back.

lawrencedoliveiro
Автор

Hi Dan,
I have 2 years experience of programming, and I know how to implement Python and some stuff, but still I can't build apps.
I'm a self paced learner
I don't have CS BC.

Any advice?

darbazali
Автор

I am self-taught and have done some work to improve my OOP design but most resources out there teach you a Java style of design. I know in python certain design patterns aren't as useful and it's often better to use functions instead of objects as interfaces. Do you know of any resources that would be useful for someone wanting to learn pythonic OOP?

spetsnaz
Автор

can you make a tutorial on dis module, debugging and optimising functions using dis module.

TechVigyanik
Автор

Could you make a tutorial about recursive function ?

nightshadow
Автор

The opposite of “procedural” is “functional”, not “object-oriented”. Most “object-oriented” languages are in fact “procedural” as well. Python does OO and procedural, but it also has functional constructs, e.g. list comprehensions.

Python also does functions as first-class objects, which is a rarity in OO languages. But then, in Python, everything is an object. E.g.

(3).__add__(4)

returns 7.

lawrencedoliveiro
Автор

I think OOP is applicable to projects or solutions where systems need to be running in memory for long periods of time...such as the background code running for web applications. Also objects carry data and methods (business logic) inside them which makes it easy to pass them through to other functions and procedures, rather then passing through file handles, database connections..etc.

mchaves
Автор

I'm not intending to be rude, and I know people have mentioned this --but as a native English speaker, the term "procedural" is "pro-see-jur-uhl". On the whole, I wanted to say though that your English is quite good, which is saying something because our spelling/pronunciation is really fucked up. Sometimes "d" becomes a "j", and our vowels are all fucked up. Each of these depends on the dialect of English and often times even the word. But since this word is actually quite important for your field, I figured I'd leave a comment. =P Keep up the good work!

GoldPhoenix
Автор

Just use the right tool. If you need a class, use it. If it's not needed, don't.

Cukito
Автор

If your application requires multiple instances of a thing, then use classes. If not, don't.

NotMarkKnopfler
Автор

I'm sorry that I need to point this out, but the pronounciation of 'procedural' is just way off...

heyredwhale
Автор

I would love you to make an OOP series with Python. I know on your site you delve into OOP with your iterator, generator and magic class' tutorials!

As a beginning programmer OOP doesn't seem useful until you start coding large apps; 50 to 100 lines or more of code. So if you find your program has 3 or more functions then OOP will make a lot of sense. I see OOP as a quick way housing your functions in one place(a class) and creating an instance(object) to use those functions(now known as methods) at any point in your program. It cleans up your code because the syntax of the dot notation and makes debugging A HELL OF A LOT SIMPLER!!! Instead of looking/scanning 100+ lines of code you'll just have at most 30 lines of code to look thru and quickly find what's throwing an exception because you'll quickly find that a method threw the exception and you can quickly edit it and be done with it. Instead of rewriting the whole program. I find with OOP and its advantage is it makes the class and it's methods fit the program whereas your program has to fit the functions if you take the procedural/functional programming route. Protip: Learn Pytest and you will know what I'm talking about when I say making the methods fit the program. Because with Pytest you're testing to see if your methods will throw an exception and how to debug it before it throws an exception when the program runs.

Again I want to stress if you're writing a little script or a program that's less than 50 lines. Use functional programming. If you find yourself writing more than 50 lines and more than 3 functions. Do yourself a favor and write it in OOP or you're going to have a long day(s) of debugging the code.

jesavius
Автор

I DON'T HAVE A QUESTION, BUT A SUGGESTION HOW YOU COULD HELP NEW PYTHON PROGRAMERS. I KNOW FROM A PREVIOUS OCCUPATION. THERE IS NO PRERSPECTIVE. I SUGGEST TAKE 5 OR 6 PROGRAMS AND EXPLAIN THERE STRUCTURE, WHY YOU DID CERTAIN THINGS. SOME DO'S AND DON'TS. I KNOW THIS IS A LOT OF WORK.

dougstrong
join shbcf.ru