3 ms·
I have a distinct memory from the first Go contributor summit where I brought this up (I have no idea what we were discussing or what it was in response to) and
by SamWhited 2y ago
I have a distinct memory from the first Go contributor summit where I brought this up (I have no idea what we were discussing or what it was in response to) and the attitude of every other developer at the table was "yah, but we special cased this after it caused problems with crypto/rand, math/rand so goimports is fixed now and it's fine".
And then it happened again with every IDE. And with other packages that haven't been special cased yet. And with… I dunno, I never could convince anyone but it just seems like a terrible idea to me. Please just write out your imports, it doesn't take that long. :(
- arp242 2y ago> Please just write out your imports, it doesn't take that long. I have to disagree with that; add debug fmt.Println() → add fmt import. Okay, found it, so remove debug → remove fmt import. Okay so the problem was that we need to use filepath.EvalSymlinks() → add path/filepath import. Wait, that still didn't work; let's add back that debug Println()... etc. etc. Other people may have other dev cycles, but I hugely miss it when it's not available (I sometimes do some work on VMs for cross-platform work where this is the case). Same with gofmt really; these days much of the time I just write: if foo==bar{fun()}else{panic("oh noes")} And let gofmt sort it out. Of course I can write all the spaces and whatnot but why bother? I do agree the whole package shadow thing is a right pain.
- kbolino 2y agoThe "write out your imports" ship sailed with modules. Nobody wants to write out "code.internal.corporate.domain/bureaucratic/hierarchy/of/orgs/foo" when they're looking for "foo". Even GitHub-hosted modules have fairly long names. The tools need to get better though. I'd rather they fall back to asking me than guessing when the import is ambiguous. I also think they should only ever autoimport from the stdlib or what's directly referenced in go.mod.
- SamWhited 2y agoI mean, copy/paste is a thing, I'm not suggesting you have to always type out every single character. Just know what's being imported.
- kbolino 2y agoI don't see a functional difference between copy-paste and autoimport. They have more or less the same risks. Imports should rarely be manually managed directly in source. Doing that is the epitome of tedium and most imports are just boilerplate, so your eyes will glaze over and you'll miss the finer points unless a specific file warrants deeper scrutiny. That doesn't mean imports should never be reviewed, and again, I think the tools need a lot of improvement in this regard.
- tedunangst 2y agoI've never copy and pasted crypto/rand and gotten math/rand.
- kbolino 2y agoYeah that's a legit gripe but I wasn't really talking about the standard library which uses nice short import paths.