JavaScript Functional Programming Tutorial

preview_player
Показать описание
Functional Programming in JavaScript is more like a style, rather than a paradigm. This JavaScript Functional Programming Tutorial was made to demonstrate it's simply writing your code in a chained, clean and efficient way. Doing this can reduce your 50-100 lines of code to just a few without sacrificing readability and logical integrity.

Relevant keywords, it seems:
fp vs oop, function purity
functional programming javascript
functional programming vs object oriented
functional patterns
functional programming patterns
Рекомендации по теме
Комментарии
Автор

Is important to highlight that when u write something like this "add = item =>{ item+1 };" is not the same as if u write it like this "add = item => item+1;" because in the first case u are not actually returning anything but in the second way u are returning the new item, so the second way is cleaner but you also implicitly return the new value

desoldenau
Автор

The downside is that you can also take this sort of programming too far, producing an endless chain of maps, filters, reducers, and whatever else. Your example is nice and clean because your data is extremely simplify and you're only performing a couple of operations.


I've seen some horrific balls of spaghetti mess written this way.
Imo programmers are too obsessed with reducing the lines of code. There is much to be said about breaking the code down to a few extra lines for readability. Less code is not always better.

Datamike
Автор

An introduction to writing
elegant, readable and maintainable code.
Great lesson, as usual. Thank you for your effort.

sergiomartin
Автор

This is not an introduction to functionnal programming but just an introduction to map/reduce. Let's stop defining FP as map/reduce/filter, these are just a small part of what FP is.

Also, an arrow function is not like a function, it is mostly like a function. We need to stop as a community teaching people that arrow functions are the same as regular functions. They have an objective and that's what we need to teach. Knowing how `this` work is important and teaching that when explaining arrow function is important.

NaouakNawak
Автор

You have shown the very basics of JavaScript functional programming in so simple a way that it clears so many confusions moving around the subject. For any code its conciseness and clarity are of prime important. Thank you for sharing. 😃👍

nizamuddinshaikh
Автор

I personally believe that ‘const’ should always be used now to remplace ‘var’ in any case with no exception and in the rare case when you will need to reassign a primitive value which is not passed by reference then in that context it would be the only exception to use ‘let’ instead

Luxcium
Автор

THANK YOU for posting this. Awesome stuff. Stay safe & healthy.

philmay
Автор

Your introduction was very perfect....as I was also looking for technical concepts of functional programming than its definition :)
Thanks for your clean and understandable video.

imorkutuser
Автор

If your array L = [2, 3, 4] and you calculating var val by applying to L function add_one to each item and than reducing the result by summarizing all items in it, than your val should equal 12. Not 9! Did you start with L=[1, 2, 3]? or L=[2, 3, 4]?

katyasorok
Автор

That's a great way to take something so simple as For loop and turn it into unreadable and incomprehensible bunch of functions :D Well now i know that i don't like functional programming. But i learned something new and am enjoying your tutorials. Thanks! Keep it up.

klemkas
Автор

I simply do not understand how immutability and functional thinking allows us to accomplish much. I'm trying to learn it and it escapes me. For example, how do you maintain a simple thing like a counter when you can't increment a counter variable? How do you design a language that doesn't allow state changes and then expect to use it to work in the real world where state and side effects are simply how things work? I'm really struggling with this.

johnneiberger
Автор

FP is not about side effects, immutability and pure functions. It is about composition and combination.

neto
Автор

in the .map.reduce example, yeah... it's "cleaner" in the looks, but you are traversing the entire array twice. I know the example serves as an illustration, but it is fundamentally flawed.
I the example it would be much more efficient, although less "clean" to have a single for loop in which you add 1 and then sum in the accumulator.

PabloGnesutta
Автор

It involves much more thinking to achieve functional programming from a language not designed for it. Then the consequences could be higher costs debugging the code. Not for me. I prefer readable code. For a guy like you who eats and breathes JS I guess this is is for you.

TorBruheim
Автор

Thank you very much! - It is very sad how Ruby is so overlooked Yukihiro Matsumoto already added all these feature in the language that JS and Java and others adopted recently.

zealousprogrammer
Автор

8:50 please remove the curly brackets { } otherwise, it won't return it, it just won't work ;)

Programming-Fun-With-Hima
Автор

@4:49 am i correct in saying that when we are not changing the state unpredictably, by ensuring we have pure functions that do not change this state unpredictably, we are achieving the desired result of functional programming?

jamesherrero
Автор

You've got a new subscriber <3

Programming-Fun-With-Hima
Автор

it helped a lot. just a request, could you start using black background in your editor or where ever you teach?

hesamdanaey
Автор

what is MAP ??? every time i want to learn somthing, unknown things come

microsoftsimba