tags:

views:

710

answers:

15

Can someone describe what advantages a C or C++ programmer would have over a .Net programming when developing for Windows?

+10  A: 

You should learn enough C to be comfortable with the native Windows API, as it's quite handy when writing complicated UI and when interacting with the system.

SLaks
I don't know c or c++, but I find its fairly easy to look up function Win32 API function definitions on Msdn and use them from .NET code.
Samuel
you don't really need to know C or C++, just how to convert between datatypes for API signatures....
Mitch Wheat
Yes, but you need to understand C's memory model if you don't want to leak memory.
SLaks
+3  A: 

Although I have committed to only programming in .NET from now on, I know there will be cases where I must use interop to use third party libraries, and will likely also need to be able to dig through their code to fix bugs.

Dave
+3  A: 

To be honest, it's only really going to be of use when you need to access the Win32 API, but most of those signatures are available online (such as pinvoke.net), and every new version of the .NET framework includes more wrappers for commonly used Win32 API calls.

Having C/C++ knowledge is worthwhile in the bigger scheme of things, but if you are not using it everyday, you lose the knowledge quickly!

Mitch Wheat
A: 

You might want to learn C++/CLI if you plan on doing any non-trivial interop.

Matt Olenik
+28  A: 

There's a saying that every sufficiently complex C application ultimately ends up reimplementing parts of C++. The same goes with C++ programs and higher languages. Learning C and C++ will indirectly make you a better programmer by helping you gain a deeper understanding of how .Net actually works, and why the designers made the choices they made.

A programmer is only as good as his understanding of the layers beneath him. .Net does a pretty good job of abstracting a lot of machine architecture issues out of view, but it's not perfect. There are still leaks in the abstraction layer where an understanding of lower-level issues will help you make good decisions at the .Net layer.

A short, incomplete list of these issues includes:

  1. Interop with native code, especially with the Windows API
  2. CPU cache coherency (if you don't believe me, google the slides from the PLINQ presentation at PDC '09)
  3. Value type performance vs. Reference type performance (this is firmly footed in the .Net world, but learning C/C++ makes the differences between stack and heap allocations more explicit in some ways).
  4. Kernel scheduling issues (i.e. why it's a bad idea to spin off 1000 threads)
  5. Understanding the garbage collector is also best achieved by writing a few memory management schemes in non-garbage collected languages.
Kennet Belenky
+1 for this: "A programmer is only as good as his understanding of the layers beneath him." I like that.
cschol
@cschol Thanks, I'm pretty sure I stole it from somewhere, probably not verbatim, and I couldn't say where from.
Kennet Belenky
Don't just look at the slides from the PLINQ presentation; watch the video, too.
Gabe
Should you stop at the C layer or go further? :)
pug
never hurts to dig down to the metal. A good understanding of assembly, even knowing what the machine code is doing wouldn't hurt. That said, if all you're writing is business applications, you'll probably never need to go that far.
David
+5  A: 

It's good to know your roots.

Managed languages are great, but they might just be a huge fad. Who knows what the next year will bring? The pragmatic programmer knows a variety of languages and learns at least one new language every year. You can take the patterns you learn from other languages into your primary one, which makes you more versatile. Learning more than one or two languages helps you reduce computer science down to core algorithms, rather than a collection of syntactical fixes. And if one day your boss asks "Do we have anyone who knows ___?", you can step up to the plate. If you don't know the language, then you're better cut out to learn it, because you have done it so many times before.

Besides, learning languages is fun! C++, Python, Ruby, Scheme, Haskell, Javascript and whatever else interests you. There are about a million! Learn something non-imperative like SQL or Erlang. Learn a scripting language like Lua or PowerShell. Try a data-flow language. I know that when I learned Scheme, I became a better programmer in every other language I worked with. Haskell and OCamL had similar effects. Also, Scala has been fun.

Travis Gockel
+2  A: 

Others have covered the necessity of Windows API interaction, but I also find fault with the assumption that you can guarantee (or that you'd necessarily want to be limited to) .NET development for the rest of your career.

.NET is an excellent framework, but it's very unlikely that it'll be the last. And, as good as it is, it's not the best choice for every project.

Learning the basics - and I would consider C/C++ essential basics - opens the way for any number of paths, including .NET and whatever the Next Great Framework is.

overslacked
+4  A: 

Just a few that occur to me right off:

  1. Speed.
  2. Portability.
  3. Avoid .NET installation.
  4. Depending on what kinds of things you're doing, C++ can be more productive.
  5. You never have to debate whether your dentist is more painful that P/Invoke.
Jerry Coffin
+1  A: 

Understanding C and C++ really make you appreciate .NET more and be more careful and aware of object responsibility, memory management and performance concept. You will have more feel to what may happen under the hood when you call a method in the framework and it just does the work for yo u.

Some parallel programming to maximize the power of hardware like multicore CPU and GPU are still more restricted to lower level language like C/C++. To choose one to learn now, I will do C++. C++ is the successor of C and have more advance and modern concepts built into it. I personally learn C++ and finding that switching and work in complex C environment was pretty easy.

Fadrian Sudaman
+1  A: 

If you're a .Net Windows programmer who wants to work at Google someday (aren't we all?), then it would help to learn C++.

