Kean and I were recently interviewed by Andrew Roe for his Cadalyst series on programming AutoCAD. As part of the discussion (not all of which appeared in his article), he asked us our opinions on which programming language was best for beginner programmers new to AutoCAD .NET development.
The quick answer to this is that it really doesn’t matter. All .NET programming languages are ‘compiled’ to a common intermediate language (Microsoft’s Common Intermediate Language, or CIL for short). This means that I can use any .NET programming language I like to access the AutoCAD .NET API. I can even mix and match – for example by writing part of my code in C# and extending it in VB.NET. There is a huge range of .NET programming languages to choose from, and (in theory) you can use any of those. However, as for anything in the real world, there are practical considerations.
The most common choice is VB.NET or C# (or F# if you’re a big fan of Kean’s blog ). Factors that will affect your choice between VB.NET and C# include:
- Company standards – No point learning VB.NET if your coding standards require everything to be in C#.
- Friends and colleagues – Your best programming resource is someone you know who’s willing to spend time answering all your noobish questions. They can help you so much more easily if you’re learning the language they are most familiar with.
- Your background – If you’ve already dabbled in VBA or VB6, then VB.NET will be a shallower learning curve. If you’re a C++ programmer, then you’ll likely choose C# (so you can keep your semicolons
).
- Code samples – What language are most of the available code samples available in?
My choice of.NET language is slightly unusual considering my background. My first exposure to programming was through being a computer geek as a kid. My parents bought a BBC Micro to help my brother with his Computer Studies homework. My brother used it mostly to play games; I used it to learn BBC BASIC and later FORTRAN. I studied Physics as an undergraduate, which included modules on programming – in Pascal on NeXT boxes. For my post-graduate study, I variously programmed in FORTRAN (on an IBM mainframe), Object Pascal and C on Mac OS 7 – writing simulations to model the results of my plasma physics experiments. Then I got bored one day when the laser in our lab was offline for repairs and read through a teach yourself C++ book. Finally (and embarrassingly since I’d already been using Object Pascal), I understood what Object-Oriented Programming was all about. From there on in it was C++ only until Microsoft launched .NET.
Which is why – of course – when faced with a choice between C# and VB.NET, I chose VB.NET.
My reasoning was simple: If any language complies down to the same CIL code, then it really doesn’t matter which language you choose. All my C++ programmer friends were learning C# and feeling superior because they weren’t VB programmers – so I went for VB.NET to prove my point. (I can be a bit contrary sometimes).
[BTW That’s another factor to consider in your choice of programming languages – some C# programmers still look down their noses at VB.NET. As a VB.NET programmer, you quickly learn to smile knowingly and get on with writing great code ].
That was about eight years ago. (AutoCAD 2005 included our first .NET (preview) API). I still stand by that early decision – I’ve not yet found anything I wanted to do that I couldn’t do in VB.NET. (Hmm - That statement could open up a can of worms ). However, just before talking to Andrew, I’d started dabbling with iOS and Android development. That caused me to answer Andrew’s question slightly differently than I had in the past …
The four factors I list above are still the main issues to consider when starting .NET development. For example, if I were programming Revit, I’d definitely go for C# because there are very few VB.NET samples available. You can translate C# to VB.NET using online translators, such as http://www.developerfusion.com/tools/convert/csharp-to-vb/, but it’s a bit of a pain having to do it for every code sample. There’s a better balance between VB.NET and C# in the AutoCAD .NET world, so the choice there depends more on the other three factors.
But now I’ve added a fifth factor to consider – your future plans.
If you’re happy that you’ll only ever be programming on Windows, and if you have little programming experience (or if you’ve dabbled in VBA or VB6), then VB.NET is an obvious choice for you. After all, BASIC was originally designed as a language for beginners. If, on the other hand, you have ambitions to join the revolution and try your hand at mobile or cloud computing development, then my recommendation is to accept the steeper learning curve of C# because its going to make it easier to learn the native programming languages for those platforms:
- iOS (Apple’s iPhone/iPad operating system) uses Objective-C – like C++, this is a C derivative. (And in my humble opinion and limited experience is an extremely ugly programming language).
- Android uses Java – and derives much of its syntax from C/C++.
- Java is also extremely widely used for cloud/web programming, and JavaScript is a mainstay of scripts on webpages.
I’ve been particularly enjoying dabbling with Android development in recent weeks. As I’ve been hacking around, I started wondering just how easy it is to convert C# code into Java, so I decided to test by writing an AutoCAD .NET plug-in in C# and then converting it to an Android app. I’ll be writing up my findings in a series of posts, but I’m starting with this article because one thing has become very clear to me as I’ve been playing around:
I’ve struggled the most in this project because my preference for VB.NET has left my C# skills very rusty. The hardest part for me was translating my VB.NET knowledge to C#. Once I’d written the C# code, migrating it to Java was disconcertingly easy - which is why my advice for beginners has now changed.
Just how easy the migration was will be the subject of a future post. For now, feel free to add a comment to stake your position in the great VB/C# debate …