Questions tagged [code-generation]

Topics related to the generation of code as the output of an application, instead of directly writing code by a programmer.

3642 questions
749
votes
24 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…
JosephStyons
  • 57,317
  • 63
  • 160
  • 234
521
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…
Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150
272
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
SPWorley
  • 11,550
  • 9
  • 43
  • 63
228
votes
10 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…
IAdapter
  • 62,595
  • 73
  • 179
  • 242
221
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…
CrazyFlyingCloseline
  • 2,229
  • 2
  • 14
  • 4
181
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…
Elijah
  • 13,368
  • 10
  • 57
  • 89
149
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": "", …
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
131
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…
Ron Harlev
  • 16,227
  • 24
  • 89
  • 132
130
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,…
Daniel Fanjul
  • 3,493
  • 3
  • 26
  • 29
127
votes
10 answers

What is scaffolding? Is it a term for a particular platform?

Scaffolding, what is it? Is it a Rails-only thing?
AnonymousAnonymous
126
votes
7 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.
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
113
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…
Ben Griswold
  • 17,793
  • 14
  • 58
  • 60
103
votes
6 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…
Thomas
  • 7,933
  • 4
  • 37
  • 45
95
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…
Chris McCall
  • 10,317
  • 8
  • 49
  • 80
95
votes
11 answers

Why do PHP Array Examples Leave a Trailing Comma?

I have seen examples like the following: $data = array( 'username' => $user->getUsername(), 'userpass' => $user->getPassword(), 'email' => $user->getEmail(), ); However, in practice I have always not left the trailing comma. Am I doing…
ashurexm
  • 6,209
  • 3
  • 45
  • 69
1
2 3
99 100