Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any reason why C#/VS doesn't have an auto-build feature like Java/Eclipse?

I am a C#/.Net developer who just began Java development for Android, and using Eclipse I noticed that it compiles as you go, so that at no point do you have to wait for the program to build. This seems pretty amazing, unless there is something going on I don't understand.

I was wondering why C# and the Visual Studio IDE don't provide this functionality? Is there a reason?

like image 655
JimDaniel Avatar asked Sep 11 '10 19:09

JimDaniel


1 Answers

This doesn't really have anything to do with Java. It's more a feature of Eclipse. In particular, incremental background compilation is a standard feature of all Smalltalk IDEs since at least 1978 or thereabouts, and even longer than that in Lisp IDEs.

Eclipse was originally a Smalltalk IDE, written in Smalltalk, and it is still to this day maintained by IBM's Smalltalk division. So, when IBM's Smalltalk division developed their own Java compiler, they naturally wrote it to be incremental and re-entrant, just like their Smalltalk compilers. And this compiler, called Jikes was open-sourced together with Eclipse and became the ecj (Eclipse Compiler for Java) that powers all of the incremental on-the-fly compilation, syntax highlighting, code completion, type inference and refactoring capabilities of Eclipse JDT.

There is absolutely no reason why this shouldn't be possible for C# as well. The reason why it doesn't work, is because the compiler doesn't support it, in particular, the compiler is not incremental. But that is not an inherent limitation of .NET or C# or Visual Studio, that's a limitation in the imagination of the C# compiler maintainers: traditionally, all compilers at Microsoft were written in C++ by the C++ compiler team, and those guys simply have never heard of incremental compilation. Not because they are stupid, but because in the C++ community nobody cares about that.

But, for example, the VB community does care about that stuff, because they are used to it from VB Classic. So, the VB.NET compiler actually supports incremental building, edit-and-continue, IntelliSense, type inference and refactoring.

Of course, the C# plugin supports a lot of that stuff, too, but they don't use the actual C# compiler to do that. Instead, they basically had to re-implement half of the compiler for the Visual Studio plugin to work, but they didn't implement the actual code generation backend, so while the "compiler" which is part of the plugin can do incremental parsing, syntax highlighting, refactoring and edit-and-continue, it cannot actually, you know, compile.

The situation for C# is going to change, however: the responsibility for the compilers was reassigned to the respective language teams, and the C# team is currently in the process of re-implementing the compiler in C# and within the C# team. One of the often talked about results of this rewrite is going to be the Compiler-as-a-Service feature, which allows you to compile small snippets of C# and/or Expression Trees on-the-fly and which powers for example the also often demonstrated C# REPL and C# Scripting capabilities.

Given that in order for the REPL to work, the compiler needs to be able to compile small individual snippets of code anyway, and the new compiler is supposed to be used in the Visual Studio C# plugin to replace the current pile of IntelliSense and syntax highlighting hacks, it shouldn't be too hard to get incremental compilation going in Visual Studio.

like image 87
Jörg W Mittag Avatar answered Sep 21 '22 11:09

Jörg W Mittag