4 ms·
I don't quite agree, especially because the implicit this not only saves you from explicitly typing it, but also because by having actual methods you don't need
by Galanwe 1y ago
I don't quite agree, especially because the implicit this not only saves you from explicitly typing it, but also because by having actual methods you don't need to add the struct suffix to every function.
mystruct_dosmth(s);
mystruct_dosmthelse(s);
vs
s->dosmth();
s->dosmthelse();
- 1718627440 1y agoMy problem with implicit this is more, that you can access member variables, without it being explicit, i.e. about the callee, not about the caller. For the function naming, nothing stops you from doing the same in C: static dosmth (struct * s); s->dosmth = dosmth; That doesn't stop you from mentioning s twice. While it is redundant in the common case, it isn't in every case like I wrote elsewhere. Also this is easily fixable as written several times here, by a macro, or by using the type directly.
- Galanwe 1y agoThis is not the same, you introduced dynamic function resolution (i.e.a function pointer tied to a specific instance), we are talking about static function resolution (purely based on the declared type).
- 1718627440 1y agoTrue, if you don't trust the compiler to optimize that, then you must live with the C naming.