MusiGenesis
Reference? I find this hard to believe. Does Google have any .Net programmers?
prestomation
Google has Python programmers, Java programmers, C++ programmers, and even .Net programmers (Orkut is ASPX). No doubt they have people who work in other languages also.
Gabe
(no, we aren't)
ima
According to something I read on Google a while back (I can't find it anymore), all (or most) of Google's in-house work is done in C++. They hire programmers from other languages, but presumably the assumption is that they will learn C++.
MusiGenesis
@prestomation, Jon Skeet is at google isn't he?
kenny
@kenny: I doubt he *really* works at Google - they have pretty strict hiring standards. :)
MusiGenesis
@MusiGenesis, yeah that makes sense anyone with that high an SO score would get booted. ;)
kenny
A: 

C++ has better libraries for many less common tasks. Math-related, especially, where it gets big advantage from access to SSE and some other processor-specific optimizations. There are many protocols and standards based on C++, COM isn't going anywhere soon - and complex interop requires even more esoteric knowledge than just writing C++.

C++ is heading into obsoleteness, but the road will be long.

Concerning general performance - while it is possible to write faster C++ code than .NET equivalent, most C++ programs are not and a many are actually slower.

And to "understanding basics" answers... choose a language without template meta-programming for that. Please.

ima
+1  A: 

.NET is great for server side projects, but usage of .NET for client side code (WinForm applications or Windows services) might not be appopriate in all cases. .NET has a large runtime, occupies significant amount of memory and takes considerable time to load. Therefore if your application or service is not the primary instrument for the end user (e.g. backup software), .NET might not be the best choice.

Vladimir Lifliand
so what is your alternative for winform? MFC? I thought that's one of the biggest reason in favour of .NET!!
Fakrudeen
I prefer ATL/WTL to MFC. Alternatively a UI can be built as a browser control hosting DHTMLs. But not all software is UI...
Vladimir Lifliand
A: 

C++ is often safer because of its automatic resource management. The performance difference (in favor of C++) doesn't usually matter but memory usage actually might (GC wastes a lot of RAM).

Tronic
I would disagree with you claim that GC wastes RAM. There are reasonable scenarios where a GC environment will succeeds where C++'s standard allocation scheme will fail. If you have a pattern of allocation and deallocation that leaves your heap highly fragmented, sparsely populated but with no contiguous large blocks, a subsequent large malloc will fail. GC has the freedom to move allocated around which would allow at-need defragmentation. Second, GC only leaves orphaned objects on the heap when it's not worth the bother to clean them up. In other words, it only wastes memory it doesn't need.
Kennet Belenky
The GC uses memory that other processes or the OS VM system (filesystem caches etc) could use better. While memory fragmentation is a very serious problem and while some languages do allow moving data around to prevent fragmentation, this doesn't generally outweigh the loss of memory by lazy collection. In the situations that you describe - frequent allocation and deallocation - this problem becomes particularly bad. Making the collection more frequent avoids the memory loss, but also has a great performance impact.
Tronic
A: 

My understanding is .NET is a foundation to support programming languages, and is of itself, not a language. There is Visual Basic .NET, Visual C .NET, etc.

I suggest continuing with C and C++ as you will never know when .NET will be replaced with another technology. So far, C and C++ are slow to change and require a consortium to approve changes to the language. You could also not limit yourself and learn other useful languages such as Java, Perl, PHP and LISP. I highly suggest LISP as it is completely different than C or C++ and will enlighten you.

Thomas Matthews
A: 

If you ever want to be more than a 1-trick pony, learn C and C++.

Windows will go away one day, because that's what happens to corporations and products. Perhaps we will get Skylights instead from Microsoft, and .NET is reformed into a different thing - .NEW. (whatever you want to call it).

Where is your .NET then? It's gone, as is your expertise's generality- you've become the next generation of COBOL programmer, a legacy-only programmer.

The only way to be able to stay on top of the curve is to know the principles of everything from assembly to SQL.

But that's then. What about now? You gain the ability to program triple-A games for Windows, to be able to write drivers for Windows, to be able to understand the kernel-level world of Windows, to be able to understand the details of security flaws for Windows, to be able to maintain old applications for Windows, to be able to be hired for firms that use C++.

And those reasons - IMO - are enough.

Paul Nathan