27 posts in this topic

I have been programming C# for the last 6-7 years or so (yes so I?m one of the ?coffee based? coders as well), before that mostly C++. At the moment I'm at a crossroad, undecided if I should switch back to C++11. Why you say? At this point mainly because I need performance, but on a grander scale because my gut feeling has started to worry me that there might be some changes coming and that C++ could be the right choice for the future?

Let me pull back a little. At the moment I'm about to start on a pretty large project, and since the project will be ridden with heavy math calculations, and I know performance will be very important, I was a little hesitant just to jump out and start implementing in C# (as I normally do). To be honest I want to choose C#, but I'm afraid it's not the correct choice do to performance issues. C# and the.NET library is beautiful and a joy to work with, and there are countless of projects where customers have been stunned of how fast I was able to produce results. This was on the other hand almost never the case with C++. But this performance thingy is nagging me big time, I?m really afraid to choose the wrong environment and discover down the path that this was a failure. So I first started out on a googling mission to find performance comparisons, tech articles, blog posts about C++ and C# performance.

During this time there was also a lot of developer anxiety due to Microsoft?s poor public relation management prior to Windows 8 pre-release and the Build conference. You have probably read most of it yourselves. In general the feeling is that Microsoft is discontinuing (read: scrapping) Silverlight and XNA, and honestly the future of .NET as a first class citizen on WinRT is also questionable. Here are just two small articles exemplifying what I?m talking about:

http://www.guardian....oft-programming

http://channel9.msdn...all-of-a-sudden

But maybe more importantly, I watched some videos with Herb Sutter from Microsoft, where he talks about why he considers C++ being the right choice for the future. For instance he talks about the Microsoft Longhorn project and Microsoft?s efforts to make managed languages a core part of Windows, and how that failed. He also talks about how they now feel the new era is towards native development with the now ?new and shiny? C++11. Take a look at the video, it?s quite interesting:

http://channel9.msdn...rb-Sutter-Why-C

Also you could supplement with this article giving a historical background explanation of Microsoft?s path towards WinRT:

http://arstechnica.c...n-dream-reborn/

And finally this video where Herb talks about how he feels C++ is now closer to C# and the managed languages, and nothing like the old C++ from back in the days:

http://channel9.msdn...our-Father-s-C-

So, what do you guys think? I would love to hear comments on the videos and what do you guys consider for the future. Should we start the journey from C# and managed and venture over to this new shiny toy C++11? Is it the right choice? Will Microsoft silently and slowly stop focusing on managed development, stop improving the CLR performance, and focus more on native development?

On the other hand, my C++ skills are fairly rusty since it's almost 10 years since I programmed any big projects in it, and it's not entirely trivial to write a high performance program in C++. I guess there will be a somewhat steep learning curve coming back to C++11, and I need to take some of that on my free time and it?s going to be rough as well (at some point I remember swearing I?ll never go back :-) But I guess, if I decide to do it, it?s because I feel it might be the right thing to do at this point in preparation for the future. So what do you all think? All comments are welcome! Yes and on a side note, anybody know a good C++11 book?

Share this post


Link to post
Share on other sites

It seems like your main reason for switching is performance. You?re going to be more knowledgeable in the core functionality of your application; you should go check out some benchmarks or run some yourself to see what performance you can achieve in each. You?re going to have to weigh the cost of adding development time by having to relearning C++ vs. the performance you application will get in the switch. If development time is negligible, than even a modest performance gain might be worth the switch. If the application is needed ?right now?, it might be best to stick with what you know except in the most extreme case of performance.

By the way, thanks for the videos, I?ll have to check them out when I get some free time.

Share this post


Link to post
Share on other sites

I'm a C++ programmer by heart - actually using C++11 on a daily basis. If you don't want to switch completely to C++ (e.g. for UI [WPF?]), how about combining C# and C++/CLI? VS 2010 supports that combination - though there are some corner cases where C++/CLI will always be incompatbile to C++11 (e.g. the nullptr-thing)

Share this post


Link to post
Share on other sites

.NET is still a first-class citizen on Windows 8. The entire .NET stack is seeing major upgrades (much more than C++) in the next release which coincides with Windows 8. WinRT is not .NET, but it exposes its functionality using .NET metadata, so if anything the integration of .NET in Windows has made a huge step forward. The integration of new Windows libraries in .NET is much more seamless than it has been in Vista/7. C++, on the other hand, requires non-standard extensions (C++/CX) to make use of the WinRT types.

