What is functional programming, and how is it different to OOP?

591 viewsEngineeringOther

I’m a mid level Swift developer and I’ve only ever worked with the Object Orientated Programming paradigm.

I’ve heard about functional programming and I tried Googling what it is, but I couldn’t understand the resources that explained it. Also, reading functional code is even more confusing.

So I was hoping that someone who understood it could break it down in incredibly basic and simple terms, and the benefits/drawbacks that it has compared to OOP.

In: Engineering

8 Answers

Anonymous 0 Comments

A function in mathematics is something that takes an input and will produce a result based on that. Something like f(x, y) => x + y

Any input will always produce the same result. Most programming languages implement functions.

If you provide the input 2+3 it will always return 5.

This also has a procedural element. A list of sequential operations. Typically languages can also affect other global state. Functional programming doesn’t do this. Nor does it do loops – at least not in the way procedural languages do.

Data can be quite complex, including structures and lists.

You can do functional programming in most languages but they don’t enforce it. You’d normally use a dedicated functional language though since they have helpful features.

OOP is about everything being encapsulated in objects. The objects incorporate operations and can be modified directly.

You are viewing 1 out of 8 answers, click here to view all answers.