top | item 36662104

(no title)

guy4261 | 2 years ago

Package visibility is actually one of the things I dislike the most about golang :(

Coming from Python, I got used to the "explicit is better than implicit" Zen. With "import *" being discouraged, usually when you see something in your Python code, you know exactly where it came from. When I started out with golang, seeing references to things that came out of nowhere (to my eyes) annoyed the hell out of me. I still consider this a cognitive burden.

discuss

order

w7|2 years ago

I'm not sure I understand.

Generally in Go: functions, structs, and consts are namespaced in a way I think is familiar to most, by package origin.

If something is not, then it's either a function/struct in the same namespace (same file, or directory), variable in same scope, or it's a built-in.

Built-ins like `append`, are not much different than say `map`, `filter`, `max`, etc in Python.

Anything sourced from a subdirectory, parent directory, or sibling directory needs to be explicitly imported via the module path.

knome|2 years ago

I discovered how it works by fighting with the compiler far longer than I will admit trying to force it to import the other files in the directory :)

lanstin|2 years ago

Yeah that is counter intuitive till you forget not knowing it.