The "native" .NET language?

Paul Vick reply to the question “isn't C# the language that's most 'native' to the .NET environment?”


The problem with blanket pronouncements like “always use CLR functions instead of VB functions“ is that you can easily shoot yourself in the foot without knowing it. One suggestion I've seen in more than one place is to use the functions exposed by the Convert class (a CLR class) instead of the intrinsic conversion operators (CInt, CStr, CLng, etc.) exposed by the VB language. This is supposedly because the CLR functions are going to perform better than the VB “functions.” The problem with this is that the conversion operators are true operators that compile down to IL instructions while the Convert functions are still just functions. This means you'll get significantly worse performance by calling Convert.ToInt32 instead of using CInt. So it's always very important to know what you're doing when you start tackling issues like performance.

So, in the end, there is no “native” language on the CLR and performance is something you're going to have to think about no matter what language you choose. (In fact, I think I should add a rule #0 to my “Ten Rules of Performance:” When it comes to performance, beware rules.) There are certainly lots of other factors to think about when choosing between VB and C#, but I don't think these are two of them.



No Comments