2 ms·
Because concepts in programming languages mean things. A discrete, named entity (a struct) is a distinct concept from a way to increase readability of a functio
by nauticacom 5y ago
Because concepts in programming languages mean things. A discrete, named entity (a struct) is a distinct concept from a way to increase readability of a function call (keyword arguments). Overloading them with the same language construct is compressing disparate concepts. It's the same thing when "Go has no set type" comes up and people say "map[T]struct{}!" You might implement a set using a map, but they're fundamentally different concepts
- preseinger 5y ago> A discrete, named entity (a struct) is a distinct concept from a way to increase readability of a function call (keyword arguments). If you take func NewServer(addr string, certKey, certCA []byte, ...) (*Server, error) and coalesce the input parameters into type ServerConfig struct { Addr string CertKey []byte CertCA []byte ... then that type is still a meaningful domain concept in your program. There is no minimum scope requirement for discrete, named entities, is there?
- throwaway894345 5y ago> Because concepts in programming languages mean things Right, but a struct means "a collection of named parameters", not "a concept in your domain model" although a struct can be used to model the latter. > A discrete, named entity (a struct) Structs don't have to be named. E.g., `var person struct { Name string; Age int }`. > It's the same thing when "Go has no set type" comes up and people say "map[T]struct{}!" You might implement a set using a map, but they're fundamentally different concepts It's not the same thing at all. In your analogy, a map is not a set but the advice says to use the map instead of the set anyway. But we're not talking about using one thing as another, we're talking about using a struct as a struct--one such (common) use for a struct is passing named values into a function.