Modern C++: What You Need to Know

Download this episode

Download Video

Download captions

Download Captions

Description

This talk will give an update on recent progress and near-future directions for C++, both at Microsoft and across the industry. This is a great introduction to the current state of the language, including a glimpse into the future of general purpose, performance-intensive, power-friendly, powerful native programming.

Tag:

C/C++

Day:

2

Code:

2-661

Room:

Room 2005

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      Ivan

      Will this have some new material or more like for ppl who dont know modern C++. I ask because I watched all Herbs lectures in past couple of years... (Im your biggest fan :P)

    • User profile image
      sbehnke15

      Will this only be available 24 - 48 hours afterwards or will it be streamed live? The main schedule doesn't mention it.

    • User profile image
      TheNCoder

      No streaming? :(

    • User profile image
      admir

      No livestream for Modern C++, (talking about IaaS ) :(

    • User profile image
      LD Moretti

      I'm watching the video now and have been programming C++ for 15+ years, and I found this talk useful, if just a reminder on why we use C++.

    • User profile image
      herbsutter

      There's also a performance-geeky section in the middle. Hope you enjoy it!

    • User profile image
      LD Moretti

      If you're a C++ regular and wondering if you need to watch this, you need to just for the prefetch stuff at about 40min in!

    • User profile image
      Fernando

      Herb, you could also mention Sum Types in your Types table.
      In C++ we have boost::variant

      https://en.wikipedia.org/wiki/Tagged_union

      Excelent talk!

    • User profile image
      Ajay Shah

      Every major ISV uses 98C++. Adding Concurrent features into C++ is not part of the philosophy of Imperative Architecture. You're wasting your time learning anything other than 97/98! Java is for most. .NET is for experts. C++ is for end-of-your-life. Get a clue!

    • User profile image
      Ajay Shah

      Adding Javascript, OpenCL Scripts, Querying, Markup all into C++ SYNTAX is awkward. Pros/cons not Plus/minus is correct about C++. The next architecture or Foo has only Plus with no minus. Screw-up your life with SSRIs or misusing C++.

    • User profile image
      Ajay Shah

      Lets' add Concurrency Language syntax into SQL! And next D-HTML-X version 6 with a Opera 4. Way to go.

    • User profile image
      Zdravko Velinov

      Bad designed code is bad in any language and OOP does not guarantee you anything. Functional programming is not a silver bullet. You might want to drop immutability from time to time to squeeze the last drop of performance out of your hardware.

    • User profile image
      devnrev

      Great talk Herb. Any chance to ask you a question by mail (or different channel), since it is a bit longer and covers some of the aspects you mentioned in the memory related part of your talk?

    • User profile image
      Matt_PD

      Good talk!

      Nice to see DOD (Data-Oriented Design; demoed & mentioned in the "Data Locality" article by Bob Nystrom) becoming more widespread! :)

      For anyone interested in learning about DOD, I've found "The Latency Elephant" and "Pitfalls of Object Oriented Programming" by Tony Albrecht (also mentioned in the article, together with a pretty interesting book by Richard Fabian) pretty good & motivating:
      - http://seven-degrees-of-freedom.blogspot.com/2009/10/latency-elephant.html
      - http://seven-degrees-of-freedom.blogspot.com/2009/12/pitfalls-of-object-oriented-programming.html
      - (PDF) http://research.scee.net/files/presentations/gcapaustralia09/Pitfalls_of_Object_Oriented_Programming_GCAP_09.pdf

      Mike Acton's presentation from GDC 2014 is quite informative:
      "Code Clinic: How to Write Code the Compiler Can Actually Optimize"
      (PPTX) https://github.com/macton/presentation-archive/raw/master/gdc14_code_clinic.pptx

      "Introduction to Data-Oriented Design" from DICE also gives a nice overview (see also the links at the end):
      http://dice.se/publications/introduction-to-data-oriented-design/

      "A Step Towards Data Orientation" and "Practical Examples in Data Oriented Design" provide a few examples:
      - http://dice.se/publications/a-step-towards-data-orientation/
      - http://gamedevs.org/uploads/practical-examples-in-data-oriented-design.pdf

      More: http://www.asawicki.info/news_1422_data-oriented_design_-_links_and_thoughts.html

      Or, last but most definitely not least, here's _THE_ definitive source: "What every programmer should know about memory" by Ulrich Drepper: http://lwn.net/Articles/259710/
      // If you read just one doc, read this one :)

    • User profile image
      samuwabi

      The video buffering takes ages. If you can't host your videos so they are useable why not host them on youtube?

    • User profile image
      Herc

      Hello everyone,

      Any know what program they use to make this video? I.E. the speakers' video is on the left with his slides displaying on the right. I'm a teacher and I would like to do something similar. I want to record my lectures with the slides for future viewing.

    • User profile image
      Olivier

      With respect to Bjarne Stroustrup, I would have written the Python arithmetic mean function this way

      def mean(seq):
      return sum(seq) / len(seq)

      Which is faster and shorter than the manual loop.

    • User profile image
      Maxim Ivanov

      Python example for mean wouldn't pass code review either

    • User profile image
      psuderman

      You can do that C++ as well:

      auto mean(const Sequence& seq) {
        return std::accumulate(cbegin(seq), cend(seq), 0.0) / seq.size();
      }

      He probably just did that to illustrate the new for range loop.

    • User profile image
      herbsutter

      @Olivier: Thanks, I'll add a slide for next time to show the alternate Python/C++ side-by-side.

      Your Python example:

      defmean(seq):
         return sum(seq) / len(seq)

      C++ example (you could write sum as a one-liner and shorten this up further but I'll stick to only std:: operations):

      auto mean(const Sequence& seq) {
         return accumulate(begin(seq),end(seq),0) / seq.size();
      }

    • User profile image
      Oktalist

      C++ arithmetic mean could be

      return std::accumulate(begin(s), end(s)) / s.size();

    • User profile image
      Oktalist

      Ninja'd by the best

    • User profile image
      Mantosh Kumar

      Thank you very much Herb for your excellent talk on modern C++ and on efficiency/performance topics.I thoroughly enjoyed as always with your talk(especially the slides of access patterns matters) overall about performance. However I have couple of doubt/query from this talk:

      1.
      While explaining about move semantic you have taken the example of collection/container type and mentioned that it would move the resource/pointer ownership to other object and let original in empty state. This is my understanding about move semantics as well.

      However TC++PL book mention about this we should leave the source object in a valid but unspecified state.

      The above line(unspecified) confuse a bit. I would like to know what else can be a source object (apart from empty) after move semantics gets called on that particular object.Is there any real world example where keeping object in unspecified state make sense rather than empty??.


      2.
      Is it possible to share your source code which you had used while demonstrating the concept Access Patterns matter(slide no:30). I would like to do some experiment on my laptop with your program(It has L1:3MB) and try to find the spikes(in the total CPU cycle taken) when my data size is below the 3MB and when above the 3MB.

      3. I always uses the std::vector as my default choice and this has been demonstrated in your talk as well. I also map/set container where look-up time is really important. I was wondering when using std::list(practical) would be really efficient and beneficial against the std::vector(as even vector beats list in insertion/deletion of node)? Do you have any suggestion on this?

      Mantosh Kumar










    • User profile image
      Zdravko Velinov

      Also, don't get fooled by the so called data-driven design. It is a glorified way to optimize loops, such as your typical graphics pipeline that transforms some arbitrary spatial data structure (might be just a flat list) to command buffer packets of some sort. It is far from being a real paradigm.

    • User profile image
      Fernando

      @Olivier,
      Could you please explain the semantics of sum and len in Python?
      You are calling sum and len. Does it mean go through the sequence twice?

    • User profile image
      Fernando

      I answer my own question.
      All the objects with which the Python len function works, keep track of their own length.
      Therefore, the time complexity of len is O(1)

    • User profile image
      George

      Are there any plans to go more in depth on doing cross platform mobile dev in c++, using native ui & language for the interface on each platform? I know xamarin is an option to do this but I’d really like to learn more about doing this with a c++ code base. Are there any talks or presentations about this?

    • User profile image
      Matt_PD

      @George: perhaps these will be useful:

      - http://visualstudiomagazine.com/articles/2013/02/12/future-c-plus-plus.aspx
      - http://nwcpp.org/may-2013.html // note: links to Video & Slides are at the bottom

    • User profile image
      Heavens​Revenge

      Parallel STL oh yes please... now this type of convergence for C++ is the truly beautiful kind type

    • User profile image
      Jerry

      Guys don't hijack the topic into Google vs Microsoft.. Python vs C++/C#.. C++ is the clear winner here. C# follows. Python is an auxiliary player in Windows and Linux world.

      BTW sucks to be you python devs.. trying hard out there! F Google.

    • User profile image
      tocsa

      This was brilliant! A blast!

    • User profile image
      Ganga

      I did a very naïve test with C# List<T> and C++ Vector<T> and I was not able to reproduce any performance benefit out of the box form C++ Vector.

      http://stackoverflow.com/questions/22926046/unable-to-reproduce-c-vector-performance-advantages-over-c-sharp-list-perform

    • User profile image
      Oleksandr Yefremov

      Thank you talk.
      On your slide at 16 min you have following sample:
      Matrix operator+(
      const Matrix&,
      const Matrix&);
      m4 = m1 + m2 + m3;

      This code can be improved with following change:
      Matrix operator+(const Matrix& a, const Matrix& b){
      auto res = a;
      res += b;
      return res;
      }
      m4 = m1 + m2 + m3; // matrix get two times copy constructed
      while:
      Matrix operator+(Matrix a, const Matrix& b){
      a += b;
      return a;
      }
      m4 = m1 + m2 + m3; // matrix get copy constructed only once

      Note, I can't write:
      Matrix operator+(Matrix a, const Matrix& b){
      return a += b;
      }
      I must
      Matrix operator+(Matrix a, const Matrix& b){
      a += b;
      return a;
      }
      or
      Matrix operator+(Matrix a, const Matrix& b){
      return std::move(a += b);
      }
      Why?

    • User profile image
      JuanDeLa​Torre

      Excellent! I enjoyed it very much. Thank you.

      It is amazing how little things change my perspective in bigger issues.
      * View the prefetch buffer as an infinite cache.
      * "Your intuition is not reliable."

    • User profile image
      Phylos

      It's good to see C++ get more "modern". Getting more modern seems to mean getting closer to C# in ease of use but with better performance. That's all very nice but as a language, despite being "modern", I can't see myself using it unless I need the performance as it still seems so baroque despite all the hand waving.

      Before using C# I had been using C++ for about 10 years, and way before the "modern" period. At the time I loved using STL and various forms of smart pointers, but it came as relief to leave that all behind and go on to C#. Despite basic type inference to enable the "auto" keyword and smart pointers and lambdas, it still seems that C++ just keeps getting more complex overall, despite some simplifications bought on by the new features.

      Having used F# for the past 4 years, I now view C++, C# and similar languages are perpetuating a sort of dark ages in programming that may take decades (if ever) to overcome. While C++ and C# have borrowed bits of functional programming, they simply don't foster true high level approaches to problem solving in ways that OCaml, Haskell, F# and similar languages do.

      Despite the "modern" face lift, compare what's still missing from C++ now with what ML had 40 years ago - immutability by default, algebraic data types, pattern matching, powerful type inference to name some very important features and an elegant intuitive syntax. Modern languages that have derived from ML, like OCaml, F# and Haskell, have ML in their DNA which in practice means they are inherently more capable at tackling complex problems then the Algol derived languages such as C++, C# and Java.

      So yes, it's nice to have C++ add these new features, but unless one needs the speed why would anyone go through the pain of using a language that's so baroque and complicated. The new features may make it a bit more palatable but unless you're an existing C++ user and really need the speed why bother with C++ when there are much better alternatives.

       

    • User profile image
      tivadj

      Why Microsoft is not releasing .NET GC implementation as an open source?

      This action would boost the adaptation of D and Rust. As a result the C++ usage diminishes and more C++ developers will be eager to adopt the next generation of a native language from Microsoft (Native C# or whatever).

    • User profile image
      fenbf

      Great talk as usual! I liked part about memory access patterns. So simple mistake can hurt code performance a lot.

    • User profile image
      Bruno Santos

      Great talk Herb. As a C++ beginner I find your enthusiasm for the language very inspiring, and your talks are always easy to understand and at the same time very deep.

      Thanks.

    • User profile image
      Srinivasa

      Excellent! The quality and efficiency C++ reflects in the talk and presentation!! Looking forward for more sessions on C++ or native technologies. Its really refreshing to view these sessions.

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.