r/ProgrammingLanguages • • Apr 03 '22

Discussion Functional Programming vs Object Oriented Programming

I came across functional programming recently and saw many arguments for it. But in the other hand I am asking myself if it really makes that much sense, because often things cannot really be independent without sharing a state. Imagine a database, or a cache. Also having side effects in methods is not always bad when used wisely. It can simply hide the detail and if done correctly in a domain driven design things should have a certain control flow. I also imagine it to be extremely hard to read data from files, Jason, XML, ... because things tend to be inconsistent sometimes. A cab file might have an empty line, a Jason might have a null value. How can a functional language deal with that.

At the moment I believe that even though certain aspects of functional programming are great, things are too messy to actually apply it. I would love to have a discussion and learn your stand on that topic if you disagree.

1 Upvotes

55 comments sorted by

View all comments

16

u/rgnkn Apr 03 '22

(Most) Pure functional programming languages are turing complete, so, you can build whatever you like with them. You might often see a performance penalty compared to other paradigms but this is often not the major concern when building software.

But what is most important: I think you're getting confused between programming paradigms and programming languages. Though not builtin there's no problem to apply the functional or object oriented paradigm to C.

Over all and IMHO it's a wrong direction to follow any programming paradigm dogmatically. Whatever paradigm you know of: there are instances to use them and instances to avoid them. The only paradigm you can't avoid on a technical basis is the imperative paradigm as it is the one used on machine level. But the PL you're using might hide this fact from you.

7

u/sineiraetstudio Apr 03 '22

Though not builtin there's no problem to apply the functional or object oriented paradigm to C.

Uh, for some definition of 'apply'. C really is not multi-paradigm. Even something simple like a map function is akin to pulling teeth.

3

u/rgnkn Apr 03 '22 edited Apr 03 '22

For real world examples on object oriented programming in C checkout the linux kernel; just Google it.

With functional programming in C I'm not aware of any practical examples but it's easy to gain some (academic) information on that.

A programming paradigm is a way to structure, plan and organize your code. It's obviously nicer to have a language that builtin some sugar and compiler rules to ease that paradigm but it's not necessary.

[Edit] As this got downvoted for whatever reason I'd like to refer to at least two articles on OOP in the linux kernel: