transit-lang-cmp icon indicating copy to clipboard operation
transit-lang-cmp copied to clipboard

Simplify Go code

Open coder543 opened this issue 3 years ago • 0 comments

I don't anticipate that this will affect the performance at all, but it will remove a lot of conditionals that appear redundant.

In Go, append(x, someElement), where x is a nil slice, will create a new slice to contain someElement, it won't explode. Similarly, accessing a non-existent element of a map will return the zero value, which will be nil for a slice like []int, it won't explode either. Iterating or checking the length of a nil slice will work fine too, it'll just be the equivalent of doing the same operations to an empty slice.

I haven't actually tested this code because I didn't feel like setting up the whole environment, but I think it should work.

in my opinion, it's also more idiomatic to construct values once the fields are all known, which you were already doing sometimes, so I added a commit to do that in one other place.

coder543 avatar Oct 25 '22 00:10 coder543