ajl
ajl

Reputation: 714

Is there any reason a .Net windows programmer needs to learn C or C++ anymore?

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

Upvotes: 19

Views: 1128

Answers (14)

Kennet Belenky
Kennet Belenky

Reputation: 2753

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.

Upvotes: 29

Paul Nathan
Paul Nathan

Reputation: 40309

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.

Upvotes: 0

Thomas Matthews
Thomas Matthews

Reputation: 57688

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.

Upvotes: 0

Tronic
Tronic

Reputation: 10430

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).

Upvotes: -1

MusiGenesis
MusiGenesis

Reputation: 75296

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++.

Upvotes: 1

Vlad Lifliand
Vlad Lifliand

Reputation: 468

.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.

Upvotes: 1

ima
ima

Reputation: 8265

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.

Upvotes: 0

Fadrian Sudaman
Fadrian Sudaman

Reputation: 6465

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.

Upvotes: 1

Jerry Coffin
Jerry Coffin

Reputation: 490108

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.

Upvotes: 4

overslacked
overslacked

Reputation: 4137

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.

Upvotes: 2

Matthew Olenik
Matthew Olenik

Reputation: 3577

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

Upvotes: 0

Mitch Wheat
Mitch Wheat

Reputation: 300549

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!

Upvotes: 3

Dave
Dave

Reputation: 15016

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.

Upvotes: 3

SLaks
SLaks

Reputation: 887413

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.

Upvotes: 9

Related Questions