4 ms·
Now this is an answer I can work with! I completely agree they represent a language deficiency and that should be rectified within the language, but that's not
by zasdffaa 5y ago
Now this is an answer I can work with!
I completely agree they represent a language deficiency and that should be rectified within the language, but that's not always practical than or even possible. Sometimes you have to fiddle with the language at the lexeme level [edit: at the token level, messing about with single keywords for example], which most (all?) most templates/generics won't allow you to do. Also the input to a code generator can be heck of a lot more compact and readable than the code it outputs, as that's a win.
Heavily modified example based on my actual code (no animals harmed):
makeClasses = [
("Dog", "chases", "Cat"),
("Fox", "eats", "Chicken"),
...
each line of which produces a small class.
Also completely agree they come with their own costs, but sometimes the cost is lower than the cost of not using code generation.