Great vid! However, there are some things that I would like to address. I'm sorry, but what you did with that function is a no go in most languages. By making functions that are supposed to be impure pure, you are violating lots of practices. - One, allocating memory for an entirely new object, where state of one could just be altered. Be mindfull of your memory, and be mindfull of informing the user that you are copying stuff. Yea it's Javascript and that tends to happen less then one might think, but it's still something to keep in mind. This goes on to be supported by number two. - A function that describes to alter state, is allowed to alter state. Your function is called addItem. It should not just return a new object. In this case you inform the user of this function that it alters the state of a variable, your array. If I expect that to happen and it doesn't, then we've got ourselves a big problem. Always inform the programmer when you are returning a new object instead of the passed one. - And third, use constants and readonly variables that can't be altered in any way shape or form. Don't expose functions publicly, that can directly or at all alter state. For an array, you can make it immutable whenever you pass it. Great vid tho, good solid basis. Just don't forget to mention that one can write a pure function more easily if they use immutable parameters, and keep an eye on the function context.
Thank you for such a big comment. I agree with what you said but related to normal languages where you have constants, allocating memory, etc. But in js everything is mutable, arrays are mutable (unless you freeze them). You don't have readonly properties in language at all. And you don't have immutable parameters if they are arrays and objects.
Deterministic functions are functions which return the same result if they are called with the same arguments. This is exactly what this video is about.
@@MonsterlessonsAcademy thanks! I love this tuto, do you have anymore of such videos, i thought a few functions is hard to understand when it comes to ecommerce.
WATCH NEXT: Javascript Interview Questions and Answers - Dominate Your Next Interview - ua-cam.com/video/wnYKH2dO620/v-deo.htmlsi=5DfbGEfhXWiiv0a_
Great vid! However, there are some things that I would like to address. I'm sorry, but what you did with that function is a no go in most languages. By making functions that are supposed to be impure pure, you are violating lots of practices.
- One, allocating memory for an entirely new object, where state of one could just be altered. Be mindfull of your memory, and be mindfull of informing the user that you are copying stuff. Yea it's Javascript and that tends to happen less then one might think, but it's still something to keep in mind. This goes on to be supported by number two.
- A function that describes to alter state, is allowed to alter state. Your function is called addItem. It should not just return a new object. In this case you inform the user of this function that it alters the state of a variable, your array. If I expect that to happen and it doesn't, then we've got ourselves a big problem. Always inform the programmer when you are returning a new object instead of the passed one.
- And third, use constants and readonly variables that can't be altered in any way shape or form. Don't expose functions publicly, that can directly or at all alter state. For an array, you can make it immutable whenever you pass it.
Great vid tho, good solid basis. Just don't forget to mention that one can write a pure function more easily if they use immutable parameters, and keep an eye on the function context.
Thank you for such a big comment. I agree with what you said but related to normal languages where you have constants, allocating memory, etc.
But in js everything is mutable, arrays are mutable (unless you freeze them). You don't have readonly properties in language at all. And you don't have immutable parameters if they are arrays and objects.
Great tips!
Glad it was helpful!
Thank you for posting this 🤗
You're so welcome!
thanks 😊
you have a great channel
Welcome!
Спасибо, освежил в памяти. Как насчет понятия детерминированности функции? Тоже ведь из этой оперы.
Deterministic functions are functions which return the same result if they are called with the same arguments. This is exactly what this video is about.
hi there, in your last example, cart.items is not an argument, even though cart is an argument, that is why it is not pure?
It is not pure because you pass arrays and objects by reference and not by values so updating them leads to updates elsewhere.
@@MonsterlessonsAcademy thanks! I love this tuto, do you have anymore of such videos, i thought a few functions is hard to understand when it comes to ecommerce.
Super, I would like to know what are the benefits can I get if I joined (membership)
Hi there are no benefits on youtube membership now except of the icons near your nickname. It is just if you like the content and want to support me.
@@MonsterlessonsAcademy yes