4 ms·
> without... letting people being able to abuse them. C++ cough cough. Curious what you consider "abuse", given the standard library itself uses generics in al
by mehrdadn 7y ago
> without... letting people being able to abuse them. C++ cough cough.
Curious what you consider "abuse", given the standard library itself uses generics in all sorts of ways?
- deleted 7y ago[deleted]
- baby 7y agoFor example. Typical C++ code: Thing<A<B, C<D>, E>>()
- mehrdadn 7y agoI know the syntax, but what about this is "abuse" of generics exactly?
- gpderetta 7y agoAnd? Care to elaborate?
- baby 7y agoIt makes the code unreadable to others.
- krapp 7y agoThe population of C++ developers who manage to write and ship code using templates far more complex than that would suggest otherwise.
- baby 7y agowho said that code is hard to write? I said it's hard to read. And it's probably filled with bugs.
- krapp 7y agoIf it isn't hard to write, it's easy enough to read to be useful, and understanding the domain and the problem being solved makes reading it even easier. Just about any production code is hard to read. >And it's probably filled with bugs. All nontrivial code is probably filled with bugs.
- gpderetta 7y agoThing<A<B, C<D>, E>> except for a different bracket syntax, it is the type level equivalent of: Thing(A(B, C(D)), E) There absolutely nothing unreadable with that. Mind you, I find <> brackets somewhat ugly, but that's subjective and plenty of languages have made the same choice. To be more constructive, C++ templates have two major pain points: template specialization means that the template machinery is a full term rewriting engine, so arbitrary computations can be expressed in it. The other issue is that it is hard to specify template constraints (or concepts, it type classes or traits or whatever term you prefer). A new language can eskew specialization (but note that Rust, that wants to compete in the same space as C++ has added, or is adding them), and there is no good reason not to have constraints in a new language (the design space is well explored).
- GeertJohan 7y agoI think you misplaced a ) there. Thing<A<B, C<D>, E>> Is the type level equivalent of: Thing(A(B, C(D), E)) Not: Thing(A(B, C(D)), E) I guess this is illustrative for how it is unreadable.
- josefx 7y agoSeems more like an abuse of one letter names.
- praptak 7y agoAbuse by users is subjective. Still, C++ templates make parsing undecidable. It's worse than just a Turing-complete preprocessor like, say, Lisp macros. In C++ you cannot decide the type of the next token until you evaluate the (Turing-complete) templates. This shows that the templates are at least a bit too powerful.