|
|
|
|
|
by happytoexplain
999 days ago
|
|
Wow, I'm not super happy about the syntax of this language. I'm familiar with what each paragraph is describing from multiple other languages, but I can't even guess how some of the syntax here maps onto those other languages, even with the explanations. |
|
In the case of slices, it can be more complicated. These types all seem similar, but aren't the same:
The idea of the article is figuring out how to write a generic type signature that would accept any of these and return the right type.Finally, you can rename types and use them interchangeably if you don't want the "safety" of making a new type:
Now you can't write methods on Name, but you can use Name and string interchangably. (This, incidentally, is how "any" works. The package builtin contains "type any = interface{}".)If the complaint about syntax is not using <T type> to denote type parameters like Java and C++, [] simplifies the parser. You can read the original generics proposal for all the details.