|
|
|
|
|
by stiff
4539 days ago
|
|
I got confused about the details, but this does hit me, the example I had in mind is this: package main
import (
"container/list"
"fmt"
)
func main() {
list := list.New()
list.PushBack(10)
list2 := list.New()
list2.PushBack(10)
fmt.Println(list)
fmt.Println(list2)
}
This does not compile, list variable shadows the list package. I would much prefer doing list::New() for package access like in C++, and being free to use obvious variable names (all the time the most obvious variable name is also the name of the package). |
|
If I decided to re-use the package name more than once it'd be `list1, list2`
I guess it's probably a programming culture thing, but I wouldn't use the word `list` to begin with. I'd use `l1`, `l2` etc. in the case where the name isn't important. It conveys no less information than `list` and short variable names AFAIK are already idiomatic so it's not even unconventional... But with all that said, `list2` wasn't a very good variable name to begin with. If you needed more than one list, then they clearly served different purposes and in that case it makes sense to name them as such: `apples`, `oranges`, `input`, `output`.