akutz / go-generics-the-hard-way

A hands-on approach to getting started with Go generics.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inconsistent syntax?

bohtho opened this issue · comments

As a middle aged hobby coder just starting out with Go I appreciate the simple and straight forward syntax (I’m middle management by day .. and I get the tingling feeling there’s a joke in there somewhere😄). I also enjoy to read the (so far) consistent reasoning of the maintainers for choices made.

Do you have any idea why this (https://github.com/akutz/go-generics-the-hard-way/blob/490784b7d7c082ea84ddeadefcb02c9b03ff7a5a/03-getting-started/03-constraints.md) logical OR in the generic constraints wasn’t two pipes too? Or is the subtle difference that this generic constraint statement doesn’t actually “result” in a Boolean value or something? Something like why variable assignment and function parameters (signature) have the type the other way around.

I love stuff like this, partly, I’m sure, because if it makes logical sense it sticks too. Not really an issue with this repo of course (which was timely, complete and well thought out!).

Ya know, I wondered the same damn thing. I think it is because they refer to these a type sets, and maybe there is some logical leap to the bitmask syntax?

I'm not on you or the creators' level, I do simple adhoc stuff and have to get familiar with generics anyway, but I hope this doesn't point in the direction that generics is bolted on from community pressure because they come from other languages with generics. I mean, there's got to be a reason why Go only had the ingenious and rare Interfaces for the longest time. I respected that and the simplicity (like me!) although I understand from this repo that it doesn't completely cover the generics use case. To really get a close look at generics you can't do better than this repo though, I'll pass it along to my fellow simpletons.

I respected that and the simplicity

I mean, it's right there on the front page of this repository -- At first I thought I wanted needed generics in Go, but over time I began appreciating the simplicity of the language. In other words, I 💯 agree with you!

To really get a close look at generics you can't do better than this repo though

Wow, that is high praise. Thank you!

I'll pass it along to my fellow simpletons.

By simpletons, for simpletons! I am not an expert either, and I very much count myself as a member of the target audience at which this repository is aimed!

I didn't quite catch that on the front page! Love it! Yay! I may not necessarily be getting crazy slow after all 😄 Conscious enough to appreciate masterful pedagogy though, don't worry.

Thanks for the back and forth!

If nothing else I think it bears work to add a call out on the appropriate page that mentions the | is acting in a way some people consider to be a logical OR, aka ||.

Ah, I found it. The Wikipedia article on Union type has many examples from other languages, ex. PHP, Python, Typescript, where the single, vertical bar | is used the exact same way as it is Go generics and union type sets.

So it may resemble generics in other languages more than its own logical statements elsewhere..

I added this note 62f3e38 and closed this issue.