5 ms·
> Can you tell how many extra memory allocations we are making to solve this problem? What suggests that the "best practice" is sliced down the efficiency lane
by randomdata 2y ago
> Can you tell how many extra memory allocations we are making to solve this problem?
What suggests that the "best practice" is sliced down the efficiency lane? The intent could be to "best" demonstrate how to structure a collection of algorithms and data structures into packages, for example.
- vrnvu 2y agoJust an example. Why should complexity and over-engineering be considered best practices for a beginner? In the example I've given, it turns out that a for loop and an if conditional are the simplest and most efficient solutions. Additionally, from a beginner's point of view, it's important to learn algorithms that are language-agnostic. In this case, Go handles the allocations, copies, and memory management for you. However, this code would be much harder to implement in C. In any language, the algorithm I've provided would still be the best solution. As others have commented, the terms "best practices" and "beginner" are sometimes used as clickbait to attract interactions and GitHub stars.
- randomdata 2y ago> Why should complexity and over-engineering be considered best practices for a beginner? I'm still not clear on where the idea that this is a "best practice" is coming from. Is there some context I am missing? Aside from the editorialized title, all I can find is an assertion of "following best practices", which does not even imply that it is trying to establish best practices (of any sort, let alone around efficiency or complexity), merely that the author tried to follow some best practices established elsewhere. It is understood that to follow opens the possibility of veering off course, so unless the beginner is also a beginner with spoken language, it would not be taken to mean that this demonstrates best practices.