views:

1198

answers:

14

Freeing developers from dealing with memory management has been touted as one of the principal advantages of managed code languages such as C#. Are there any studies/real-world examples of actual productivity gains of developing commercial applications in C# vs. C++?

+8  A: 

I'm not sure if there are any studies, since the speed of development is largely influenced by many other factors like people's qualification, project managements, requirements change, internal politics etc. etc., but judging from my personal experience I can definitely say my productive rose tenfold.

It just gives you suddenly so much extra time when you don't have to worry about who's responsible for allocating and freeing memory withing a class, then between classes in a module, then between modules, then between applications, then how to implement this strategy in a consistent manner, then how to communicate it to all developers in a team or external contributors. You get lots of free time to implement useful functionality instead of still staying in the same place after many months trying to debug and clean up things.

Having said that I fell inclined to add that having a garbage collector does not excuse a developer from solid understanding of the low level operation of the CLR. An incompetent programmer without knowledge of value and reference types, of stack and heap management can still lay low an application in an innocent ignorance of the operational model.

Developer Art
Two years ago, a crack commando C++ programmer was sent to work in a cube farm by a manager for some code that he didn't commit. This man promptly escaped from a maximum security cubicle to the Stackoverflow underground. Today, still wanted by the management, he survives as a C# coder that is as productive as a small C++ team. If you have a problem, if no one else can help, and if you can find him, maybe you can hire... New in town.
rpg
So what proportion of your previous projects did you actually spend "worrying about who's responsible for allocating and freeing memory withing a class, then between classes in a module, then between modules, then between applications, then how to implement this strategy in a consistent manner, then how to communicate it to all developers in a team or external contributors."
frankster
@frankster: A noticeable time portion of those C++ projects where there was > 1 developer. More than one person => many perspectives on how to do it right, people have different background, you have to first "tune" them in, until that happens there are errors and strategy collisions inevitably.
Developer Art
+2  A: 

I can definitely say my productivity has increased without having to worry about unsafe structures in C++, but that's just my experience. I feel that C# is much easier to work with than C++, but I've never seen an actual study, just my own experience.

Scott Vercuski
+6  A: 

I would say that the productivity gains by using C# as a language is the fact that you are working on top of the .NET Framework. This is where I find you get to be able to develop solutions faster.

Pete Davis
+2  A: 

I find that the main gain is the tooling, being able to set a conditional break-point that compares string values is something that VisualStudio still fails to do for C++ (even though dbx has supported it for ages). The reduced compile times help too.

Motti
A: 

I don't know about any studies, but from my experience, writing C# code is much faster. And memory management is not the only thing that speeds it up. In C# a lot of good things that make development faster:

  • convenient iterating (foreach)
  • standard string type
  • standard string formatting
  • built in conversions string<->numberic types
  • reflection (no problem to create good object factory)
  • enums that are easy to iterate, convert to string and vice versa
  • built in analogs of boost::function and boost::signal that are easy to write, support and debug
  • convenient lambda that helps to exploit algorithms

List is very long.

bocco
std::for_each in C++, std::string in C++. I'll give you lambda and reflection, though lambda's ae available in boost and C++0X
Glen
Yes, I know, but I personally have to deal with at least 4 types: CString, BSTR, const char*, std::string :(I like Boost as it makes my life easier. But I hate to debug boost::function/signal (due to messy call-stack) and I still cannot write boost::lambda as it looks unnatural to me and pretty hard to modify/support. It is still much easier to write loop or functor in production code.
bocco
+11  A: 

In my personal experience, automatic memory management has not really been a big factor. These days, there are a number of simple constructs in C++, like reference counted pointers, that can be used in the majority of cases to abstract memory management away. In fact, I would argue that it's more difficult in C# as it's sometimes very important to call Dispose on objects that implement IDisposable, but it's not always immediately obvious which objects are IDisposable.

On the other hand, I have benefited from C#'s other useful features. Things like events, the ability to alter my code in the debugger, using Designer (when it works) to set up a GUI, and "it just works" interoperation with native libraries (P/Invoke) or C++ code (C++/CLR) have made my life much easier.

Eric
+30  A: 

I've been a C++ programmer for several years and now I'm a full-time C# programmer. To be totally honest, I don't think having automated memory management really makes me that much more productive because once you get use to it, it's really not such a big deal.

To me, the main productivity gain in C# is the .NET framework library and visual studio integration. The fact that intellisense actually works, able to using runtime reflection and having good date/time library really saves me a lot of time.

oykuo
+1 that's pretty much what i was going to say but you beat me to it.
markh44
+1 that's the main productivity gain by far.
Daniel Daranas
another +1 for the same reasons :)
peterchen
true. There are corner cases where the GC is a convenient (cyclic references), but in general, it's not a big deal for a C++ programmer who knows what he's doing. Of course it's probably a big productivity booster for new programmers though, in easing the learning curve.
jalf
I agree with jalf, though I'd use the term "poorly skilled" in place of "new".
gbjbaanb
+1 I agree, I didn't consider the IDE when I made my reply and you're right, the intellisense, MSDN help and other features really do make development quicker and more uniform.
Scott Vercuski
For intellisense there's Visual Assist. The framework is hard to beat, although boost comes in pretty handy.
sbi
I agree as well. In fact, when I first started coding in C#, I actually felt like I was being bad. Not thinking about memory is a cardinal sin, right? I spent more time testing just to be sure that I wasn't making a mess of things. Those feelings eventually passed, and I got back up to normal productivity. I still love C++ best of all though. C# brings a lot to the table simply for the fact that it's packed with tons of extra goodies, but the language itself is nothing special. Not bad, but not groundbreaking either.
Casey K.
+1 I fully agree, and then I start wondering: was it a good thing that yet another language was created with no big improvements over C++?
Dimitri C.
+1 for same thoughts. Been a C++ developer for 5 years now, and I seriously have to say that Java and C# allow me to program *much* faster. Just because I dont have to *think* about what library I'm going to use for common tasks.
ShaChris23
+6  A: 

