Object oriented or functional programing? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Object oriented or functional programing?

When I start developing software, then I have a dilemma - which of the programming concepts i will use. Please explain to me - In which case should I use the concept of OOP and when to use the concept of functional programming? Thank you)

4th Mar 2018, 11:27 AM
Timofey Samodurov
4 Answers
+ 1
Functional/imperative and OOP/procedural are orthogonal paradigms. So you can do both OOP and functional programming. That what I usually try to do in Python, instinctively. The goal of functional programming is the minimise the state you at working with, while the goal of OOP is to bundle the state. You can do both, but it is sometimes quite hard EDIT: @Marco: if done correctly, both functional and object oriented programming permit a huge deal of code reusability. Thus, if your code is very short, you can do it both procedurally and imperatively, otherwise, if your language supports both functional and object oriented programming styles, try doing both as much as possible (I'd say start with functional)
4th Mar 2018, 4:21 PM
Amaras A
Amaras A - avatar
+ 7
oop👍
4th Mar 2018, 11:28 AM
Shruti Singh
Shruti Singh - avatar
+ 2
Oop is usually the best because it makes code a lot more reusable for example You have a game and a game is made out of different modules: You have the resources manager(loads data) You have the game engine you can have a game state machine now if you want to make more than one game you want to maybe use the same resource manager, but if you made all in functions you will have to rewrite some code, by using Oop you can divide every module and use the same module for different projects. TL;DR:For really small programs Oop is not necessary but if you are making a big one that needs to be organized Oop is the way to go
4th Mar 2018, 1:43 PM
Marco
Marco - avatar
0
oop
4th Mar 2018, 12:56 PM
Onasanya Tunde
Onasanya Tunde - avatar