Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify Go code #17

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Simplify Go code #17

wants to merge 2 commits into from

Conversation

coder543
Copy link

@coder543 coder543 commented Oct 25, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant