My career is varied and quite long. I started out age 11 on TI BASIC and then ZX BASIC, writing a game at age 14. By 1990 I was using C and 68000 assembler quite freely and in 1993 I did a text editor in MC68000 on an Atari ST, some 130,000 lines of code in under 3 months for a university project.
My use of C++ came about around 1995 when I started working for a college who had a contract to write a piece of educational software for Windows 3.1 just before Windows 95 was released. I'd been dabbling at home and I actually got a very cheap license of Borland C++ 5.
In 2001 when there was a beta of the SDK I dabbled with C# and also at the time I was heavily involved in ASP development. In late 2003 the company I worked for got a contract for a small app and we did it in C#/ASP.NET and that was my first real .NET application - I never looked back.
About 3-4 years ago I slowly moved back to C++ in the form of MFC while working on projects in C#. We use Visual Studio 2010 currently and have done for around 3 years (VS6 previous!!) and looking to move to VS2015 soon.
You could say I have a bit of experience in both languages. What language would I recommend?
There is actually no clear answer. For basic simple applications I would say it probably doesn't matter too much. For larger projects with many users there are issues. Below is a list of what I deem key points for both languages.
C++
C++ is a nice language with real power. In VS2010 the insight is not great and if you happen to want to use a native/framework hybrid then you're in for a world of hurt - I know newer versions address this.
- C++ is fantastic for 3D work (DirectX) in windows apps.
- It's also fast so if performance is an issue then it's great.
- The language is established and there's a lot of cross-platform code out there that just works.
The downside?
- UI-wise it's a very painful experience. MFC C++ in particular uses a .rc file for the form design, menus, images and the likes and when you're working on multi-user projects the merging of resources is a nightmare - often so that it can go totally wrong. You have to co-ordinate commits of resources with the team.
- Then there's another issue which is crazy IMO. Numerical accuracy. Doubles are supposed to be accurate to 14SD or there abouts and yet assigning 0.3 doesn't give you 0.3, it gives you 0.2999999999999997. We discovered this recently.
- Finally, Because of heavy use of pointers the learning curve is big and memory leaks like to happen - studio does report them but in a vomitous form.
C#
C# is similar enough in syntax to C++ to be easy to learn and also the fact the languages (libraries excluded) are simple makes the journey quick to get up and going.
- C# as you are probably aware supports WPF and Forms development as well as ASP.NET. This has the advantage over C++ in that the forms are handled individually so greatly reduced merge conflicts.
- Numerical accuracy seems better so the C++ number issue doesn't occur.
- There are massive libraries and if a library doesn't do something, there's a lot of code out there too and third party control libraries.
- Code is easily shared between apps and even to C++ via COM - it can be done both ways.
- Loads of plug-ins to help with authoring of code
- Visual Studio and C# together work beautifully.
- LINQ - it's brilliant and while VB.NET supports it partially, C++ supports it fully and it's a beautiful thing.
- Generally C# applications look nicer because they can.
- If you need to work with databases, C# and .NET is fantastic and you have so many choices as to how you do it. It's not impossible with C++, it's just it's so easy with C#.
There are downsides too.
- WPF can be painful, if awkward. Sometimes things just don't work the way you want them to.
- It's not as fast as C++ but it's a trade-off between performance and speed of development.
Summary
Looking at the 2 lists, it would seem clear that C# is actually the best of the two but it really depends on what you are doing. Does your application need CPU Intensive calculations to be performed quickly??? This may actually be the key point. Also, does it need heavy 3D graphics* or are they basic enough? Do you need to share code between web and windows apps or possibly even other applications like MS Excel? Do you need to use a relational database?
Sharing is easier for C# or .NET in general and doing things are generally easier. C++ excels at speed and 3D and you can use pointers to squeeze every ounce of that performance out of your system when working with huge amounts of data.
What would I choose? C# pretty much most of the time. It's just easier to work with. C++ for anything that needs a 3D display without question.
* 3D is supported in the likes of WPF but as we experimented, we saw its limitations compared to using DirectX - it works, it's fast and it just wins. What a team did was write the 3D parts of the app in C++ and embeded them on a WPF form and it works brilliantly.
No comments:
Post a Comment