21

Possible Duplicate:
What does the latest “C++ Renaissance” mean?

Lately, I hear a lot about C++ Renaissance. What is that?

C++ is currently undergoing a renaissance. This means that, by definition, the language, compilers and compositional tooling are evolving and coalescing into a state that maximizes native developer efficiency, productivity, and creativity across hardware and software domains.

I agree that C++ needs a lot of improvements, mainly, because it was updated in Neolithic Age (98,03). What really bugs me is the Build conf. They've showed a few metro style apps written in C++ and XAML - like RSS reader or Piano.

I have a feeling that C++ is an overkill for this kind of apps and only case when I see the advantage is battery power, but is it true? C# as well as C++ calls WinRT which is native and C# has only tiny runtime overhead.

Can someone provide case study or hard data where use C++ in windows 8?

I think it will be status quo (games, servers, OSes, databases, apps like Photoshop will be C++ and other client apps run .Net) and renaissance is just a marketing slogan.

8
  • 4
    From what I saw, I think they were showing C++/CLR, which is NOT a C++. It's not a C++03 or C++11.
    – Coder
    Sep 29, 2011 at 10:42
  • The showed Visual C++ with c++11 syntax and features, hence it was c++11 Sep 29, 2011 at 10:59
  • 4
    @Coder, C++/CX is an extension of C++11. (I'm not sure what do you mean by C++/CLR, C++/CX is not the .Net-based C++/CLI, if that's what you meant.)
    – svick
    Sep 29, 2011 at 11:16
  • 2
    @Coder, it uses the same syntax as C++/CLI, but it's not C++/CLI and it means something different. Specifically, it doesn't mean “an object in managed memory that uses .Net GC”, but “WinRT object that uses automatic reference-counting”. It's similar to CComPtr<T> with a built-in syntax.
    – svick
    Sep 29, 2011 at 11:34
  • 14
    You are expecting case studies to confirm your bias on an operating system that's not officially out yet for a language you don't like? Sep 29, 2011 at 12:08

6 Answers 6

31

I believe that every senior programmer / architect should watch Herb Sutter's presentation at C++ and Beyond 2011.

Basically, he claims that .NET and Java indeed offer better productivity. However productivity is not all. Battery power and performance are becoming more important for hand-held devices. For big-data server-farms, if you can squeeze your processing to 1000 cores instead of 2000 cores - you'll save more money on energy and maintenance than the money you'll lose on the extra programming hours.

So both for small and large systems - productivity is not everything, and even not the most important factor. When it comes down to processing power and battery power - C++ wins.

The new C++ standard offers extra productivity, without sacrificing performance. It shifts the balance even more.

16
  • 2
    I watched it and I do agree but my concert is about Metro app for Windows 8 Sep 29, 2011 at 10:27
  • 6
    @lukas: Well, the thing is, I think even Microsoft has no clue where they are going. We now have Win32, WinForms, Silverlight, now Metro, MFC, MFC-Ribbon, Win7/Vista dialogs. IMHO it's a mess, and all of this is supported.
    – Coder
    Sep 29, 2011 at 10:45
  • 1
    Yes, but they know it. For example they made .Net profile for metro apps. It is cleaned-up .Net (half of all classes) Sep 29, 2011 at 11:12
  • 6
    @lukas: You have any hope that Metro profile won't be deprecated like WinForms or Silverlight after two years? I don't. The problem is that you have to develop for mass market, which includes XP, and by the time XP is out of the market, Metro will most likely be deprecated as well. That's the reason I still like pure Win32, at least it's equally supported, allows anything (not without extra work), and is not going to go away in a near future.
    – Coder
    Sep 29, 2011 at 11:30
  • 4
    @hotpaw2: There is no condition in which C can run faster or with less memory than C++. If you don't want to use exceptions/etc in C++, nobody is forcing you to.
    – DeadMG
    Sep 29, 2011 at 19:38
17

I agree that C++ needs a lot of improvements, mainly, because it was updated in Neolithic Age (99).

