4 ms·
There's sort of a survivorship bias in play here, where you only noticed the brittle codegen being brittle.
by fizx 11y ago
There's sort of a survivorship bias in play here, where you only noticed the brittle codegen being brittle.
- fapjacks 11y agoAt the risk of sounding obtuse, then, where is the robust codegen code?
- bartonfink 11y agoCompilers, for start.
- fapjacks 11y agoHah! Touche!
- nostrademons 11y agoOn a continuum from "so robust you don't even consider it codegen" to "well, some people use it": microcode, compilers, virtualization, visual interface builders like XCode and Android Studio, dynamic HTML pages, ORMs, protobufs & other schema definition languages, autoconf & friends, compile-to-C languages like early versions of C++ and Go, ES6 transpilers like Traceur and Babel, compile-to-JS languages like CoffeeScript. Probably others I've forgotten or don't know about. When it works, you forget that the only thing that computers understand is their native instruction set, and everything on top of that is built on some form of codegen. When it doesn't, you curse out the programmer who left you a pile of buggy scripts to maintain.
- kazinator 11y agoNice easter egg: "autoconf & friends" buried in the middle of a paragraph that appears to be about robust code generation.
- nostrademons 11y ago"Well, some people use it." Particularly toward the end of the list, there'll be more and more examples where people hate the code generation aspect (for example, I've personally had bad experiences with any JS technology that requires a build step). That doesn't change the fact that they're widely used; autoconf, for example, was mandated for all Google-owned open-source C/C++ libraries, because despite its kludginess, it will build on virtually everything.
- deleted 11y ago[deleted]
- teacup50 11y agoIn addition to what peer comments already listed: - Macros and compiler plugins that operate over the language AST. - Tools that generate native bytecode. - Parser generators that don't paste arbitrary user code into the generated code. The consistent theme is: tools that understand language semantics to whatever degree is necessary to perform reliable transformations.
- _asummers 11y agoJava annotations have been used pretty successfully for several versions. Not all of them are code generating, but many (from e.g. Spring, or something smaller like Retrofit) generate tons of code for you.
- Ologn 11y agoAlso, codegen exists on a solution continuum. Codegen is a superior solution to manually pumping out lots of boilerplate code with slight variations. A solution that does not need lots of boilerplate code would be even better, but codegen is still better than the makeshift code that it originally replaced.
- ArkyBeagle 11y agoThere's an intermediate approach - use a generator to spew out tables of data that an engine-type thing uses to adapt to boilerplate style variations. This is totally a 'C' hacker's approach but it's not bad for some things - especially serialization and the like. But it will need some generic reference mechanism - as void * is used in 'C' - to work.