By: Jörn Engel (joern.delete@this.purestorage.com), May 23, 2022 10:41 am
Room: Moderated Discussions
anon2 (anon.delete@this.anon.com) on May 23, 2022 12:47 am wrote:
>
> Why aversion against templates? They are just the way to parametrize implementations.
> In plain C you either end up with vicious amount of copy-pasted code or messy macros that
> do exactly the same thing. On the end it’s about ergonomy and maintainability.
The honest answer is probably 80% irrational reasons and 20% rational reasons. And the aversion extends to macros in plain C, for sure.
In plain C, these macros make it incredibly hard to follow code flow. They break ctags, grep, etc. and often cost you half and hour and half your nerves to traverse. I also cannot shake the feeling that they are the right solution to the wrong problem and it would have been better to avoid the problem they solve in the first place. If you had to write 20 slightly different functions yourself, the problem would be a lot more visible and might motivate you to use a different approach.
Even if the source code looks elegant, you still have the 20 slightly different functions in the binary. And you have the potential to cascade templates and create 20*20*20 slightly different functions in the binary. At least I think this is possible, please correct me if this is wrong.
Among the irrational reasons there is probably an association between templates and poor-quality code. That's similar to the association between Perl and the horrible scripts generated during the dotcom-boom. I shouldn't blame templates or Perl, but it's hard to dissociate them.
>
> Why aversion against templates? They are just the way to parametrize implementations.
> In plain C you either end up with vicious amount of copy-pasted code or messy macros that
> do exactly the same thing. On the end it’s about ergonomy and maintainability.
The honest answer is probably 80% irrational reasons and 20% rational reasons. And the aversion extends to macros in plain C, for sure.
In plain C, these macros make it incredibly hard to follow code flow. They break ctags, grep, etc. and often cost you half and hour and half your nerves to traverse. I also cannot shake the feeling that they are the right solution to the wrong problem and it would have been better to avoid the problem they solve in the first place. If you had to write 20 slightly different functions yourself, the problem would be a lot more visible and might motivate you to use a different approach.
Even if the source code looks elegant, you still have the 20 slightly different functions in the binary. And you have the potential to cascade templates and create 20*20*20 slightly different functions in the binary. At least I think this is possible, please correct me if this is wrong.
Among the irrational reasons there is probably an association between templates and poor-quality code. That's similar to the association between Perl and the horrible scripts generated during the dotcom-boom. I shouldn't blame templates or Perl, but it's hard to dissociate them.