Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

In this example, *cptr is a color by contract. A Color is a type alias of a string. *cptr is a string. Interfaces match.


Technically not a type alias, just a normal type declaration. But yes, this is my point: you can't assume that an enum type will always be one of a fixed set of values that you've defined. You always have to do at least a little bit of runtime validation of the parameter. It's unavoidable.


alias and type redefinitions are conceptually the same. int and int_t are conceptually the same. I’m going to assume it’s my type, as defined in the signature of my method you’re calling. If you don’t adhere to the contract then the onus is on you. I’ll check existence, I’ll check conformity, but I won’t check that your string = my string.


> alias and type redefinitions are conceptually the same.

In Go, they are not. Aliases establish precise equivalence between types, type redefinitions establish new types altogether.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: