Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

C64

C64 C64

Niner since 2010

  • Herb Sutter: (Not Your Father’s) C++

    @Luna:

    C++ is fast as hell I'll give you that. But even C++11 is no where near the comfort of C#. Syntactic sugar does not cut it. There are pitfalls everywhere and I doubt that all this new candy makes it better, since everything else is still aimed at your own foot. I don't even talk about memory/resource management since C++ is really good at it. But things like object slicing, pointer dangling, and stuff like that really create hard to find and nasty bugs in large code bases...

    If you use convenient classes like STL containers, smart pointers, etc. and modern C++ programming style, it is very difficult to have pointer dangling.

    Lots of problems and bugs with C++ and pointers are for old code bases, when C++ was used "like a better C", with raw pointers everywhere, no smart pointers, etc. But in more recent times the story changed.

  • Herb Sutter: (Not Your Father’s) C++

    Excellent talk! Thanks for this.

     

  • C++: A Language for Modern Times

    @Chris:To kind of support Chris' point about managed code performance, there is a long thread on a MSDN Forum about the slowness of VS2010 IDE, an interview to a VMWare dev (former VC++ MVP and author of a great tutorial series on WTL) that confirms this opinion, and the experience of Evernote (emphasis mine in the following quote):

    "Evernote 4 is a major departure from Evernote 3.5 in every way. While 3.5 added tons of great new features, there were some problems we simply couldn't fix: the blurry fonts, slow startup times, large memory footprint, and poor support for certain graphics cards were all issues that the technology behind 3.5 (Windows .net and WPF) was incapable of resolving. As a result, we ended up chasing down platform bugs rather than adding the great features our users wanted.

    So we decided to start over from scratch, with fast, native C++ that we knew we could rely on. As you'll see, the results are amazing."

     

  • C++: A Language for Modern Times

    @Jagannath:You're right: C++11 range-based for loops are a great tool to improve code quality, and are a very welcome addition.

    But the general point about C++ having more details to pay attention to than C# still holds.

    Even in your code, you have shared_ptr, and in general the C++ programmer has to think: "I need to put X in a container. Should I use X*? Or shared_ptr<X>? Or unique_ptr<X>? etc.". In C# you just use SomeContainer<T> and are done.

    And there was another very good example made above about virtual. And others can be found along the same line.

    Of course, all this is not "rocket science". It just requires more study and a steeper learning curve to climb.

  • C++: A Language for Modern Times

    @Mark: I think people here are trying to produce constructive feedback comments, and express their own views in a respectful way. Then one can agree or disagree, using his own "knowledge chamber".

    If you are here to insult and pollute the conversation, it would be better for you to go somewhere else and don't waste people's time.

    There are other places on the Internet where idiots can call other guys "troll".

    Coming back to a fair C# vs. C++ comparison, it seems clear to me what is the simpler (easier to write, easier to understand) code between "modern C++" and C#:

    // C#
    
    var c = new Circle(42);
    List<Shape> v = LoadShapes();
    
    foreach (Shape s in v)
    {
      ...
    }
    
    

    What is the most efficient? Well, the (more complex) C++ one.

    But a more interesting question would be: "Would it be possible to kind of extend C++ - without sacrificing its core values like efficiency - so that we can use a simpler syntax?"

    For example, I'm thinking of having something like C++/CX "^" (but without WinRT), which is still pure native code (no garbage collector, no virtual machines; just ref count automatically performed by the compiler) but without a verbose shared_ptr<> syntax required. Maybe in this case the compiler could also do some optimizations that are not possible with shared_ptr.

     

  • C++: A Language for Modern Times

    Well it is not like you would use smart pointers on every object you create. In C# you have no real control where a object is allocated. In C++ you have to make the choice all by yourself. This requires a careful choice, and you will first try to allocate your stuff on the stack. This is blazing fast AND safe.

    Yes, for simple allocation stack semantics is fine. But in non trivial code you have to create objects and put them in some container.

     

  • C++: A Language for Modern Times

    , Rokris wrote

    Not like C++ is a walk in a park. Still lots of pitfalls:

    It's important to be clear and honest: C++ is not a walk in the park.

    Compare the modern C++ MSDN sample of circle and shapes in the aforementioned "Welcome back to C++" to what can be written in C#.

    auto p = make_shared<circle>( 42 );vector<shared_ptr<shape>> v = load_shapes();for_each( begin(v), end(v), [&]( const shared_ptr<shape>& s ) {    if( s && *s == *p )        cout << *s << " is a match\n";} );

    In C++ you have make_shared, vector<shared_ptr<>>, const shared_ptr &, etc. C# code is simpler (no make_shared, no shared_ptr, no reference "&", etc.), there is no doubt about it. But, as Herb Sutter excellently pointed out in the interview, this has a cost in terms of efficiency.

    I think the golden rule is: "Use the right tool for the job". And, if you want efficiency, speed, low memory consumption, etc. then: go native Smiley

    BTW: Speaking of performance of native vs. managed code, I wish Microsoft came back to a fast native Visual Studio IDE (like we had in VS2008 and before).

     

  • C++: A Language for Modern Times

    , dot_tom wrote

    Great interview chaps.

    I agree.

     

    I find that one of the big problems C++ suffers from in the Windows programming community these days is that the folks writing it 10 years ago have moved to .NET, taken on team leadership roles and can't seem to separate in their minds C++ from 'COM', 'ATL' and 'MFC'. Whenever I hear negative stuff about C++ it's 'Oh, remember the grief we had with COM, manual reference counting and the registry', which of course has nothing to do with either the core language or its wonderful (if small) Standard library.

    Note that ATL is an excellent tool to do COM programming in C++ in an efficient way, and it also offers convenient RAII wrappers to raw COM interfaces like CComPtr<T> smart pointer. There is no need to manual ref count if you use ATL.

    And note also that COM is a robust native technology that is still at the basis of more modern stuff like WinRT, and modern Win7 APIs like Ribbon or Animation Framework are conveniently exposed in an "object-oriented" way using COM. COM in plain C can be complicated to program, but COM in C++ with ATL is OK.

    Instead, I agree with you that MFC exposes some "anti patterns" (like throwing exceptions on the heap instead of on the stack, having an array class that grows arithmetically instead of geometrically like std::vector correctly does, having some container classes that "memcpy" their data instead of using proper copy constructor, etc.).

    However, one of the advantages of MFC is that there is a rich 3rd party market, like Codejock components; ATL and WTL unfortunately don't have that.

     

  • Interactive Panel: The Importance of Being Native

    @JulienNitard:I don't have a crystal ball to predict the future.

    I just compare what I have available today, and it seems to me that native GUI's tend to be snappier than manged GUI's. (When the future comes, we'll see what happens.)

     

  • Interactive Panel: The Importance of Being Native

    , JulienNitard wrote

    [...] It is hard to see where, in theory, the advantage of a purely native language is. Please don't get me wrong, I write C++ all day long, I am just trying to get a better picture of the problem.

    I think your request is fair, and I'm trying to get a better picture of the problem as you do.

    I see the advantage of native language in practice for power and performance.

    I gave you VS2010 WPF IDE as an example. You may want to try it with some open-source very big code base, like Google Chrome. Try loading it in both VS2008 and VS2010, and see the memory consumption and the responsiveness of the two IDEs. Sometimes VS2010 hangs, becomes unresponsive, etc. Moreover, the start-up time for VS2008 is shorter than VS2010.

    Note that (at least for me) the build times for VS2008 and VS2010 are almost the same, the problem is in the IDE. VS2010 offers us an improved C++ compiler and improved libraries: but they just deserve a better IDE.

    See also the move of Evernote, which dropped .NET and WPF in favor of native C++.

    And you can see how snappy are native apps (written in Objective-C/C++) on mobile devices like iPhone's and iPad's. 

See more comments…