Code generation is a strangely rare art, possibly because people are trying to solve the wrong problem.
I've used code generators dating back to Visual Studio plugins from the mid-1990's, and eventually started writing my own around the turn of the millennium.
While most code generators are elegant, scriptable, table-driven applications that can be tweaked and customized to handle any number of special conditions, mine are messy, hand-coded affairs that only support the coding style I care about. Yet in my experience many of these elegant systems fail to represent quite enough real-world complexity to be practical aids to development, and more often than not they generate "write only" code.
I treat code generators as junior developers, with the added advantage that they don't want paying. They write only the boilerplate serialization and UI code that would otherwise take up large amounts of relatively unrewarding effort.
They produce code that is indistinguishable in style to the code I write, because they have the corporate coding-standard built in. The ones that generate C++, it is true, use comment-markers to indicate the 'safe' areas for developers to add their own code, which is a product of how hard it is to parse C++. The ones that generate Python take advantage of the language's build-in parser to figure out how not to step on custom additions.
The thing about how messy they are, though, with dozens of special cases hand-coded, is due to a curious fact: good, clean, real-world software is full of special cases and odd exceptions. That is one reason why software development is hard: there are a lot of rules to "good style", to make code readable. This is particuarly true for UI-generating code, where a whole range of different widgets require special conditions to make them behave sensibly and look good, which is surely the goal of all reasonable coding standards.
I'll be writing more here about generating code as time permits. My thinking on the topic has evolved a lot over the past decade, going from grandiose schemes that will change how software development is done, to more modest, practical and effective systems that take a great deal of the day-to-day burden of development off developers, letting them concentrate on design and the custom implementations that will make the application remarkable.
I've used code generators dating back to Visual Studio plugins from the mid-1990's, and eventually started writing my own around the turn of the millennium.
While most code generators are elegant, scriptable, table-driven applications that can be tweaked and customized to handle any number of special conditions, mine are messy, hand-coded affairs that only support the coding style I care about. Yet in my experience many of these elegant systems fail to represent quite enough real-world complexity to be practical aids to development, and more often than not they generate "write only" code.
I treat code generators as junior developers, with the added advantage that they don't want paying. They write only the boilerplate serialization and UI code that would otherwise take up large amounts of relatively unrewarding effort.
They produce code that is indistinguishable in style to the code I write, because they have the corporate coding-standard built in. The ones that generate C++, it is true, use comment-markers to indicate the 'safe' areas for developers to add their own code, which is a product of how hard it is to parse C++. The ones that generate Python take advantage of the language's build-in parser to figure out how not to step on custom additions.
The thing about how messy they are, though, with dozens of special cases hand-coded, is due to a curious fact: good, clean, real-world software is full of special cases and odd exceptions. That is one reason why software development is hard: there are a lot of rules to "good style", to make code readable. This is particuarly true for UI-generating code, where a whole range of different widgets require special conditions to make them behave sensibly and look good, which is surely the goal of all reasonable coding standards.
I'll be writing more here about generating code as time permits. My thinking on the topic has evolved a lot over the past decade, going from grandiose schemes that will change how software development is done, to more modest, practical and effective systems that take a great deal of the day-to-day burden of development off developers, letting them concentrate on design and the custom implementations that will make the application remarkable.



