Questions tagged [code-generation]
66 questions
138
votes
27 answers
Is source code generation an anti-pattern?
If something can be generated, then that thing is data, not code.
Given that, isn't this whole idea of source code generation a misunderstanding? That is, if there is a code generator for something, then why not make that something a proper function…
Utku
- 1,912
112
votes
22 answers
Automatic programming: write code that writes code
After reading the book The Pragmatic Programmer, one of the arguments I found most interesting was "write code that writes code".
I tried searching over the net for some more explanations or articles about it, and while I found some good articles on…
Jose Faeti
- 2,815
51
votes
5 answers
Do I check generated code in to source control or not?
I'm developing a .Net application that uses google protocol buffers. Historically the application used the approach, advocated by the protobuf-net team, of decorating the classes with attributes instead of using .proto files.
I am now in the process…
Dave Hillier
- 3,928
33
votes
6 answers
Why do programs use call stacks, if nested function calls can be inlined?
Why not have the compiler take a program like this:
function a(b) { return b^2 };
function c(b) { return a(b) + 5 };
and convert it into a program like this:
function c(b) { return b^2 + 5 };
thereby eliminating the computer's need to remember…
moonman239
- 2,063
23
votes
8 answers
Detect manual changes to an autogenerated C header
I have a C header that is generated from a CSV file and a Python script. The C header mainly contains a list of #define constants.
I want to be able to detect manual changes to this header during compilation (which tends to happen frequently in this…
9a3eedi
- 2,099
22
votes
4 answers
How do we go from assembly to machine code(code generation)
Is there an easy way to visualize the step between assembling code to machine code?
For example if you open about a binary file in notepad you see a textually formatted representation of machine code. I assume that each byte(symbol) you see is the…
user12979
- 375
13
votes
4 answers
Automatic code generators
One of my colleagues likes to use automatic code generators, which create large amounts of code that is poorly documented and very hard to maintain.
Is the cost of using a code generator worth the hassle in maintenance, for the reduced time to…
Mumbles
- 469
13
votes
6 answers
Automatic source code generation -- good idea or potential nightmare?
In response to my question regarding Java source code generation, I received this answer warning me about potential maintenance problems:
mixing auto-generated code always pose a risk of someone modifying it in future to just to tweak a small…
Tony the Pony
- 440
12
votes
2 answers
Design decision - why generate without
?
tl;dr
Some widely used programs, which generate html, will only generate opening paragraph tags, and not closing ones, assuming that the browser will properly close paragraphs.
On the face of it, it seems to me that the assumption that browsers will…
blueberryfields
- 13,360
11
votes
2 answers
How easy should a language development framework be to use?
This is part of a series of questions which focuses on a project called the Abstraction Project, which aims to abstract the concepts used in language design in the form of a framework.
Another page associated to it related to structural typing can…
11
votes
1 answer
Way for generating C# classes from existing C# class
I have simple POCO classes, like this:
public class Book
{
public string BookId { get; set; }
public string Name { get; set; }
//etc...
}
I want to get all those classes and generate another classes, which called viewmodels, for…
Yurii N.
- 341
10
votes
5 answers
Generating Java Classes with Compile-time Value Parameters
Consider a situation where a class implements the same basic behavior, methods, et cetera, but multiple different versions of that class could exist for different uses. In my particular case, I have a vector (a geometric vector, not a list) and that…
Parker Hoyes
- 225
10
votes
4 answers
Writing a Compiler Compiler - Insight on Use and Features
This is part of a series of questions which focuses on the sister project to the Abstraction Project, which aims to abstract the concepts used in language design in the form of a framework. The sister project is called OILexer, which aims to…
8
votes
3 answers
code generation - would C be a good compiler backend?
In this and this stack overflow questions, the answers state that C as a compiler backend is a bad idea.
But why?
C has many compilers that can heavily optimize it. Every platform has a compiler that supports it, and it can be compiled to every…
8
votes
4 answers
Should one test generated code?
My team doesn't write tests for generated code (e.g. some POJOs). An engineer that I greatly respect recently wrote this on the subject:
Research over the past 10 years has revealed that generated code is as
prone to bugs as other code, and in…
Justin R.
- 189