Hacker News new | ask | show | jobs
by jussij 4280 days ago
The old (STL based) C++ looks like this:

    // circle and shape are user-defined types
    circle* p = new circle( 42 ); 
    vector<shape*> v = load_shapes();
    
    for( vector<circle*>::iterator i = v.begin(); i != v.end(); ++i ) {
        if( *i && **i == *p )
            cout << **i << ā€œ is a match\nā€;
    }
    
    for( vector<circle*>::iterator i = v.begin();
            i != v.end(); ++i ) {
        delete *i; // not exception safe
    }
    
    delete p;
The new modern C++ looks like this:

    #include <memory>
    #include <vector>
    // ...
    // circle and shape are user-defined types
    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";
    } );
To be honest, as a C++ programmer who dates back to the days of Turbo C++ (i.e. before the days of STL), I can honestly say I no longer have any time for the old or new STL based C++.

The modern day C++ language is just too full of noise!

To remain relevant C++ needs to try to become a nice, easy to use language without the massive level of noise.

To be honest, as a 10 year+ veteran of C++, I have to say I don't miss it one bit.

2 comments

As a 15 year vet, I agree, surely its time for something with new design goals.

- safe by default: you have to opt in to extra magic / conversions. c++ is totally broken here. sure, we'll let you easily use uninitialized data/classes with auto generated constructors, and do conversions on your arguments, that was what you meant, right? I mean really, the shortest and quickest thing to do should always be the safest. make the speed freaks opt in to the 'leet / magic stuff'.

- still keep the option to use exceptions for stuff that, you know, is actually exceptional in your project.

I'm actually looking at modern java and finding it not horrible, but there are some issues in java that don't exist in c++ like 1) nulls 2) type erasure of generics 3) stupid object.equals() defined by default and not typesafe. Sigh.

That's not modern C++. This is much less noisy:

    #include <memory>
    #include <vector>
    // ...
    // circle and shape are user-defined types
    auto p = make_shared<circle>( 42 );
    auto shapes = load_shapes();
    
    for (auto s : shapes) {
        if( s && *s == *p )
            cout << *s << " is a match\n";
    }
Not sure what MS is thinking.
I guess a next feature would be auto auto (i.e., do not have to write auto). :-)