开发者

If .NET languages are compiled to CIL, does the .NET language choice matter?

If all the .NET languages compile down to CIL, does that mean that the language behind it (VB.NET, C#, etc.) doesn't really matter? Or does the compilation process开发者_开发技巧 treat code differently between the languages? Are there notable differences?


If all the .NET languages compile down to CIL, does that mean that the language behind it (VB.NET, C#, etc.) doesn't really matter?

Yes, that's exactly what it means. No matter which language you have used, as long as it is CLS compliant of course, the CLR doesn't care at runtime as it eats MSIL.

Different languages provide different syntaxes but in all of them you should be able to achieve the same final goal. C# and VB.NET being the flagship .NET languages you can expect most features, progress and support from Microsoft (and StackOverflow :-)). Obviously each language has its own ways of doing things.

There is one important thing to notice though: there are features that are defined in MSIL but not implemented in C#/VB.NET (yet). For example in MSIL you can define an enum or delegate generic constraint but not in high level languages. Jon blogged about this interesting feature.

As far as which one of the two you should choose make sure you never ask such a question here or it is unlikely to survive 1 min before it gets closed.


Well, there are notable differences between the languages.

In particular, I believe C++/CLI has some tricks up its sleeve which C#/VB don't (e.g. the ability to directly modify the value inside a "box"), and I wouldn't be surprised if the reverse were true too.

Likewise different language compilers may make use of different aspects of IL - the F# compiler will use the tail. prefix where the C# compiler doesn't, for example. (And F# is obviously a pretty radically different language to C#, C++/CLI and VB.)

Ultimately though, the JIT compiler neither knows nor cases which source language you used. Use whichever language allows you to get your work done most readably and maintainability. That will depend on both the task at hand and the experience and preferences of the developer team involved. Some languages are better suited to some tasks than others. Until C# 4, for example, VB made it easier to work with COM APIs than C# - but dynamic typing helps to level the playing field here. C# would be a better bet for implementing LINQ to Objects right now as C# has iterator blocks, whereas VB doesn't have anything comparable... just yet, but will actually have better support in the next version.


To some degree, it doesn't matter. The result of compilation of all .Net languages is CIL and you can easily use code created from one of them in a different language (most of the time).

And while, to some degree, different languages have just different syntax, it's not completely true. And syntax can be important too.

For example, if you want to write fully-dynamic code, IronPython is probably a better choice than C#. If you want to write functional code, including more advanced features like monads, F# would be much better than standard procedural .Net languages.


Yes, it can matter a lot.

For example, Visual Basic isn't supported on the XBox or .NET Micro frameworks.

I'm not certain, but I believe that C++ CLI isn't supported on Windows Phone 7. And the dynamic languages certainly aren't. (e.g. anything that uses the DLR.)

If the tooling requires code generation it often comes out for C# before the other languages. And some languges never get the tooling support.

So while I think VB is a superior language to C#, I usually use C# these days for my production work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