The future of certain technologies is indeed uncertain: XNA in particular, Silverlight also probably. But I think .NET as a whole will remain as relevant on Windows 8 at it has been on Windows 7. What can you suddenly do with C++ that you couldn't before? What can't you suddenly do with .NET that you could before? If it's about performance then the situation hasn't changed, only a tiny minority of code really benefits from going the C++ route - and then the added costs of development have to be weighed against the added value anyway.

We don't know the entire story behind the failure of the .NET rewrite of Windows (Longhorn); poor vision and management certainly had as much to do with it as .NET's inherent limitations. Also it was .NET 1.1 at the time, which was an early rushed-out version of the framework - it didn't even have generics and all the collection classes sucked. We're not talking about the same .NET in 2012.

Sutter is trying to present C++11 as something fundamentally different than C++98, and I disagree entirely. C++11 has all the same major flaws the language always had: header file management, absurd compilation time, cryptic compiler errors, poor tooling support, esoteric template language, poor, confusing and redundant standard libraries, brittle memory model, undecidable grammar, and I could go on.

In short I don't understand the hype around an old broken language that has been slowly but steadily on its way to niche status, just because it gets a few features other languages have had for years.

Share this post


Link to post
Share on other sites

C# and the.NET library is beautiful and a joy to work with, and there are countless of projects where customers have been stunned of how fast I was able to produce results. This was on the other hand almost never the case with C++.

Why would coding in C# be any faster? If you use libraries like Boost, C++ apps can be coded pretty fast provided you start out with a solid design.

Share this post


Link to post
Share on other sites

