Skip to content
loading...
Discussion
markdown guide
 

Your hands can do things right? And your feet and your tummy do things, and so does your head. If we were talking about OOP, all of the different parts of your body and the behaviors they perform would all be apart of the object that is you. If someone needed you to do something with just your hands, they would need to create an entire you to do it.

With functional programming, your head and hands and feet and tummy are all separate functions that manipulate all of the different types. They don't have to be coupled to you anymore. If someone needed more than 2 of your hands, they would just need to invoke multiple calls to your hand functions. They wouldn't need to create two or more of you in order to use your hands. They do all the same stuff, but they can all be there own separate parts.

A less like I'm 5 explanation: functional programming languages can have strong typing systems, but those types can't expose behaviors, nor are they tied to any specific behavior or contract. There's no such thing as interfaces or class hierarchies.

Instead, when you create a type, you would write functions that can be used to manipulate that type. Those functions can be chained with other function calls to do other things.

Check out Elm if you're interested in learning functional programming. It compiles into JavaScript and can be used to create web applications. Compiler messages are super helpful, and the community is awesome.

 

Hey little Function. Bring me back one thing at a time. And when you do it, don't multi-task. I want you to be really good at one thing.

Why you ask? Because it's more predictable, especially when I have a lot kids (like you Function), and they all do something different. I need to know when I ask you for something, I'll get something back.

Don't tell anyone else what you're doing, and don't do anything extra like write this in your diary. Just do what I ask. You might not get what I ask, then try writing in your diary, but have nothing to write! So just do what I ask, and I'll have another kid write in the diary for you.

Classic DEV Post from Aug 6 '19

What to put in your portfolio as a beginner web dev

Manuel profile image