On Wednesday, December 23, 2020 at 10:16:00 PM UTC-8 Martin Hanson wrote:

> If all we're presented are these small theoretical examples of sorting 
> lists, etc., then clearly this is nothing but hype that needs to go 
> away. 
>
My personal example: ordered containers. My code works with physical 
simulations and it needs to be fully deterministic. This means that I can't 
use simple maps because their iteration order is random (on purpose!).

As a result, a lot of my code looked like this:

struct ElectricNode {
    ChildrenList []ResistiveNode
    ChildrenMap map[string]ResistiveNode
};

When I wanted to remove an element I have to write something like:

newList := make([]ResistiveNode, len(node.ChildrenList)-1)
for _, i := range node.ChildrenList {
   if i.Name != nameToRemove {
      newList = append(newList, i);
   }
}
node.ChildrenList = newList
delete(node.ChildrenMap, nameToRemove);

I had a couple of reflective helpers that did this work through reflection, 
but it was not clean and had broken more than once during refactorings. I 
actually gave up on Go for this project and rewrote it in Python, resulting 
in 10x (ten times) less lines of code.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/131cda29-6201-45bb-8728-4b7af4726ea6n%40googlegroups.com.

Reply via email to