5 ms·
Then you wouldn't really be programming in Go. You'd be programming in whatever franenkstein's monster of a language your preprocessor is using. Preprocessors
by lliamander 4y ago
Then you wouldn't really be programming in Go. You'd be programming in whatever franenkstein's monster of a language your preprocessor is using.
Preprocessors are a code smell, and indicate that the language you are using lacks the right abstractions for productive programming.
- zasdffaa 4y ago> and indicate that the language you are using lacks the right abstractions for productive programming. Indeed go did not have generics, in fact that's explicitly stated in the post I was responding to: "at the time the lack of generics made it so that you either had to use reflection - or implement the same function N times over to support the different numeric data types" So, you unthinking prat, what do you recommend he should have done, carried on coding much near-duplicate code by hand or get the computer to do the repetitive job infinitely faster and more safely? HN is riven with plodders who just spew out memes like "Preprocessors are a code smell" or "correlation is not causation" with a relentlessness that would make Sisyphus say, 'well, you know, at least I'm not him'.
- lliamander 4y ago> So, you unthinking prat, what do you recommend he should have done, carried on coding much near-duplicate code by hand or get the computer to do the repetitive job infinitely faster and more safely? No, my recommendation would be to use a different language that doesn't need a preprocessor. Use any more insults and I'm just going to flag you.
- zasdffaa 4y agoYou don't get always to choose your language, and even then there will be stuff that needs automated cut & paste at a level that the language can't provide (even down to the lexeme level). Which is why I use generated code for my C# work. I use python rather than a preprocessor but either would do. Prepros and code generation in general are just tools, no more nor less, and not good or bad intrinsically. There is no code smell from using these. The bad smell comes only from misusing them.
- kaba0 4y agoMacros and templates are the proper solution to the problem, not unhygienic hacks.
- lliamander 4y agoI use preprocessors for Java. I'm not averse to using them when I have to work in a more verbose language. And you are right that we often don't have a choice of language to work in. But they are still a sign that the language you are using is deficient. Preprocessors may ameliorate those problems somewhat, but they come with their own costs and complexities. For anyone who is in the position of making a language choice, the fact that a given language community relies heavily on such tools should be a reason to avoid that language.
- zasdffaa 4y agoNow 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.