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.

Lukasz Madon
  • 1,496
  • 13
  • 22
  • 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 '11 at 10:42
  • The showed Visual C++ with c++11 syntax and features, hence it was c++11 – Lukasz Madon Sep 29 '11 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 '11 at 11:16
  • @svick: At least this presentation - http://channel9.msdn.com/Events/BUILD/BUILD2011/PLAT-874T was full of String^... – Coder Sep 29 '11 at 11:25
  • 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` with a built-in syntax. – svick Sep 29 '11 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? – Joris Timmermans Sep 29 '11 at 12:08
  • @MadKeithV I don't mind C++, case studies is a big word. If Microsoft invests millions to WinRT and shows C++ apps all day long, I bet there is compelling reason. – Lukasz Madon Sep 29 '11 at 13:00
  • "case study or hard data where use C++ in windows 8?"? How many Windows 8 developers do you think there are right now? How many third-party Windows 8 apps are available right now? Wouldn't it be a little more useful to wait until the OS is actually out? – David Thornley Sep 29 '11 at 20:00

6 Answers6

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.

Lior Kogan
  • 1,467
  • 12
  • 12
  • 2
    I watched it and I do agree but my concert is about Metro app for Windows 8 – Lukasz Madon Sep 29 '11 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 '11 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) – Lukasz Madon Sep 29 '11 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 '11 at 11:30
  • "Silverlight after two years" comon who says it is deprecated? What can run on phone, browser, desktop? – Lukasz Madon Sep 29 '11 at 11:38
  • @lukas: From what I understand you will need to redevelop Silverlight apps for Metro. The same goes with .NET, and you'll have to port all apps to ARM as well. Where only Metro will be supported. – Coder Sep 29 '11 at 11:42
  • This is not true, all apps will be still suported, but Silverlight won't use WinRT. – Lukasz Madon Sep 29 '11 at 11:49
  • @lukas: Only on desktop versions x86/amd64, but not on ARM? – Coder Sep 29 '11 at 12:03
  • Of course, for the lowest power and small memory footprint apps, plain C might be even better than a richer use of C++ (or Objective C). And Window 8 may run on user devices with much smaller batteries than todays common laptops. – hotpaw2 Sep 29 '11 at 17:58
  • 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 '11 at 19:38
  • 1
    @DeadMG - Of course this is true, especially if you stick near the common subset of C and C++. I was referring to the use of a richer set of C++ features not in C which sometimes requires more runtime support, etc. – hotpaw2 Sep 29 '11 at 19:49
  • @DeadMG: Libraries, you need msvcp along with msvcr. Not much of a reason nowadays, but still, there is a valid reason. – Coder Sep 29 '11 at 20:06
  • Coder, your reasoning is inconsistent. On one hand you say Microsoft support multiple technologies leading to mess, on the other hand you claim they are deprecating them too quickly. Which one of it is it? – Boris Yankov Sep 29 '11 at 23:38
  • @hotpaw2 There is no C++ feature that requires "more" runtime support than the same in C. Also, if you use higher structure in C++ you give more clues for optimization to the compiler than in C. That's why the C++ sort (template, type-safe, inlined, take account of the call context) is faster than the C one (manipulate arbitrary pointers blindely at runtime). – Klaim Mar 08 '12 at 08:57
  • [Jevons paradox](http://en.wikipedia.org/wiki/Jevons_paradox): "technological progress that increases the efficiency with which a resource is used tends to increase (rather than decrease) the rate of consumption of that resource" – superfav Jul 12 '12 at 01:40
  • Strange that on all the mobile platforms, where you'd expect battery lifetime and performance to be key concerns, C++ is not the primary language of choice. WinPhone prefers c#, Android Java and iOS Obj-C. Claims of a C++ renaissance are just wishful thinking that evidence doesn't support. – sashang Jul 27 '12 at 09:03
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.

DeadMG
  • 36,794
  • 8
  • 70
  • 139
  • 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 – Lukasz Madon Sep 29 '11 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)": http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.67.5276 – J D Jan 14 '12 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 '12 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 '12 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 '12 at 04:24
  • 2
    @DeadMG: Your statement was about generics and not C# and, therefore, is totally factually incorrect. – J D Jan 26 '12 at 19:25
  • 1
    @JonHarrop You don't really get the context, do you? And no, I don't mean you don't ever get any context. My comment is meant in the context of the above discussion. – Christian Rau Mar 08 '12 at 11:53
  • @ChristianRau: If someone said "addition in C++ predates arithmetic" and then claimed they had *obviously* meant "addition in C++ (1983) predates arithmetic in C# (2001)" what would you think? – J D Mar 08 '12 at 13:51
  • 1
    @JonHarrop I wouldn't argue with him if the immediately preceding sentence said: "features C++ had since long ago have only just come to .NET languages, like arithmetic". The meaningfulness of this (as C++ predates .NET, anyway) is another question, but he **obviously** is right and **obviously** didn't mean arithmeitc in general. And also the meaningfulness gains much quality when somebody else likes to argue that .NET languages have many nice features, like arithmetic (which doesn't imply the OP did, but many do). – Christian Rau Mar 08 '12 at 14:09
  • @ChristianRau So you agree that the statement is meaningless? – J D Mar 08 '12 at 15:39
  • 1
    @JonHarrop No, only partly, given the context (see my last sentence). And it's definitely not wrong either. – Christian Rau Mar 08 '12 at 16:28
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.

Lord Tydus
  • 1,429
  • 1
  • 10
  • 12
  • 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 '12 at 06:16
  • 2
    but new version of java got this feature http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html – Lukasz Madon Jan 24 '12 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 '12 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). – Adam Zalcman Jan 24 '12 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 '12 at 23:56
  • Also, there are a lot of problems in your code. You probably meant `File` to be a class representing a file (since you put the constructor into try-catch block) and you should not call `close()` on a reference which may be `null`. The [File](http://docs.oracle.com/javase/6/docs/api/java/io/File.html) from java.io represents an abstract path and doesn't have `close()` method. Finally, you should not be catching base class `Exception`. – Adam Zalcman Jan 24 '12 at 23:58
  • @Adam Zalcman. There's no error handling in the C++ "do stuff". The clean up is in the destructor. The example is only about the "clean up" portion of the error handling. The swallowing or throwing of the expecption is irrelevant. I should have re-thrown the exceptions in the java example to make it equivalent. – Lord Tydus Jan 25 '12 at 00:01
  • @Adam. That's not true. You don't need to check anything to guarantee the destructor is called. – Lord Tydus Jan 25 '12 at 00:04
  • @Adam. Edited the example to address your issues (which are not related to the point of the example which is cleaning up shared external resources). – Lord Tydus Jan 25 '12 at 00:17
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".

Nemanja Trifunovic
  • 6,815
  • 1
  • 26
  • 34
  • 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 '11 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.

daven11
  • 769
  • 5
  • 11
  • 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 '12 at 17:10
  • WinRT is definitely not portable. – Tamás Szelei Jan 23 '12 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.

C Flat
  • 31
  • 1