3 ms·
Incredibly insightful comment, even the performance concern. Apologies for doing a glorified +1 comment, but if you take the above comment plus the article's i
by ptsneves 3y ago
Incredibly insightful comment, even the performance concern.
Apologies for doing a glorified +1 comment, but if you take the above comment plus the article's in-loop mutation algorithm and try it in different languages you get insights on who you are as a coder and what are the language's strengths.
Another detail is that the programmer in the article prefers an mutation iterator format while the language forces him/her to use an array/index. This has further impact on pointer vs value accesses.
Also by mapping on players list the above post means: just discard the previous one, create a new one however you want and make the new one the new source of truth. No need for mutability considerations.
- Joker_vD 3y ago> just discard the previous one, create a new one however you want I want to create it by re-using the memory of the previous one that I've just discarded, please (well, the one that will end up discarded, actually: it has to live until the map ends executing, hasn't it). Unfortunately, most of the languages' implementations/runtimes don't employ the Perceus algorithm.
- fifilura 3y agoCan you describe why you need it? Is it because of real performance concerns or just because it feels better knowing that you don't waste memory space and CPU cycles? If you really need it, you can always fall back to using mutables for this special list, and use immutables for the rest? This is probably the reason why languages don't implement the Perceus algorithm. If you really needed it you might as well do it by hand.
- duped 3y agoIn a managed language that's the job of the compiler. You don't need a fancy reference counter either, peephole optimizations will do.