I don't know about studies. However, in my experience memory management in C++ is a negligible problem if you use common idioms such as RAII. In my opinion, the much more important productivity boost in C# comes from assisting tools. For example, there are no refactoring tools for C++ that really deal with all the constructs the language allows. In C#, Visual Studio already provides some nice tools, but Resharper is what I miss most in Visual C++. It's not that different in other C++ IDEs, since C++ is really hard to parse.

So if you compare productivity, also consider these effects. Adding the Boehm garbage collector to C++ might bring it to the same level as C#.

Malte Clasen
VisualAssistX works well for C++
Dmitriy
+5  A: 

I would not trusat studies like that anyway. They all have som agenda they want to prove and the parameters can always be modified to support any result.
The comparisons with memory management is most likely based C# vs C or C with classes. Most current C++ project uses smart pointers and then memory is as easy as in memory managed languages(altough a little more syntactiucally verbose) The main productivity gain for C# is not in memory management but in its Visual studio integration.

I have been in several big projects in both C++ and C# but contrary to most of the other posters in this thread, my experience is that once the project has matured, C++ has better productivity than C#. This is mainly due to its better abstraction abilities, where you can hide more into libraries and remove more boilerplate code.

A: 

From my point of view C# seems to be far more intuitive and contains a lot of functionality which C++ implements using 3rd party libraries such as Boost. Please note that not all C++ IDEs contain intellisense or something related to it while C#'s native IDE (MS VS) has it - and I must say it speeds up coding tremendously.

Also, C# 3.0 has got LINQ which seems to be an extremely convenient way of accessing data sources such as MS SQL Server, XML , CLR objects, regular arrays Lists Dictionaries etc.

From what I've been told C# 4.0 is going to implement additional data sources such as IBM's DB2, Oracle etc.

It's also worth saying that C# language itself is being developed more rapidly then C++ is, but the reason for that is pretty obvious.

Best regards

Maciek
considering MS are deprecating OracleClient in .NET 4, I hold no hope that they'll somehow decide to support it or DB2: http://reddevnews.com/Articles/2009/06/16/Microsoft-Kills-Oracle-Data-Provider-for-ADONET.aspx
gbjbaanb
Your functionality argument is exactly what I dislike about C#: whereas you can add functionality to C++ through libraries, even to the point of creating DSLs (see LuaBind or Boost.Spirit), in C# the actual language is revised again and again, adding ever more bloat to it.
Cygon
Everybody is entitled to their opinion I suppose.
Maciek
+6  A: 

I'd be interested to hear from anyone with experience in both .NET and a good C++ library like Qt. I've not touched .NET for more than a few hours, but I'm loving Qt - the productivity gains over MFC, GTK, and wxWidgets is, IMO massive.

I've seen similar questions all over stackoverflow. Many people end up comparing the C++ language with C# language bundled with the .NET framework, which is clearly nonsensical. It's an easy mistake to make, since the two are often bundled together.

I'd also agree with Eric - automatic memory management isn't that big a deal for experienced programmers.

Thomi
IMO, Qt made C++ into a new language
Lawand
yep - I'm hooked on Qt.
Thomi
+1 I totally agree. However, I think having a big standard library is a big plus indeed.
Dimitri C.
Yes, I totally agree, but I think it's important not to confuse the library with the language.
Thomi
A: 

I too believe its the Visual Studio integration. It's one of the most powerful IDEs available in the market right now. The productivity can be increased further with use of tools like Resharper, CodeRush, AnkhSVN etc . It's awesome to see what these tools can do for u. Definitely got my productivity up.

Amol
+2  A: 

I've been using C++ for several years before switching to C#. My C++ knowledge includes Boost, Loki, libsigc++ and of course the SC++L.

I don't think memory management was ever an issue in C++, productivity-wise. Any programmer worth his salt has a clear concept of ownership for any object and smart pointers made it effortless to work with shared objects.

If I had to choose between automatic garbage collection and deterministic finalization, it would be a hard choice. Both have their advantages. Garbage collection allows for lightning fast heap allocation and solves the problem of heap fragmentation. Deterministic finalization nearly eliminates the risk of unreleased resources and allows for ad-hoc RAII (see ScopeGuard).

What makes me more productive in C# is its reflection capabilities. This allows for agile development practices like unit testing and test coverage measurement, which are rather inconvenient to wield in C++. Using dependency injection in C++ is almost impossible, for example, and requires a lot of boilerplate code.

I also adopted a higher-level mindset in C#. I'm worrying more about object interactions than about how to best turn an algorithm into code. I can't say whether this is a natural progression or whether its due to .NET, but I feel the simpler programming model allows me to concentrate on algorithmic efficiency and less about implementation details.

Cygon
I agree with you. I will say this, C# libraries when found to be buggy are hard equally a time waster.
Eric M
+3  A: 

Having worked a lot with both languages, I can confirm that GC is not a profuctivity booster. Any productivity gains I saw with C# were due to the rich .NET Framework support in the areas such as database access and XML processing.

Nemanja Trifunovic