Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Instead of coding all the steps to create the sum, we told reduce to use the add function.
If we were using something like Ramda, we could even do this to create a new function:
import{reduce}from'ramda'constadd=(x,y)=>x+y// Here we are composing a new function `sum` from `reduce` and `add`.constsum=reduce(add)(0)constvalues=[1,2,3]sum(values)//=> 6
To be able to compose functions like this, you need to also create pure functions, curried functions and also have immutable data. Which is why functional programming can be tricky to learn. It's not difficult to learn, it just takes time to fully understand the why.
Pellentesque nec neque ex. Aliquam at quam vitae lacus convallis pulvinar. Mauris vitae ullamcorper lacus. Cras nisi dui, faucibus non dolor quis, volutpat euismod massa. Donec et pulvinar erat.
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
There are many good things. I tried to boil it down to one for simplicity.
For me, it's also about not having the mistakes of OOP: Inheritance, State, Mutations, Combining data + functions into one Object, Access Modifiers (public, private, internal, protected), property accessors get/set. etc.
Pellentesque nec neque ex. Aliquam at quam vitae lacus convallis pulvinar. Mauris vitae ullamcorper lacus. Cras nisi dui, faucibus non dolor quis, volutpat euismod massa. Donec et pulvinar erat.
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Pellentesque nec neque ex. Aliquam at quam vitae lacus convallis pulvinar. Mauris vitae ullamcorper lacus. Cras nisi dui, faucibus non dolor quis, volutpat euismod massa. Donec et pulvinar erat.
You know, everybody is like rxjs and mocha and Jasmine and mojiscript and asynchronous curry ketchup frameworks but to me they are just collections of 'helpers' from other people that I like to write myself most of the time. Functional programming to me is closely related to context free development and that means elimiting dependencies. If functional programming really insists on being a thing then don't clean up only the language but also the rest.
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Explain to me functional programming like I'm 5, you said dumb questions right? Seriously though I hear this term but I'm always lazy to search it up.
To me, functional programming is all about composing (or combining) functions to create new functions.
A good example of this would be
map
and it's siblingsfilter
andreduce
.Imperative
Functional
Instead of coding all the steps to create the sum, we told reduce to use the add function.
If we were using something like Ramda, we could even do this to create a new function:
To be able to compose functions like this, you need to also create pure functions, curried functions and also have immutable data. Which is why functional programming can be tricky to learn. It's not difficult to learn, it just takes time to fully understand the why.
I hope this was helpful!
Cheers!
To me it is not just composition but also isolation.
There are many good things. I tried to boil it down to one for simplicity.
For me, it's also about not having the mistakes of OOP: Inheritance, State, Mutations, Combining data + functions into one Object, Access Modifiers (public, private, internal, protected), property accessors get/set. etc.
Yeah but still we need streams and emitters.
For sure. I use event emitters also. I usually tie those in together with RXJS.
You know, everybody is like rxjs and mocha and Jasmine and mojiscript and asynchronous curry ketchup frameworks but to me they are just collections of 'helpers' from other people that I like to write myself most of the time. Functional programming to me is closely related to context free development and that means elimiting dependencies. If functional programming really insists on being a thing then don't clean up only the language but also the rest.
Now that's something a 5 years old can understand lol. Thanks!
Happy that you were satisfied with the answer. Hopefully others can also chime in with what functional programming means to them.
And don't be shy about asking more questions ;)