Go R1 Day 84
progress🔗
Ultimate Syntax (Ardan Labs - Bill Kennedy) and went back through various topics such as:
- Pointers: One thing mentioned that resonated with me was the confusion regarding pointers in parameter declarations.
I also find the usage strange that the deference operator is used to denote a pointer value being dereferences in the parameter.
I'd expect a pointer value to pass clearly with
func (mypointer &int)
and notfunc (mypointer int)
with a pointer call. - Literal Structs: Great points on avoiding "type exhaustion" by using literal structs whenever the struct is not reused in multiple locations.
- Constants: Knowing that there is a parallel typing system for constants with "kind" vs "type" being significant helped me wrap my head around why constants often don't have explicit type definitions in their declaration.
Iota🔗
This is one of the most confusing types I've used.
- Iota only works in a block declaration.
Also showed using << iota
to do bit shifting.
This is common in log packages (I'll have to look in the future, as bit shifting is something I've never really done).
Become of kind system, you can't really make enumerators with constants.
Best Practices🔗
Don't use aliases for types like type handle int
in an effort.
While it seems promising, it doesn't offer the protection thought, because of "kind" protection.
This is because "kind promotion", it destroys the ability to truly have enumerations in Go by aliasing types.
I've seen stringer
used in some articles as well, but not certain yet if it's considered idiomatic to approach enum like generation this way.