Java – Managed Coders vs Native Coders

javanet

I'm a coder and have experience with both native and managed code.
I started out with Pascal and C, then moved into C++ and eventually into C#.

Over the last year or so, I've been coding almost exclusively in C# and have lost a lot of what used to come naturally when I was a C++ coder.

A few weeks ago when I sat down to write some native C++ code, I found myself fumbling around as I slowly got re-acquainted with the complexities, quirks, and idiosyncrasies of it all. I'm almost embarrassed to say that I had completely forgotten that passing a dynamically allocated array to a function without also passing its size would mean that the receiving function would have no way of knowing how long the array is.

There are countless articles and documents which compare and contrast managed vs unmanaged code. We all know that native code, if well optimised, can run significantly faster and lighter than managed code. On the other hand, managed code has garbage collectors and run-time CPU-specific and OS-specific optimisation which can give native code a run for its money.

Purely from a technical perspective, there is no clear winner.

There is no doubt that managed code is orders of magnitude simpler to code and understand.
Just look at difference in the number of lines necessary to construct a simple GUI in Win32 C++ vs C#.

Back in my native-coding days, I mostly wrote mathematical simulations that ran on supercomputers. They had ugly CLIs and were mostly algorithm-focussed.
Nowadays I write in C# and produce beautiful GUI applications, but would be lost if I had to make something of a similar calibre on a native language. Even with a framework such as QT, it would still take twice as long to produce something in C++/QT than it would in C#.

Whenever I see someone who has written a large-scale, full-featured GUI application in C/C++, I can't help but feel a sense of awe and a hint of jealousy.

I'm curious how other experienced coders see managed and unmanaged languages.
Do you see managed code as amateur-ish? Do you see native coders as more hardcore?

Best Answer

My day job is currently in C++, but I've programmed in several languages long enough that I barely notice a difference anymore. Here are my observations:

  • A lot of the alleged inefficiencies with other languages are frequently reimplemented by C++ programmers as best practices. We add enough null checks, array bounds checking, type checking, input validation, etc. to largely negate any execution speed advantage gained by the language not automatically doing those things, at least for code that isn't data processing intensive.
  • That extra boilerplate becomes an ingrained habit after a while, so that it doesn't really feel like extra work, and sticks out like a sore thumb when it's missing.
  • When I program in a "managed" language I still think about memory allocation, so as to make sure I don't create a memory leak. I may not be putting an explicit delete, but I'm still aware in my mind of the point at which the garbage collector considers it eligible for deletion. I had more difficult to solve low memory issues starting out in Java than I ever did in C++, probably because in C++ they are much harder to ignore for very long.
  • Same goes for dynamic typing. I still have to keep track in my head of whether a function parameter is an array, or an int, or a string. In fact, it requires more mental effort because the type isn't plainly listed right there for me.
  • Modern C++ style is very different than the pre-C# era. Rather than the language changing, people "discovered" how to use existing C++ features in unique ways to avoid much of the menial memory management of the past. Design patterns that free memory automatically are very common now.
  • As far as I know, even though it's possible to make GUI applications by only writing code, graphical designers like QT designer are the vastly preferred method, with code mostly only used for event handlers or runtime customization.
  • Languages you haven't used extensively in a while always feel a little clumsy, even if you mostly remember the syntax. If I don't write python for a year, there are a lot of idiosyncrasies I have forgotten, and it feels more awkward than C++ for a while, even though objectively most people consider python the "easier" language.

With the combination of all those factors, my mental model stays fairly consistent between when I program in C++ and other languages, and the differences feel mostly merely syntactic. Granted, a lot of that is a result of training, habit, coding standards, and modern design patterns rather than features intrinsic to the C++ language itself, but the comparison still stands.

I guess what I'm trying to say is that in my experience the programmer's training makes a lot more difference than the language he is using.

Related Topic