DEV Community

loading...

Discussion on: State (in JavaScript) Explained by Cooking A Simple Meal

Collapse
rafaelcastrocouto profile image
@racascou

Hi Kevin, really nice article. I totally agree that there's an overall tendency of creating prototypes/classes where there's no need for them (at all). This seems to be the side product of the fact that most code tutorials focus on how to do exactly that. But there's a reason for that, most complex systems will require instances and other benefits provided by those prototypes and that's why they are present in nearly all programs. Seems like the problem lies on figuring out where those prototypes should be used. If you consider scaling up those two versions of code, think about cooking new meals, and using other tools to heat it up, and so on. You will soon realize that the best approach would be to have at least one class (maybe Food) where you would store the temperature parameter and many others. But again you are right in pointing out that most problems can be solved with pure functions and they should.

Collapse
kbk0125 profile image
Kevin Kononenko Author

Thanks Rafael! Yeah, the way that I think about this is that the analogy focused article should only cover the very basics of the system. As you get more advanced and doing the real thinking that it will take to structure your code, it should be mainly code-based. So, I try to leave the later, more technical stuff up to people's imagination since it will inevitably become a more technical article in order to cover those considerations.