怎么会有人像 Java 一样制作 c# 增量编译器?
几年前有人问为什么c#不允许像Java 一样的增量编译。 El Skeet 表示,这与 Java 输出 .class 文件而不是程序集有关。
既然它的 2011 和诸如 Mono 编译器即服务之类的绝妙东西已经发布,那么需要做什么来为 C# 制作一个增量编译器呢?
编辑:对于每个人都在谈论这不是问题,这是我链接到的线程中乔恩·斯基特(Jon Skeet)的引用:
您是否建议您永远不会发现自己在等待构建?甚至15 秒?如果构建需要 15 秒,而您想要构建 20 次 一个小时(我当然是用TDD做的)这意味着我浪费了5个小时 分钟。休息 5 分钟是一回事 - 这是一个好方法 放松等 - 但 20 次 15 秒的停留可能会非常痛苦 令人沮丧。时间不够长,无法做任何有用的事情(除了 也许喝一杯)但时间已经足够长了。
我怀疑有两个因素导致了我的烦恼程度 其他人显然没有: 1) TDD 确实依赖于更快的周转 2) 在 Eclipse 中使用 Java 时,这种延迟非常罕见
Years ago someone asked why c# doesn't allow incremental compilation like Java. El Skeet said it is to do with Java outputting .class files rather than assemblies.
Now that its 2011 and groovy things like the Mono compiler-as-a-service have been released, what would need to be done to make an incremental compiler for c#?
edit: to everyone banging on about how this isn't a problem, here's a quote from Jon Skeet from the thread I linked to :
Are you suggesting you never find yourself waiting for a build? Even 15
seconds? If a build takes 15 seconds and you want to build 20 times in
an hour (which I certainly do with TDD) that means I'm wasting 5
minutes. Taking a 5 minute break is one thing - that's a good way of
relaxing etc - but being held up for 15 seconds 20 times can be very
frustrating. It's not long enough to do anything useful (other than
maybe sip a drink) but it's long enough to irritate.I suspect two factors contribute the level of annoyance I feel which
others apparently don't:
1) TDD really relies on a faster turnaround
2) When working with Java in Eclipse, such delays are very rare
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有做,那么只有一个原因:做这件事的努力高于可能获得的收益。
微软肯定不会这样做,因为成本太高:.net 代码存在于程序集中,没有人会更改它。是的,程序集会阻止逐类增量编译。没有人会停止使用组件。
这就是我的答案,为什么没有人需要它。您可以将构成单个项目的类分布在多个程序集中,然后一一编译它们。它实际上是增量编译,但不如逐类增量编译那么细粒度。当您的架构设计正确时,汇编级增量编译就足够了。
编辑:好的,我下载了 Mono C# 编译器来看看是否可以使其增量。我认为这不是很难。基本上它执行以下步骤:1)解析文件2)编译3)创建程序集。您可以在类型编译后挂钩某处,然后保存到某种中间文件中。然后仅重新编译更改的内容。所以这是可能的,但看起来这对于 Mono 团队来说并不是高优先级的问题。
编辑2:我发现这个有趣的线程,人们在其中讨论 Mono C# 编译器的增量编译。它相当旧,但关键解释可能仍然有效:
编辑3:C#编译器在v1.0和v1.1中有
/incremental
选项,但它是已删除:编辑4:Miguel de Icaza给出了明确的答案(1,2) 为什么 Mono Compiler 不会是增量的:
所以他认为这是一项比一个人的论文更艰巨的任务。 Mono 还有更多突出且实际的任务。
If it was not done then there is only one reason for it: efforts to do it are higher than possible benefits.
Microsoft will definitely not do it because costs are too high: .net code lives in assemblies and no one will change it. And yes, assemblies prevent class-by-class incremental compilation. No one will stop using assemblies.
And here is my answer why no one needs it. You can distribute your classes that constitute single project among several assemblies and compile them one by one. It is actually incremental compilation but not as fine-grained as class-by-class incremental compilation. And when your architecture is properly designed assembly level incremental compilation is sufficient.
Edit: Okay, I downloaded Mono C# compiler to take a look it is possible to make it incremental. I think it is not very hard. Basically it does following steps: 1) Parse files 2) Compile 3) Create assembly. You could hook somewhere after types are compiled and save then into some sort of intermediate files. Then recompile only changed ones. So it is possible, but looks like it is not high-priority issue for Mono team.
Edit 2: I found this interesting thread where people discuss Incremental compilation for Mono C# compiler. It is rather old but key explanation might be still valid:
Edit 3: C# compiler had
/incremental
option in v1.0 and v1.1, but it was removed:Edit 4: Miguel de Icaza gives clear answer (1, 2) why Mono Compiler will not be incremental:
So he considers it to be a task huger than for one man's thesis. And Mono has much more outstanding and actual tasks.