你用code生成工具? [英] Do you use code generation tools?

查看:123
本文介绍了你用code生成工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你用code-生成工具(除了那些用来生成代理,并从内置到Visual Studio的设计师)?

Do you use code-generation tools (aside from those used to generate proxies and from designers built-in to visual studio)?

你生成你的应用程序的一部分(S)?

What part(s) of your application do you generate?

你通常推出自己的发电机?如果是这样,你写什么类型的发电机(ASP模板,coddom等)。如果没有,你用什么第三方工具?

Do you typically roll your own generator? If so, what type of generator do you write (asp templates, coddom etc.). If not, what 3rd party tools do you use?

我目前工作的几个不同的项目至极都使用自定义的code-发生器处理一切从生成数据库结构,业务实体,DAL和BLL。我很好奇其他人的经验是用这些工具。

I am currently working on a few different projects wich all use a custom code-generator that handles everything from generating the database structure, business entities, DAL, and BLL. I am curious about other peoples experiences are with these kinds of tools.

推荐答案

我在哲学阵营认为code生成是错误的,因为它们预示着什么,应作出语言的一部分。

I'm in the philosophical camp that considers code generators to be "wrong", because they indicate something that should be made part of the language.

但它一直是语用程序员的伦理写code写入code的重要组成部分,并在实践中code一代行之有效的,如果产生的code默认是隐藏的。无论你想怎样哲学纯是,语言永远不会演变为要解决的问题,以最快的速度。

But it's been a big part of the Pragmatic Programmer's ethic to write code that writes code, and in practice code generation works well if the generated code is hidden by default. No matter how philosophically pure you want to be, the language will never evolve as fast as the problems you want to solve.

当你建立一个Windows窗体在Visual Studio想到的获取生成的code。你可以看一下生成的code,如果你想要的,但它是一个更好的主意都不到。移动到一个说明性语言与WPF是优越的,但是,因为它是更清洁,更可靠的以编程方式操作声明code比势在必行code。

The code that gets generated when you build a Windows Form in Visual Studio comes to mind. You can look at the generated code if you want, but it's a better idea not to. Moving to a declarative language with WPF was superior, however, because it's cleaner and more reliable to manipulate declarative code programmatically than imperative code.

他们应该做同样的事情LINQ到SQL类。他们需要一个声明的语言,仅仅具有属性和没有自定义行为的类。或许,这将使它更容易使这些实体类的动态 - 自动改变当底层数据库架构更改

They should have done the same thing with LINQ-To-SQL classes. They need a declarative language for classes that just have properties and no custom behavior. It probably would make it easier to make those entity classes dynamic--changing automatically when the underlying database schema changes.

我们尝试使用codeSmith产生.NetTiers类的所有表在我们的数据库中,但遇到了两个问题:

We tried using CodeSmith to generate .NetTiers classes for all the tables in our database, but ran into two issues:

  1. .NetTiers是臃肿,和code产生的是巨大的。我认为,code生成工具使它很容易的生物feep。

  1. .NetTiers was bloated, and the code generated was enormous. I think code generation tools make it too easy to creature feep.

由于架构正在积极制定和修订,我们不得不重新生成了很多,也和这最终使得它很难保持所有的源代码控制,因为所有的文件都被再生和替代。我最终被确定,如果产生的code的应该的源代码控制的。

Because the schema was being actively developed and revised, we had to regenerate a lot, too, and that ended up making it very difficult to keep everything in source control because all the files were being regenerated and replaced. I ended up being unsure if the generated code ought to be in source control at all.

为code一代最好的地方应该是在编译或构建阶段,而不是设计阶段。当您使用C#匿名类型或方法,编译器做对飞code一代。如果产生在设计阶段code,你得到一大块的的东西的,必须每次基本参数改变再生。

The best place for code generation should be in the compiler or the build phase, not the design phase. When you use an anonymous type or method in C#, the compiler is doing code generation on the fly. If you generate code during the design phase, you get a chunk of stuff that must be regenerated every time the underlying parameters change.

这篇关于你用code生成工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