After a long time learning and working with object-oriented programming, I took a step back to think about system complexity.
“Complexity is an...
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
This is one of the better posts I've seen on here so far. Thank you so much for this! Lots of useful resources and very well written and explained examples.
Thank you! I'm glad you liked!
I hope I could help you in any way!
Hi TK,
I really like the fp style in JS, but how can I (or you) justify it, if, when I refer to your last shoppingCart example...
imperativeGetTotalAmount, also gives me the correct value and will be much quicker to execute, particularly when the "shoppingCart" array length is length 10,000 or greater? Additionally, the code length of imperativeGetTotalAmount is shorter.
Once again, I must reiterate, I am a huge fp fan and I am playing devil's advocate here in posing this question, but I feel that one must be able to defend a particular style,(oop, imperative, fp), if it is to be accepted by the community in general.
Thanks for your post and it's huge list of useful resources.
This solution returns an amazingly fast execution time for 100,000 generated items of approx. 2.5ms
or, alternatively ...
visit runkit link
I thought
caculateArea
is a pure function.Am I understand wrongly?It will return the same value if you call it with same variable, because
PI
is a constant.If you use replace
PI
with3.14159
orMath.PI
, it should still be a pure function.Yes, Maple, maybe my example was a bit confusing. My attempt was to show that the "constant"
PI
(an external variable) could change (in my example, I changed it to42
).If the
PI
value changes, ourcalculateArea
function will change the output for the same input (radius
). The whole idea is to show that the function to be pure, it needs to not change the output, for the same input.I will try give another example with a variable instead of a constant.
For the input
100
, we will have120
as a result. But if our tax changes, our output will change, for the same input (100
).To make our function pure, we can pass the
tax
variable to the function as a parameterFor the inputs 100 and 20, it will always be 120
For the inputs 100 and 100, it will always be 200
With this example it is a bit less confusing I think.
Thanks for the feedback!
This is gold, fantastic! I'm a new programmer trying to wrap my head around functional programming and this has been extremely helpful!
This is Great post! thank you so much.
Great post ! I strongly recommend "JavaScript Allongé" to learn functional programming in JS : leanpub.com/javascriptallongesix !
Awesome resource, thanks for sharing!
Great article. Thank you
I'm a little concerned to find this is still a "new concept" in 2018. SOLID, SRP, separation of concerns, functions without side-effects, please use these.