Functional Vs. Object-Oriented Programming

preview_player
Показать описание
Here is what you should know when deciding whether you should use Functional or Object-Oriented programming.

#arjancodes #softwaredesign #python
Рекомендации по теме
Комментарии
Автор

Switching from python to julia, the most important thing for me is that separating behavior from internal representation is a great idea.
Also composition is often times better than inheritance (alternate view: in oop languages inheritance is often over-used)

MCRuCr
Автор

Indeed, no need to choose between functional and classes or types...
The main difference is about the state, functional is stateless only, while OOP may allow you to introduce desired or undesired side effects.
Using final and frozen data types/classes is okay in functional programming!

DuniC
Автор

So you basically equated functional programming to not have structured data, and oop being about having it. Of course having structured data (or hmmm… structs) is good. But it is not inherent to OOP in any way.

yapet
Автор

I feel like this guy has never used a language like OCaml. We have types which are like structs in C, enums, modules, etc. The type system is more expressive than your average OO language.

benfaerber
Автор

But dataclasses are functional - you separate data from behavior

talwald
Автор

Need both to do best job. OO to build the framework but implementation is function / expression based. Pure, honest, immutable, small, dependency inversion (not injection) partial application / currying should be part of your toolbox. Doubt you have a team of devs that can maintain a code base that’s proper functional done right.

coderider
Автор

This seems like a strange take. Making a choice between functional programming and something with structured data, is like making a choice between a car and "something with a steering wheel". You can do functional programming with structured data and custom types, and it'll still be functional programming.

The main things you need to avoid if you want to do functional programming are mutable values, and global variables. You can definitely write python code or c++ code that meets those requirements, even if you're using classes to structure data. In fact, dataclasses are great for that

douglaswolfen
Автор

C-style structs (without logic) are not at all opposed to functional programming. In fact, it's a vital part in any kind of programming activity to get the data structures right.

marcotroster
Автор

I think oop is better for value objects and invariants in them. Keeping the logic in types as much as possible

Feronom
Автор

So you mean to uses functions for the behavior and classes for the data?

coxinitus
Автор

When your state is closely related with it's behaviours or actions, you need a class. When you have a class with no state, then you should just have done functions.

nsambataufeeq
Автор

C has a type called "struct" for that and does not have classes. So i don't know.

gordonfreimann
Автор

why are you using more functional intead of OOP?

MagnusAnand
Автор

that was not helpful at all, I just heard your opinion and no point to prove anything

ELHAUKEZ
Автор

I disagree. OOP is bad for data structures too.
For example: is a linked list a list? no it's not. why? because the data is different. But OOP mindset will lead you to believe these structures are related.

kablouserful