0

Python. Functional vs Object Oriented Programming

I'm newbie and learning Python and now I reached step where starts OOP. So I want to ask question. Is that two programmings works together or separate? I mean, if you coding Functional programming do you can include and Object Oriented codes as well and opposite. I don't know is my question clear enough.

18th Jun 2020, 8:29 PM
Sigitas S
Sigitas S - avatar
11 Respuestas
+ 4
Python, different to a language like Java, does not force you to put everything in a class, which gives some flexibility. Since you have it, why not use it? I see no reason to stigmatize a hybrid form when it fits your project. EDIT: Given your learning history, I translated 'functional programming' to 'procedural programming' which means structuring your code by functions. If this was not what you meant, please clarify. Although I'll probably stick to my point that you can mix it all up in order to find the shape that expresses your idea most clearly.
18th Jun 2020, 8:41 PM
HonFu
HonFu - avatar
+ 2
HonFu so as I understood you can mix both programming in one project if it, like you said fits. But it is not necessary? You can make project just with functional programming or just with Object oriented programming. Am I right? Maybe I'll ask in different way. If you know functional programming (like example, or OOP) can you code with Python from a to z or you need and other method to know as well.
18th Jun 2020, 10:12 PM
Sigitas S
Sigitas S - avatar
+ 2
It depends on what you want to do. If you plan on becoming a professional, you can't limit yourself to a small scope of knowledge - you gotta open up and learn. If you do this without a specific aim and are in no hurry, it would probably be good to stick to procedural programming for a while, writing actual programs with it. You *can* do everything with it. But after a while you will naturally find the point where this becomes inconvenient and where OOP will start to make more sense to you.
18th Jun 2020, 10:19 PM
HonFu
HonFu - avatar
+ 2
Code Crasher thank you so much for this video. I just watched first episode. Maybe you know how to slowdown video? I'm not so good in English 😂 but lesson really very good. Would be good as well if somebody would give examples same code wrote in both methods.
19th Jun 2020, 5:25 AM
Sigitas S
Sigitas S - avatar
+ 2
I feel there's a sort of tipping point when to use what (if you have the choice in the first place). For little scripts that just do one job, sometimes you don't even need functions. You just string up a few lines of code. When it gets a bit more involved, functions start to make sense, to keep things in order. The data you work on will sit in the global scope and/or will be passed as arguments from function to function. But then, maybe when your programs pass a length of a thousand lines, it will become cumbersome: You'll have a long list of functions and data items, like variables, lists, dicts or whatever, and it will become hard to keep track of which functions work on which data. Then it will start to make sense to organize data together with only its related functions, and build a case around it so that the rest of the code can't touch it. This reduces the danger of bugs, because you can keep track more easily of where a problem occurs. And that's basically what OOP does.
19th Jun 2020, 9:03 AM
HonFu
HonFu - avatar
+ 1
Code Crasher I meant same code wrote on OOP how it looks like wrote on Functional programming? English - Good morning = Lithuania - Labas rytas 😉
19th Jun 2020, 6:56 AM
Sigitas S
Sigitas S - avatar
+ 1
Thank youHonFu
19th Jun 2020, 2:59 PM
Sigitas S
Sigitas S - avatar