C++ was never updated in 99. The first C++ Standard was 98. And then another one in 2003. And a new one has just come out this year. That's not exactly neolithic. More importantly, it's worth noticing that programming techniques that C++ had since well before 98 have, relatively speaking, only just come into .NET languages, like generics and functional APIs. C++ has had templates for vastly longer than generics have existed in C# - and generics aren't even as powerful as templates. Arguably, it's C# that's playing catchup, decades later.

I have a feeling that C++ is an overkill for this kind of apps

Overkill how? Apart from the idea that some people might prefer C++ for subjective reasons (which I could give a dozen of if you're interested), plus the fact that it doesn't require a 100MB install to get running on a consumer's computer, for example, or works on many more platforms than C#.

And C#'s runtime overhead is not tiny. At all. In fact, the smaller the app, the greater the proportion of time is spent just loading up the CLR.

As far as I can tell, the fundamental problem is that Microsoft has two divisions - WinDiv and DevDiv, I believe.

WinDiv can't be bothered and feels compelled to lump C++ in with another language- first it was C with the Win32 API, and now it's C# with the Metro APIs, which are C++ APIs only in the sense that technically, they're compiled by a C++ compiler and actually have very little in common with a C++ design. In addition, WinDiv doesn't learn from their mistakes- for example, even in the new Metro APIs, you can't mix Metro controls and DirectX rendering. Seems to be the kind of thing you would have fixed after the airspace problems with the previous generation of native controls.

DevDiv on the other hand seems to actually know wtf they're doing, for example, see the Concurrency runtime in Visual Studio 2010 and C++ AMP in vNext, which are awesome. They also produce some pretty sweet tools- the IDE improvements for C++ in vNext are quite good, and AMP is a big deal, even if unfortunately, that means few new C++11 features.

The problem is that WinDiv produces a lot more content than DevDiv, for example, sockets and UI libraries. So there is a C++ renaissance- it just only applies to the stuff that the unfortunately tiny DevDiv library team managed to paste over the WinDiv stuff.

11
  • 5
    ah ye it was 98, "it's C# that's playing catchup" it catch-uped in 2005, now it C++ trying to catchup with lambdas etc. it was 100MB, now client profile is 30MB and it is not possible to get windows-8 without metro .Net profile which I believe is a tiny bigger than SL plugin (8MB?). "you can't mix Metro controls and DX rendering" They don't want ppl to mix 3D with Metro, metro is not 3d. But they see this problem, for example in WP7 7.5 you can mix SL with XNA in one app. We can argue about .Net starup, assemblies or Jitterfor AMR. I don't care I care about Metro apps and some hard data Sep 29, 2011 at 11:09
  • 3
    -1: "C++ has had templates for vastly longer than generics have existed". Actually generics (aka parametric polymorphism) were invented in the 1970s as part of ML. Not uncoincidentally, one of the two guys behind .NET generics went on to do F# (an ML). See "A theory of type polymorphism in programming (1978)": citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.67.5276
    – J D
    Jan 14, 2012 at 12:06
  • 3
    @JonHarrop: Generics in ML are utterly irrelevant in a question comparing C# to C++. I obviously meant "Generics in the one of the only two relevant languages which have a language feature with that name", most of which is kind of implied.
    – DeadMG
    Jan 14, 2012 at 14:15
  • 2
    @DeadMG: "Generics in ML are utterly irrelevant". Your original statement that I quoted is totally factually incorrect. Your new statement that C++ had templates before C# had generics is true but hardly interesting given that C++ predates C#.
    – J D
    Jan 14, 2012 at 17:08
  • 7
    @JonHarrop: Considering that the question compares C# to C++, then that is the only statement at hand. Random feature X which may or may not have a similar specification/purpose/effect in random language Y with the same name is not under discussion. And since the OP is trying to suggest that C# is catching up to C++, then he has invited that comparison.
    – DeadMG
    Jan 24, 2012 at 4:24
6

C++ is starting to see some more importance on server side applications. Efficiently using the processor saves millions in server costs. If your app runs 7 times slower then you need to buy 7 times the servers, 7 times the cooling costs, 7 times the floor space, etc. Facebook started using some C++ for this reason. Google uses many languages, but their core is C++. If you expect massive load, your life can be made much easier if you use a native implementation from the start.

People seem to think garbage collection is what makes development easier. In my experience it's not, especially when your code is holding external resources. The C++ model of destructor clean up is cleaner and more modern than the Java model.

Consider this java psuedo code:

public void someMethod()
{      
        FileObj f = null;
        try
        {
          f = new File("/somePath/myFile.txt");
          String str = f.read();
          System.out.println(str);
        }
        catch(CustomException ce) { /*la */ throw ce; }
        catch(PathNotFoundException pe) { /*la */ throw pe; }
        catch(Exception e) { /*la */ throw e; }
        finally
        {
            try { if(f !=null) f.close(); } 
            catch(Exception e) { /*la */ throw e; }
        }
}

In C++ you could so something just as safe, without so much bloat. Just one line of code with all the saftey of the pseudo code above.

void someFunction()
{
   FileObj f("/somePath/myFile.txt");
   string str = f.read();
   cout << str;
   //the file is magically closed even if an exception occurs during f.read();
}

Edit: Changing pusedo-code methods from "main" to "someMethod".
Edit: Re-throwing exception in java pseudo code to make it equivalent to the C++.
Edit: Re-naming File to FileObj so psuedo code is not confused with real java libraries.

9
  • 2
    -1 Not that I like Java but public static void main() throws Exception gets rid of try, catch and finally in your example
    – gnat
    Jan 24, 2012 at 6:16
  • 2
    but new version of java got this feature docs.oracle.com/javase/tutorial/essential/exceptions/… Jan 24, 2012 at 10:45
  • 3
    @gnat. You can't remove the try/catch if you want the file closed in the event of an exception. However with the C++ destructor you can make that guarantee without try/catch. With stack allocation your classes are much harder for novices to misuse even if they grab shared external resources. Now +1 me!!!
    – Lord Tydus
    Jan 24, 2012 at 23:21
  • 1
    Your code snippets aren't equivalent: Java snippet is explicit about error handling while the C/C++ snippet hides all the necessary error handling in "do stuff" (or outside the function if the ctor can throw). Jan 24, 2012 at 23:55
  • @lukas. Looks like Oracle is doing something right with java. But it doesn't quite match the safety of a destructor. Remembering to create the java object in a block is the same as remembering to have catch handling. It's a sweeter syntax but the onus to remember still exists with the heap allocation. What if it's a custom made class and you aren't aware you need to explictly dispose it? With the C++ destructor your free to careless forget and your still safe.
    – Lord Tydus
    Jan 24, 2012 at 23:56
4

Of course it is a marketing slogan, but it shows that Microsoft is (again) committed to support native code as a first class citizen on the new platform.

Whether it is of any interest to you personally, that is another question - if you prefer some other language and it does the job for you, feel free to ignore the "C++ Renaissance".

1
  • Microsoft should fully support native code, native code will always have a place, because in some situations its your only choice. Microsoft cannot extend .NET to every single platform that comes out, so the only choice is to use native code in those situations, and use frameworks like MonoTouch to use common code.
    – Ramhound
    Sep 29, 2011 at 18:27
4

It's also C++ is portable. You can write a C++ app in windows move it to Mac/Linux/Android/iOS albeit with some fiddling. Although this probably isn't an angle MS is interested in.

When windows was the only game in town then C# was safe to use.

There are other alternatives Java/Python etc. They all come with a run time and so take some time to port to the new environment and as all these new platforms are coming then native is safer.

Also C++ (and C) are the only ones that have multiple compilers from multiple vendors - so you are safe that no one is going to change the rules - Oracle with java, MS with C# etc.

So if you're writing an app and you want to move it to different platforms then C++ is a very safe choice.

2
  • 1
    "Although this probably isn't an angle MS is interested in". I think Microsoft are very interested in that for advertising but what they'll actually do is coerce developers into adopting their own proprietary dialect of C++.
    – J D
    Jan 14, 2012 at 17:10
  • WinRT is definitely not portable. Jan 23, 2012 at 21:57
3

Can someone provide case study or hard data where use C++ in windows 8?

Well, the OS is written in C++.

The quick answer is that nobody with half a brain wants to design a commercial app that runs 10x slower and drains more battery than competing apps.

Not the answer you're looking for? Browse other questions tagged or ask your own question.