2 ms·
> "go generate" is an half assed macro feature that shouldn't even part of any modern language. Agreed. > And it has absolutely nothing to do with genericity,
by kerkeslager 6y ago
> "go generate" is an half assed macro feature that shouldn't even part of any modern language.
Agreed.
> And it has absolutely nothing to do with genericity, your argument is a fallacy.
In arguments against adding generics, it's been cited numerous times that you can achieve similar code reuse via macros. It's been a while since I looked at the awfulness of `go generate` so I'm not going to attempt to demonstrate the equivalency with that syntax, but here's how you'd achieve something similar to genericity with macros in C:
Instead of:
T swap<T>(T* left, T* right) {
T temp = left;
*left = *right;
*right = temp;
}
...
int a = 1, b = 2;
char c = 'c', d = 'd';
swap<int>(&a, &b);
swap<char>(&c, &d);
You do:
#declare_swap_function(T) T swap_ ## T(T* left, T* right) {\
T temp = left;\
*left = *right;\
*right = temp;\
}
...
declare_swap_function(int);
declare_swap_function(char);
...
int a = 1, b = 2;
char c = 'c', d = 'd';
swap_int(&a, &b);
swap_char(&c, &d);
So, macros do have something to do with genericity.
Macros are certainly a crappy way to achieve genericity, however, especially since the original reason go didn't include generics was to compile in a single pass, and adding a preprocessor adds another pass.
It's clear you were ignorant here. That's fine--I don't expect you to know everything. But I think it's reasonable to expect that if you don't know what someone is talking about, you approach the conversation with some humility and ask questions before accusing someone of a logical fallacy. Ignorance is fine, arrogance isn't.