Questions tagged [code-generation]
63 questions
135
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,922
- 4
- 17
- 19
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
- 2
- 23
- 30
50
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,940
- 1
- 25
- 37
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,023
- 4
- 18
- 23
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,101
- 3
- 23
- 29
19
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
- 345
- 1
- 3
- 4
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
- 1
- 6
- 16
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
- 1
- 3
- 10
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,200
- 8
- 51
- 87
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…

Allen Clark Copeland Jr
- 401
- 2
- 16
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
- 3
- 12
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
- 2
- 5
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…

Allen Clark Copeland Jr
- 401
- 2
- 16
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…

Kied Llaentenn
- 91
- 5
7
votes
2 answers
How to generate java class files with framework boilerplate in a project?
The Java project I am working on currently has a complicated folder structure, and to add a new functionality, one needs to add many .java files in different places in order to let it work in our project structure. For example, when I want to add a…

Xiang Wei Huang
- 181
- 5