4 ms·
> Unpopular opinion: I hate meta programming. As papaf asked, is it metaprogramming you hate, or bad metaprogramming? Metaprogramming is just another tool in
by rauhl 8y ago
> Unpopular opinion: I hate meta programming.
As papaf asked, is it metaprogramming you hate, or bad metaprogramming? Metaprogramming is just another tool in the toolbox, and hating syntactic abstraction (macros) makes as much sense to me as hating procedural abstraction (functions). Yes, it’s easy to write bad syntactic abstractions, but it’s also very easy to write hilariously bad procedural abstractions, too.
cbzbc states that metaprogramming is often harder to get write than functions. I’m not certain that’s true; might it just not be the case that most programmers just don’t get very much experience with metaprogramming, since they’re typically using languages with very underdeveloped facilities for it?
> A long time ago, I was freelancing Rails. I can't accurately describe the deflating feeling of tracing your problem back to some class that one person (a ruby guru warrior, no doubt) wrote, with a few dozen dynamic deeds or to_methods. It's the most demotivating thing I've come across in real life code.
My own experience is that for some reason Ruby tends to attract programmers who enjoy doing things because they can be done, not because they should be. It’s so bad that my general rule is not to use systems programmed in Ruby, because I’ve been burnt so many times before. That’s not entirely fair (obviously there are some great systems written in Ruby — e.g. I believe that both GitHub & GitLab are), but it reflects my experience.
- rtpg 8y ago> hating syntactic abstraction (macros) makes as much sense to me as hating procedural abstraction (functions). This is a bit pedantic, but... Many people's experiences with macros are through C. C macros are not syntactic abstraction, but some sort of lexical expansion that introduced syntactic confusion. I get this is not the case in many languages now but for most popular languages macros are "throw appended strings into eval/C preprocessors"
- jimbokun 8y agoI think the challenge with "metaprogramming" is coming up with a good debugging model. The strength of functional programming is the ease of reasoning about the computation model. "This function is called with these arguments, and I can see it will then always return this exact result." Imperative programming makes predicting what a program will do much, much more difficult. Then metaprogramming can take understanding a program's behavior up another level of difficulty. I experience this programming in Java with Annotation Oriented Programming (the preferred model of Spring). I find it even more difficult than Ruby "define method" or Lisp macros to deduce the behavior of a program. It's really hard to go from seeing an annotation in the program, to figuring out how exactly the annotation will change the program's behavior. In practice, it's pretty much just "Stack Overflow and Pray".
- jrq 8y agoI agree! I suppose that the wish for meta programming, when I rely on it, is to express a pattern that either can't express with types or with functions. In ruby, I know well enough to avoid define method and mm, and do things the hard way, but in other languages the temptations are still there. My first foray into programming was Scheme, through SICP. So, I was exposed to a lot of meta programming early on, but I wasn't adept and certainly the majority of that book is beyond what I can comprehend. I love functional programming, and especially a language with a mature type system, because it holds my expressions to a standard that alleviates that urge to use a dynamic def, and a wackedy-hackedy solution. I hate that there are difficult concepts that can't be easily expressed without syntax transforms, and that so many of these macro systems make code harder to read. Honestly, even scheme's macros are hard to read at first. You're thinking about three entire levels of computation, the forms, where its evaluating, and where the continuation is, it's completely unmanageable, or so I think. Other people seem to have an easier time of it. Am I a bad programmer for not being able to metaprogram well? Certainly some of these systems are bad, and certainly some of the blame for my dislike of them is within myself also. But I don't think I'm a bad programmer for wanting to express my code in the most compositional, logical, functional, as close to unambiguous manner as possible, and to that end I avoid macros when I can. I also dread seeing them, especially someone else's code that I'm gonna have to debug or refactor, and then I was the last person to touch it so when it nearly inevitably blows up, it's magically my fault. I don't think the merit of syntax transforms (macros) and value transforms(functions) are equal. In a situation where the macro is typesafe and obeys black box principle, they're essentially equivalent in the manner of their side effects, but in the vast majjority of real world situations, that's not the case. Rails builds take forever, and early on, it was widely accepted that a rails app would crash dozens of times a day, and cutting edge rails convention was forged by people figuring out how to start it back up quickly. I can imagine there are some CL defmacro horror stories floating around out there. Hell, LtU was figuring out how to cheat syntax-rules years ago. I hope this brings you some sort of insight. Sorry for this mess of paragraphs. I'm generally not allowed off of my spreadsheets, so I'm just a dorky hermit, and I can't express my thoughts into the right words, really. Anyways, yes. I guess I hate meta programming and prefer higher order FP.