Andrew Gerrand | 5bc444d | 2014-12-10 11:35:11 +1100 | [diff] [blame] | 1 | # Introduction |
| 2 | |
| 3 | This wiki entry will try to document the rationales behind some important language |
| 4 | decisions besides what's included in the Go FAQ and Effective Go. |
| 5 | |
| 6 | # Language Features |
| 7 | ### Why method receiver's base type cannot be pointer or interface? |
| 8 | Reference: https://groups.google.com/forum/#!topic/golang-nuts/aqTwXHaSC_Y |
| 9 | |
| 10 | Go doesn't allow receiver's base type to be pointer to avoid possible ambiguity. |
| 11 | Suppose you have: |
| 12 | ``` |
| 13 | type T blah |
| 14 | type P *T |
| 15 | |
| 16 | func (t *T) String() string { ... } |
| 17 | func (p P) String() string { ... } |
| 18 | |
| 19 | var p P |
| 20 | ``` |
| 21 | |
| 22 | Then the meaning of the expression ` (*p).String() ` is ambiguous, because it can refer to |
| 23 | both ` (*T).String ` and ` P.String `. |
| 24 | |
| 25 | Go doesn't allow receiver's base type to be interfaces, because interfaces already have methods. (TODO) |
| 26 | |
| 27 | # Memory Model |
| 28 | |
| 29 | # Standard Library |