code-generation

Generating pass-through code when “preferring composition over inheritance”

北战南征 提交于 2019-11-30 06:22:09
Problem Let's say I'm trying to model a cell phone as a combination of a regular phone and a PDA. It's sort of a multiple inheritance scenario (a cell phone is a phone, and it is a PDA). Since C# doesn't support multiple inheritance, this pretty much calls for some kind composition. Plus, let's say that I have other reasons to favor composition anyway. The thing I always wonder: Are there any tools that will generate all the inevitable pass-through code automatically? Let me flesh out my example with some actual code: Interfaces: public interface IPhone { public void MakeCall(int phoneNumber);

What's the use of metaprogramming?

♀尐吖头ヾ 提交于 2019-11-30 06:14:04
问题 I've read: Wikipedia Code Generation vs. Metaprogramming The art of Metaprogramming Metaprogramming at c2.com and I confess some confusion at the purpose behind metaprogramming/code generation. Does anyone have a concrete example of where they use metaprogramming/code generation? Even better would be an accompanying explanation of why it was better than an alternative. edit : Would Thistle be considered metaprogramming? 回答1: Imagine a guy who builds cars. Say it's the same thing as using a

Can I configure Hibernate to create separate sequence for each table by default?

空扰寡人 提交于 2019-11-30 05:47:14
问题 Hibernate by default creates a globel sequence which is used to generate ids for all tables, (in the case for PostgreSQL) which scales very bad IMHO. Though I can specify for each entity type which sequence to use, I don't like to do it. I don't like to explicit name the sequence and force to use sequence as the generator strategy, because I want hibernate generate DDL for databases which may not support sequence at all. The single global sequence also make it impossible to use 32-bit int as

Automatically generating Java source code

馋奶兔 提交于 2019-11-30 05:26:34
I'm looking for a way to automatically generate source code for new methods within an existing Java source code file, based on the fields defined within the class. In essence, I'm looking to execute the following steps: Read and parse SomeClass.java Iterate through all fields defined in the source code Add source code method someMethod() Save SomeClass.java (Ideally, preserving the formatting of the existing code) What tools and techniques are best suited to accomplish this? EDIT I don't want to generate code at runtime; I want to augment existing Java source code Modifying the same java

C# to format (indent, align) C# properly

依然范特西╮ 提交于 2019-11-30 04:54:33
问题 We have a code generator that munges the schema of a given database to automate our inhouse n-tier architecture. The output is various C# partial classes, one per file. In the code to munge all the strings, we try and keep on top of the indenting and formatting as much as possible, but invariably when you come to open the file in Visual Studio the formatting is awry. A quick ctrl-k, ctrl-d fixes it, but obviously this reformatting is lost the next time the class is generated. What I'd like to

How do I determine if a column is in the primary key of its table? (SQL Server)

痴心易碎 提交于 2019-11-30 04:53:08
I am currently using... select Table_Name, Column_name, data_type, is_Nullable from information_Schema.Columns ...to determine information about columns in a given database for the purposes of generating a DataAccess Layer. From where can I retrieve information about if these columns are participants in the primary key of their table? Galwegian Here is one way (replace 'keycol' with the column name you are searching for): SELECT K.TABLE_NAME , K.COLUMN_NAME , K.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS C JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS K ON C.TABLE_NAME = K.TABLE

Stored Procedure generator tool [closed]

放肆的年华 提交于 2019-11-30 04:51:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am looking for tool which will generate the basic stored procedure structure (CRUD operations) for the given table, Is there any tool for the same? 回答1: For MS SQL there is SSMS Tools Pack, works great! 回答2: If you want to generate stored procedures to access your relational database system, you should look at

Do you create your own code generators?

雨燕双飞 提交于 2019-11-30 04:28:52
The Pragmatic Programmer advocates the use of code generators. Do you create code generators on your projects? If yes, what do you use them for? Code generators if used widely without correct argumentation make code less understandable and decrease maintainability (the same with dynamic SQL by the way). Personally I'm using it with some of ORM tools, because their usage here mostly obvious and sometimes for things like searcher-parser algorithms and grammatic analyzers which are not designed to be maintained "by hands" lately. Cheers. In "Pragmatic Programmer" Hunt and Thomas distinguish

T4 Templates - suitable for generating C++ code?

萝らか妹 提交于 2019-11-30 04:02:11
问题 Are there any issues which might make MS's T4 Template code-generation system unsuitable for generating C++ code? 回答1: It can generate any text you want, including C++ code. 回答2: A bit lengthy answer yet I think some might find it interesting I would say T4 is excellent to generate C++ with Some might retort that C++ already has tools to do MetaProgramming with like: The Preprocessor Using the preprocessor and higher-order macros you can achieve somewhat what you can do with T4, but I say

Code generators vs. ORMs vs. Stored Procedures

ε祈祈猫儿з 提交于 2019-11-30 01:58:54
In what domains do each of these software architectures shine or fail? Which key requirements would prompt you to choose one over the other? Please assume that you have developers available who can do good object oriented code as well as good database development. Also, please avoid holy wars :) all three technologies have pros and cons, I'm interested in where is most appropriate to use which. Every one of these tools provides differing layers of abstraction, along with differing points to override behavior. These are architecture choices, and all architectural choices depend on trade-offs