4 ms·
Go actually doesn't have any other way to clear a map!
by dilap 8y ago
Go actually doesn't have any other way to clear a map!
- tedeh 8y ago... but they made one (runtime only) for that particular use case if I understood the slides correctly, and that is the optimization.
- dilap 8y agoyep, that's right. but it's not accessible to user code, so this isn't something that could be handled by a linter (as suggested by GP). i'm actually happy with the situation. there is literally only one way to clear a map, and it is fast.
- stcredzero 8y agoGo actually doesn't have any other way to clear a map! Which, actually, is brilliant design! Now, I can find all map clearings with one operation. (I need to implement that syntactic search/rewrite tool I miss from Smalltalk.)
- apta 8y agoHow is not having map.clear() a brilliant design?
- stcredzero 8y agoIn a large project, you'll have all ways of doing any given thing represented in a code base. Reducing that number down to 1 means that searching for all occurrences is reduced to 1 operation. If you are working on a large project, searching for usages/senders/occurrences is one of the most common tasks that you do. In fact, using escape analysis of the same kind used for "Extract Method" refactorings, you can even catch clearing interspersed with other code in the for-range loop. A 50%+ reduction in programmer work is nothing to be sneezed at.