Reputation:
Which areas of programming are each language best suited for?
I like both C++ and C# but i prefer to use C# because of .NET.
My question is when will you use C++ and when do you use C#?
So if you make a financial application for a company you will use C#? ( It's easy to design a form and connect to a database without downloading 3rd party libraries, and if you make advanced algorithms you would use C++ for it's speed?
This is my idea. I just watched video's @ http://www.academicearth.org, and it seems that universities prefer to use C++ for Machine Learning for example.
What do you guys think of it? and what is the industry view on this.
Upvotes: 5
Views: 6856
Reputation: 97671
Trying to compare the two isn't really fair -- C++ is usually used nowadays when you have the need for low-level, or portable, high performance code. You rarely find it used to implement business logic for enterprise systems, though about 10 years ago you did. You certainly wouldn't want to start out development with an enterprise system with C++ today unless you had a really, really good reason to.
But in academia, C and C++ have been used for many years, so it's probably not surprising that there is a large base of C++ code there for things like Machine Learning. C++ can often be faster than C# when it's optimized properly. It can run with less memory, on more platforms, and with fewer dependencies on large frameworks than C# can.
C#, however, is a lot more forgiving with its memory model, and typically has access to Microsoft or Mono's very large, comprehensive framework which allows developers to do a lot of stuff with minimal development effort, time, and cost. If you're working on the Microsoft platform, it is arguably the standard language nowadays.
Upvotes: 12
Reputation: 791361
From a commercial and support perspective, C# is still a one platform wonder. If you're not targetting the .NET runtime then it's not usually a realistic choice to use C#.
C++ is supported by a huge array of platforms, from embedded OS's to super-computers.
If you're targetting .NET, then C# is probably a more suitable language, there isn't really a good binding for C++, C++/CLI is more like a different or extended language in any case.
If there is a genuine choice, then the most overriding consideration should be the expertise available. Getting a bunch of C++ experts to develop in C# is a poor use of skills; writing a system in C++ with no C++ experts will probably result in a mess.
Upvotes: 2
Reputation: 5637
The one feature I like in C++ is the low-level access to memory and the control over memory-layout of structures. If you interface with even lower level APIs such as OpenGL, you usually interact with arrays of basic datatypes, such as floats. In C++, you can cast a void* texture to user defined types such as Image2D<PixelWithAlphaChannel<float, 4> >
and use a fully object oriented interface for this otherwise unstructured dump of unspecified data.
If you cannot afford to keep multiple copies of low-level API data, C++ is the way to keep your code clean. However, you trade a lot of developer time for this. While in theory C++ allows for faster code (or at least the same speed, you could implement .NET in C++, but not vice versa), having tools such as Resharper and dotTrace can enable developers to improve the performance faster. So in practice, I'd opt for C# for both financial applications AND performance critical algorithms, IF they are not constrained by low-level APIs.
Upvotes: 2
Reputation: 150108
Always use C# for business solutions. It's a more evolved language.
I worked for a company that does real-time authentication for PPV (like if you buy WWE or boxing on cable). They have huge volume right before the event. The team that worked on that part insisted that it had to be written in C++ for speed.
After a year of debating, we finally wrote a prototype replacement in C#. It turned out that the replacement was twice as fast.
There are VERY few problem domains where you need any of the optimizations you can do in C++ that are unavailable in C#, but C# code is much less error prone.
Upvotes: 7
Reputation: 212
Often we will use C# for front-end UI development, and C++ for server-side. One of the main reasons is portability/speed. People tell me mono for C# on linux/OSX is fast and stable, but from what I have seen that is not the case. YMMV.
Upvotes: 2