Learn Pure Functions In 10 Minutes

preview_player
Показать описание
Functional programming is constantly on the rise, and with functional programming comes pure functions. Pure functions are the base of what functional programming is built upon, but they are useful even outside of functional programming. The idea of a pure function is a function that when given the same inputs always returns the same output. This function also must have absolutely no side effects and rely on no other state besides the input variables. It essentially works exactly the same as a math function. 2 + 2 always equals 4 no matter how many times you execute the function. 2 + 2 also never effects anything else outside it. For example 2 + 2 never causes 3 to change to 7 or some other side effect.

In this video I will be covering pure functions in depth by example. We will take an impure function and incrementally modify it so it is a pure function by the end of the video. I will also discuss the advantages and disadvantages of pure functions.

📚 Materials/References:

🧠 Concepts Covered:

- What a pure function is
- How to avoid side effects
- Why pure functions are important
- The limitations of pure functions
- Immutability in pure functions

🌎 Find Me Here:

#PureFunction #WDS #FunctionalProgramming
Рекомендации по теме
Комментарии
Автор

Just wanted to say that this is my favorite channel for learning web dev. Your lessons are consistently to the point and concise, and it's done in a way anyone learning JS may understand. Keep up the great work!

namelikeemid
Автор

I call your channel and I get the same results every time. Lessons that really help me that are clearly explained, plainly spoken with no confusing arrogance . You sir are a living pure function!

palent
Автор

Pure functions 👏👏👏
- Great for unit testing
- Does not change the original value
- Does not affect anything outside (e.g. database, files)
- Minus the side effects

hyfydistro
Автор

This dude is super awesome amazing! Something that I love about his tutorials is that he teaches in a very solid way. I mean, if there is something important, some lesson which is preliminary to understand current lesson, Kyle already has made it, he points it us so in case we need it we can learn it conveniently. Just amazing bro, just amazing. Very well structured and great approach.

RameenFallschirmjager
Автор

Thank you, Kyle! Your videos helped me alot and I'm grateful to you for sharing your knowledge and expertise with us. Not many people are humble and generous when it comes to sharing their knowledge as they think it would affect their positions. Because of you I'm now interviewing more and opening more doors than I did before I subscribed to your channel. God bless your heart man. Keep up the good work and thanks again!
Mohammed

mohammedalmukhtar
Автор

I've seen this video twice now. first before I got into a job, and now when I have a job

the first time, I didn't really think it would matter a lot, because I was the only one working on my code

now, I've been told multiple times at my job that testing is nessessary when changing stuff because it can mess up something else

my next hobby projects will absolutely be based on pure functions, for sure!

lassebrustad
Автор

Really love how concisely and clearly you explain things. :)

One question: Isn't this just a classification of a function, rather than a method of coding? Pure functions seem like they'd be really good for performing single tasks repeatedly, but a lot of times (as you say), you *need* the functions to do something more.

BrianHartman
Автор

simple and to the point, thank you :)

a_maxed_out_handle_of__chars
Автор

This is the best web dev channel. The explanations and very solid and simple. Thank you so much

abhayganti
Автор

I would add that 'pure function' allows to use streams and parallel processing.
This is a secured way to parallel processing, and also to compose functions, it is backed by the mathematic concept called "monads".
We could do parallel processing with imperative style but it is so risky that it was rarely done.
The moderns web sites (helped by javascript language progress) rely heavily on parallel processing secured by a functional style using pure function. A flow in input must always creates a new flow on output.
I think you could explain this more clearly than me ....

chrislr
Автор

Pure functions:
1. function where the return value is only determined by its arguments without any side effects.
2. When these functions are called, again and again, the output remains the same, it does not get changed.
3. It is helpful in unit testing and not good for getting data from the database.

spiritualcontent
Автор

Brilliantly explained, thank you so much for making this video!

thatoneuser
Автор

Great video as always. Would love to see you refactor some "real" code w/ common tasks to make it more functional. Thanks for not making this stuff overly complicated!

RogerThat
Автор

Didn't know it was called pure functions but I learned this technique years ago from I think Code Complete. Much easier to test when each function does one thing and one thing well and you use a controller to receive and send input. Also suggest programming to interfaces and passing them instead of implementations to make it easier to mock.

geneanthony
Автор

Clear and right to the point. That's why I always come back!

raisedbyreels
Автор

Great explanation. Another thing you could have added is that pure functions are easy to move. If you want to move a pure function to a shared service, no big deal.
Another important thing is that purity is not an all or nothing notion. For example you can have a function that writes in a database AND relies on a global variable ! Better pass the variable as an argument. That will make the function purer. Therefore easier to test and to move if needed.

maldoror
Автор

Great videos, very concisely explained. I just watched your memoization video and it was so easy to understand. Keep up the great work.

coplepk
Автор

your vids are amazing and the first place I come for support. thank you!

NathanMcclure
Автор

One thing to add now that serverless and edge are bigger with things like next js is that pure functions can help save a lot of cloud processing money in web world.
You can run the functions for a lot cheaper a lot more places closer to users if they’re not having to communicate with DB or do fancy things. You’re getting a virtual machine to run thousands of mini virtual boxes to thousandths the cost at times.
I can recall my College professor’s heavy accent yelling ULTIMATE RE-USEABILITY, EXTENDABILITY, TESTABILITY.

ryanquinn
Автор

I have learned a lot from you to the extent that I feel I owe you

ahmadelbullock