Which are advantages and disadvantages of C# over C++?
This is a discussion on C# and C++ within the C# Programming forums, part of the General Programming Boards category; Which are advantages and disadvantages of C# over C++?...
Which are advantages and disadvantages of C# over C++?
IDE: DevC++ 22.214.171.124 (GCC 3.4.2)
2nd compiler: g++ (GCC 3.4.3/4.0.0)
3rd compiler: Borland 5.5
IDE: Microsoft Visual C# Express 2005
2nd IDE: SharpDevelop
2nd compiler: csc in Command Prompt
.NET Framework: 2.0
Core: 5.1.0 beta 3
2nd IDE: Notepad
Favourite extensions: exif,gd2,mysql
Favourite PEAR packages: DB, XML_RSS, ID3
Favourite databases: SQLite, MySQL
Have a look at what employers are asking for nowadays by going to any reputable job site
hoping to be certified (programming in c)
here's the news - I'm officially certified.
One is better suited for a job than the other. When you look at a specific job, chose the right tool. It's won't be the same for each job.
One is better suited for a job by a programmer with strengths in the language, under the right socio-economic conditions than the other. When you look at a specific job, chose the right tool for you and your budget. It's[sic] won't be the same for each job.
And be sure to take fries with your language of choice
I guess what we meant to say is: If you are confortable with a language and you can solve the problem with this language, use it. If you know only one or none of them, learn both so you can decide which will solve the problem most efficient so you can take the rest of the day off.
Truer words were never spoken crusader.I guess what we meant to say is: If you are comfortable with a language and you can solve the problem with this language, use it. If you know only one or none of them, learn both so you can decide which will solve the problem most efficient so you can take the rest of the day off.
nvoigt is right, every language has it's strengths and weaknesses (I don't know what Java's would be, but I'm sure it has one) and some are better suited to a job (or a programmer for that matter) than others.
In my opinion
C# is much simpler syntactically than C++. It is also designed to be a Rapid Application Development language - it's simply makes a lot of things easier for developers, letting them get code out the door faster. C# has no pointers in the C++ sense (although really everything is a pointer, but its hidden), and when you allocate memory (by calling the new keyword) you do not have to worry about when that memory will be de-allocated back to the operating system. This feature, known as garbage collection, is one of my favorite features because many C++ programmers spend days fixing bugs caused by memory leaks (when memory is not de-allocated).
C++ on the other hand is usually viewed as a higher performance language that is closer to the operating system. Some developers simply don't like the idea of not having "control" over everything that's happening.
The power of C++ and C# isn't in the languages themselves though, but in the C++ Standard Library and the Microsoft .NET Framework (for C#). These two 'libraries' provide many great features to both languages such as templates/generics, file system functions, mathematical functions etc. However the .NET Framework contains much more, such as Windows Forms, ASP.NET Web Forms, Web Services, Remoting, Reflection, XML support... a much longer list. That's my favorite thing about C# - nearly everything you could want to do is already there, you don't have to go looking for libraries.
I wrote some C# code to read a large (150MB) text file and extract any email addresses. A friend wrote the same thing in C++. We both optimized our code as much as we could, and his ended up about 8% faster than mine, mine taking 13 seconds to run, his taking around 12. Granted the speeds were no doubt impacted by our various levels of programming knowledge, but even if there was a 20% performance difference I don't think it would have impacted very much.
Now of course 20% could mean a lot in some circumstances like games or critical business systems. Sometimes the .NET Framework (weighing in at a hefty 20MB) is simply too big for things like embedded devices or older PC's. But in the work I primarily do (desktop applications), the cost of new RAM is around $50 for a 512MB stick, and I generally consider a 20MB runtime a very small drawback if it means I can finish the application and be much more certain it has a relatively low number of bugs in 6 months rather than 9.
However I always recommend for new programmers not to learn C#. A good solid grounding in C++ will give you an understanding of programming that you can apply to most any situation that may come up. If you never learn a lower level language like C# you will not appreciate any of the benefits it offers over ye olde languages, and you will (generally speaking) have less of an understanding of what goes on at the lower level and write more inefficient code.
I hope you can see by the examples I have given above that both languages have their relative merits (note: I am somewhat biased towards C#, though I do have at least a moderate understanding of C++ and programming in general). It's a bit like asking what’s better, a truck or a yacht. It all depends on your destination.
ISV owner Joel Spolsky wrote a good article entitled Back to Basics. You might like to have a read.
Edit: Another way to think about it:
C# allows you to get the job done quickly and done reasonably well. I believe Microsoft designed .NET to be used mostly by businesses.
C++ was designed to get the job done in the best possible way, in a reasonable amount of time. It is more general purpose than C#.
Using C# you can usually create a good solution in a shorter time frame, but it won't always be the Best Possible Solution. Using C++ you'll generally be able to get the Best Possible Solution, but it will generally take longer to do so (and lots more debugging).
Last edited by nickname_changed; 02-25-2005 at 08:26 AM.
And this is all assuming you're talking about ye olde C++, not Managed C++ (or "C++ .NET"). Otherwise the differences merely come down to Managed C++ programmers smelling because they never have time to wash because they're too busy typing cryptic syntax.