Microsoft has some working prototypes of fully managed OSs, some public ones (e.g. Singularity) and some internal ones (e.g. Midori, see http://webcache.googleusercontent.com/search?q=cache%3Ahttp%3A%2F%2Fwww.microsoft-careers.com%2Fjob%2FMountain-View-Software-Development-Engineer%2C-Senior-Startup-Business-Group-Job-CA-94035%2F1750562%2F&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:fr:unofficial&client=firefox-a ).

Apparently, they've also created a "language like C# that has the performance characteristics of C++" ( http://www.microsoft...-94035/1514399/ 2nd sentence of 2nd paragraph).

Their sudden love for C++ is a way to tell native developers they haven't forgotten C++ exists.

Share this post


Link to post
Share on other sites

That is an odd first post

Share this post


Link to post
Share on other sites

That is an odd first post

There's a reason for it.

Share this post


Link to post
Share on other sites
Yes and on a side note, anybody know a good C++11 book?

The latest (6th) edition of the C++ Primer Plus by Stephen Prata covers C++11.

Share this post


Link to post
Share on other sites

We don't know the entire story behind the failure of the .NET rewrite of Windows (Longhorn); poor vision and management certainly had as much to do with it as .NET's inherent limitations.

http://stackoverflow.com/a/7524710/983912 :)

Share this post


Link to post
Share on other sites

I've looked through the Wikipedia page on C++11. Many of the solutions to previous issues and limitations use whatever space is available in the syntax. For example, strongly typed enums are defined as "enum class" (or "enum struct"). The keyword, "using", may be used as an alternative to "typedef" in certain cases. It's a mess.

There are alternate languages available today, with Go, D, and perhaps Rust being the most popular. I'm personally an advocate for D, and it already has many of the features added to C++11 with a much more elegant syntax. I don't think it's time to reconsider C++, I think we're long overdue for a new language that does things right.

1 person likes this

Share this post


Link to post
Share on other sites

esoteric template language,

There's absolutely nothing esoteric about templates, maybe you should look up the definition of esoteric programming languages...

poor, confusing and redundant standard libraries

Funny to read that out of the mouth of a .NET supporter - name the redundancies in the C++ standard library than...

In short I don't understand the hype around an old broken language that has been slowly but steadily on its way to niche status, just because it gets a few features other languages have had for years.

Niche status? You do realize that almost everything sold by Microsoft (including Windows, Office, Visual Studio and so on) is written in C and C++?! Not to mention that the industry reinforces it's focus on C++ as "the free lunch" is over,,,

Share this post


Link to post
Share on other sites
Allow me to doubt the theory of Mr. "user480729" who has only one post on stackoverflow and when Larry Osterman, developer at Microsoft, calls it a conspiracy theory.

Share this post


Link to post
Share on other sites

what is a "coffee based coder"?

Share this post


Link to post
Share on other sites

Allow me to doubt the theory of Mr. "user480729" who has only one post on stackoverflow and when Larry Osterman, developer at Microsoft, calls it a conspiracy theory.

There are two possibilities with that post - either it's written with a lot of humor, or by someone who does not wish to be identified. Either way, it is an amusing read.

Share this post


Link to post
Share on other sites

Thank you all for all good advice, and comments. I guess I will take a peak into C++11 at least to evaluate a little more what the fuzz is all about. I guess some sort of combination would be the best choice, frontend in C#, back-end core algorithms in C++. I have done some benchmarks on my own and C# always comes out slower and sometimes significantly slower, even though I try to do all the tricks with unsafe etc. But I don't consider myself a performance guru, and I could be missing something. Operations I have tested is image filtering, mean filtering and such. It's a shame actually, in the beginning I believed if I just did all the small tricks (unsafe, i < array.Length etc) I could squeeze out more performance of C# and make it at least very close to C++ (of course not counting the startup time and JITing and such). But in my experience even simple C++ for loops is way better, no tricks (release code that is!). After doing my own small performance tests I started scanning the net for more on the matter, in case I was missing something, which finally ended up in this post.

Microsoft has some working prototypes of fully managed OSs, some public ones (e.g. Singularity) and some internal ones (e.g. Midori, see http://webcache.goog...lient=firefox-a ).

Apparently, they've also created a "language like C# that has the performance characteristics of C++" ( http://www.microsoft...-94035/1514399/ 2nd sentence of 2nd paragraph).

Their sudden love for C++ is a way to tell native developers they haven't forgotten C++ exists.

Interesting, C++ like performance is the only thing I'm missing from C#. One of the reason I wrote the post as well was my growing worry that Microsoft's new love for C++ would somehow reduce the effort put into significantly improving .NET performance (like for instance SIMD). Thanks for the heads up!

That is an odd first post

Maybe. My main reason for writing the post was to start a discussion about the future of C#, .NET and C++11 in light of the sudden outburst from Microsoft around C++. Since I'm also have personal reasons for considering a switch to C++11 (starting a big project with extreme performance requirements), I thought that was valuable information. It's not like I would consider switching to C++ if I was going to write a mainly GUI centric application, that would just be dumb. I was also eager to hear other posters opinions, especially I wanted to hear what Dr_Asik had to say, since I actually first posted this post as a comment to one of his blog post about C# being the future for Console development.

Why would coding in C# be any faster? If you use libraries like Boost, C++ apps can be coded pretty fast provided you start out with a solid design.

In my experience it's faster, but that?s not very objective I know :-) It?s also the responses I have got at several occasions from co-workers and customers, and Herb says so also in his videoes. I should probably add I code mostly GUI centric applications with rich interaction experiences. There might be a good chunk of libraries for C++ doing that a lot easier now (Qt or similar probably), but around 10 years ago when I started out with my transition via. VB 6.0 towards C# there was very little, at least that I knew of. I was coding MFC, oh horrible!

what is a "coffee based coder"?

It's what Herb Sutter calls you if you code managed languages. Take a look at the videoes ;-)

Share this post


Link to post
Share on other sites

There's absolutely nothing esoteric about templates, maybe you should look up the definition of esoteric programming languages...

The fact that the Turing-complete template metaprogramming language was an accident, not a design decision, and that the syntax and behavior are nothing like the rest of C++, break most compilers and cannot be understood by even most expert C++ programmers, makes it esoteric in my book.

Did you know that because templates are Turing-complete, it's impossible to determine whether a valid C++ program can be compiled without solving the halting problem - i.e. it's impossible?

Funny to read that out of the mouth of a .NET supporter - name the redundancies in the C++ standard library than...
Most of the C++SL is duplicate features from the C library which is also in the standard C++SL, to begin with...
Niche status? You do realize that almost everything sold by Microsoft (including Windows, Office, Visual Studio and so on) is written in C and C++?! Not to mention that the industry reinforces it's focus on C++ as "the free lunch" is over...
Demand for C++ developers has steadily been on the decline for more than a decade now. C++ remains relevant where significant C++ codebases already exist and the rewrite effort isn't worth it - which is case for most Microsoft products - or where the performance requirements really justify it, which is a minority of software given that you already get pretty damn good performance for a lot less effort with .NET.

As for the industry "reinforcing its focus on C++"... all I see is some Microsoft evangelists trumpeting C++11 like lambdas or very limited inference were equivalent to a re-birth.

Share this post


Link to post
Share on other sites

Since it might be of interest to others as well, here is some numbers from a quick performance test I performed. The problem was median filtering of an image:

(1) C++ AMP (same quick_select code as below just AMPified, included copying of data to the GPU)
? 1.4ms

(2) MATLAB (using medfilt2 with uint8 data, IPP acceleration)
? 4.4ms

(3) MATLAB .NET component called from C# code (including copying of data between programs)
? 5.1ms

(4) Python OpenCV medianBlur (I guess with IPP acceleration)
? 8ms

(5) C++ using quick_select instead of quicksort
? 298ms

(6) MATLAB (using the normal built in medfilt2 with double data)
- 399ms

(7) NumPy (4 for-loops)
- 533ms

(8) C# Parallel.For (same 4 for-loops as below)
- 865ms

(9) C++ (4 for-loops using quicksort)
- 997ms

(10) C# (4 for-loops using quicksort)
- 1129ms

(11) MATLAB (4 for-loops using quicksort)
? 5200ms

(12) Python (4 for-loops using quicksort)
- 16400ms

Share this post


Link to post
Share on other sites

Also, make sure your running benchmarks in a production-similar environment. OS/hardware can have an effect on these things, so make sure you?re targeting the actual machine this code is going to run on and not your development machine.

Share this post


Link to post
Share on other sites

It's what Herb Sutter calls you if you code managed languages. Take a look at the videoes ;-)

From what I remember he called Java and C# "coffee languages" (because Java = coffee), but he didn't call the programmers themselves "coffee-based coders".

Share this post


Link to post
Share on other sites

Since it might be of interest to others as well, here is some numbers from a quick performance test I performed. The problem was median filtering of an image:

(1) C++ AMP (same quick_select code as below just AMPified, included copying of data to the GPU)
? 1.4ms

(2) MATLAB (using medfilt2 with uint8 data, IPP acceleration)
? 4.4ms

(3) MATLAB .NET component called from C# code (including copying of data between programs)
? 5.1ms

(4) Python OpenCV medianBlur (I guess with IPP acceleration)
? 8ms

(5) C++ using quick_select instead of quicksort
? 298ms

(6) MATLAB (using the normal built in medfilt2 with double data)
- 399ms

(7) NumPy (4 for-loops)
- 533ms

(8) C# Parallel.For (same 4 for-loops as below)
- 865ms

(9) C++ (4 for-loops using quicksort)
- 997ms

(10) C# (4 for-loops using quicksort)
- 1129ms

(11) MATLAB (4 for-loops using quicksort)
? 5200ms

(12) Python (4 for-loops using quicksort)
- 16400ms

So this is orders of magnitude faster with GPU acceleration than without; it's about 3 times faster with QuickSelect than QuickSort; and using the same algorithm, it's about 10% slower in C# than C++. That seems about right.

Using WinRT it's easier than ever to call C++ components from C#, so since AMP is C++-only, typically you'd write the app in C# and call into the C++ AMP component if and when required.

Share this post


Link to post
Share on other sites

Yes, the C++ AMP results was insane :-) It was really easy to change the original code as well, only a couple of lines of the program had to be changed. GPU acceleration is way to go!

Will try out the mixing of C++ and C# in WinRT, haven't been experimenting much with Win8 programming just yet. Downloading VS 2012 preview as we speak...

Share this post


Link to post
Share on other sites

Nice try,

Bjarne.

2 people like this

Share this post


Link to post
Share on other sites

Well there is also web development with C#/ASP.NET (MVC) which is making great strides forward nowadays, so unless C++ becomes a web language, it's hard to see C# going away even if C++ somehow replaces C# in the desktop apps space. A mix may indeed be the best option. I hope XNA doesn't go away, I quite enjoy coding with it and it's an important component (only way to do graphics-intensive apps) for Windows Phone.

Share this post


Link to post
Share on other sites
I hope XNA doesn't go away, I quite enjoy coding with it and it's an important component (only way to do graphics-intensive apps) for Windows Phone.
Me neither. I'm totally ****ed at MS for not supporting XNA for Metro, and probably not working on another version of XNA at all. SharpDX, although great, is no replacement for a high-level, novice-friendly and cross-platform API.

In the meantime, however, the APIs are being reimplemented as the open-source project MonoGame, which supports every platform from Android to Metro, and is apparently quite popular already.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.