Topics related to the generation of code as the output of an application, instead of directly writing code by a programmer.
Questions tagged [code-generation]
3366 questions
657
votes
21 answers
What is the best way to auto-generate INSERT statements for a SQL Server table?
We are writing a new application, and while testing, we will need a bunch of dummy data. I've added that data by using MS Access to dump excel files into the relevant tables.
Every so often, we want to "refresh" the relevant tables, which means…
![](../../users/profiles/672.webp)
JosephStyons
- 53,646
- 63
- 151
- 228
518
votes
46 answers
Seeking useful Eclipse Java code templates
You can create various Java code templates in Eclipse via
Window > Preferences > Java > Editor > Templates
e.g.
sysout is expanded to:
System.out.println(${word_selection}${});${cursor}
You can activate this by typing sysout followed by…
![](../../users/profiles/82865.webp)
Jon
- 55,763
- 30
- 120
- 149
247
votes
7 answers
Function passed as template argument
I'm looking for the rules involving passing C++ templates functions as arguments.
This is supported by C++ as shown by an example here:
#include
void add1(int &v)
{
v+=1;
}
void add2(int &v)
{
v+=2;
}
template
![](../../users/profiles/74222.webp)
SPWorley
- 10,852
- 9
- 41
- 61
217
votes
11 answers
Why generate long serialVersionUID instead of a simple 1L?
When class implements Serializable in Eclipse, I have two options: add default serialVersionUID(1L) or generated serialVersionUID(3567653491060394677L). I think that first one is cooler, but many times I saw people using the second option. Is there…
![](../../users/profiles/30453.webp)
IAdapter
- 55,820
- 69
- 166
- 236
172
votes
8 answers
Convert Python program to C/C++ code?
is it possible to convert a Python program to C/C++?
I need to implement a couple of algorithms, and I'm not sure if the performance gap is big enough to justify all the pain I'd go through when doing it in C/C++ (which I'm not good at). I thought…
![](../../users/profiles/570252.webp)
CrazyFlyingCloseline
- 1,731
- 2
- 11
- 4
168
votes
12 answers
How do I generate a constructor from class fields using Visual Studio (and/or ReSharper)?
I've gotten accustomed to many of the Java IDEs (Eclipse, NetBeans, and IntelliJ IDEA) providing you with a command to generate a default constructor for a class based on the fields in the class.
For example:
public class Example
{
public…
![](../../users/profiles/33611.webp)
Elijah
- 12,636
- 9
- 54
- 88
127
votes
15 answers
A Java API to generate Java source files
I'm looking for a framework to generate Java source files.
Something like the following API:
X clazz = Something.createClass("package name", "class name");
clazz.addSuperInterface("interface name");
clazz.addMethod("method name", returnType,…
![](../../users/profiles/16135.webp)
Daniel Fanjul
- 3,433
- 3
- 24
- 28
123
votes
6 answers
Rails migration for has_and_belongs_to_many join table
How do I do a script/generate migration to create a join table for a has_and_belongs_to_many relationship?
The application runs on Rails 2.3.2, but I also have Rails 3.0.3 installed.
![](../../users/profiles/242933.webp)
ma11hew28
- 106,283
- 107
- 420
- 616
120
votes
3 answers
How to auto-generate a C# class file from a JSON string
Given the following JSON object,
form = {
"name": "",
"address": {
"street": "",
"city": "",
"province": "",
"postalCode": "",
"country": ""
},
"phoneDay": "",
"phoneCell": "",
"businessName": "",
"website": "",
…
![](../../users/profiles/1108891.webp)
Shaun Luttin
- 107,550
- 65
- 332
- 414
112
votes
7 answers
What is scaffolding? Is it a term for a particular platform?
Scaffolding, what is it? Is it a Rails-only thing?
AnonymousAnonymous
110
votes
27 answers
Should I store generated code in source control
This is a debate I'm taking a part in. I would like to get more opinions and points of view.
We have some classes that are generated in build time to handle DB operations (in This specific case, with SubSonic, but I don't think it is very important…
![](../../users/profiles/1363.webp)
Ron Harlev
- 15,010
- 24
- 83
- 128
102
votes
5 answers
Is it possible to use Razor View Engine outside asp.net
If I look at the Razor View Engine, then I see a very nice and concise syntax that is not particularly tied to generating html. So I wonder, how easy would it be to use the engine outside asp.net in a "normal" .net environment for example to…
![](../../users/profiles/57505.webp)
Thomas
- 7,560
- 4
- 35
- 43
99
votes
2 answers
Naming Conventions For Partial Class Files
I'm generating the bulk of my ASP.NET MVC scaffolding code. All generated files are partial classes which use standard naming conventions. For example, my employee controller file is named EmployeeController.cs. If I wish to extend the…
![](../../users/profiles/4115.webp)
Ben Griswold
- 16,363
- 13
- 53
- 59
86
votes
5 answers
Can I define properties in partial classes, then mark them with attributes in another partial class?
Is there a way I can have a generated code file like so:
public partial class A
{
public string a { get; set; }
}
and then in another file:
public partial class A
{
[Attribute("etc")]
public string a { get; set; }
}
So that I can…
![](../../users/profiles/86259.webp)
Chris McCall
- 10,043
- 8
- 46
- 79
83
votes
11 answers
Builder pattern code generation in IntelliJ
Is there any way to automate writing Builder patterns in IntelliJ?
For example, given this simple class:
class Film {
private String title;
private int length;
public void setTitle(String title) {
this.title = title;
}
public…
![](../../users/profiles/264276.webp)
Martyn
- 15,782
- 24
- 69
- 104