Hacker News new | ask | show | jobs
by gorgoiler 1469 days ago
I’d like to get into go but in the past I’ve always been burned by not being able to quickly refactor my code.

If I want to change the contract of get_kittens so that it returns a set instead of a list, I found it quite tiresome to then go to all the call sites of get_kittens and change their types to match.

What was I doing wrong?* Perhaps there’s a cleverer tool out there that can infer and implement these type changes for me, automatically?

* using vim? [joke]

3 comments

Although go has many deficiencies, this is not one of them. When you use "var" or "val", it works like "auto" does in C++.
I also use Vim.

1. Use `:=` whenever you can, so types are inferred by the assignments/allocations 2. Alternatively query all references from `gopls` and put the results into quick fix list, then `:cdo`

This is true for all typed languages though..
No, type inference avoids this issue.
Which Go has. https://go.dev/ref/spec#Type_inference

(Not to a level something like Typescript has it, but I'll argue that's a win. Typescript inferred typing can be hard to follow.)