Live data from Hacker News

Towards a more powerful and simpler C++ with Herb Sutter

blog.jetbrains.com

1–10 of 63 posts

Re: Towards a more powerful and simpler C++ with Herb Sutter

#2
Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$".

Update: From Herb's blog :

"Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing $ is an easy change at any time and we’ll just follow what the committee decides for reflection syntax (in fact, the alternative syntax I showed in the endnote above removes the need to write $). So further work is needed on those items, but fortunately none of it affects the core model."

https://herbsutter.com/2017/07/26/metaclasses-thoughts-on-ge...

P.S. I really hope that vocal minory would win ;)

But overall the proposal is what I have been talking about for a long time.

Re: Towards a more powerful and simpler C++ with Herb Sutter

#3
post #2

Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$". Update: From Herb's blog : "Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing…

The best way to add new language primitives without breaking anyone is to pick a syntax that currently fails to compile.

`reflexpr interface {...}` could be declaring and initializing a global.

`$class`, on the other hand, doesn't compile. One could also do `virtual class` or something, I guess, since `virtual class` is a combination of reserved keywords.

Re: Towards a more powerful and simpler C++ with Herb Sutter

#4
post #2

Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$". Update: From Herb's blog : "Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing…

The best way to add new language primitives without breaking anyone is to pick a syntax that currently fails to compile. `reflexpr interface {...}` could be declaring and initializing a global. `$class`, on the other hand, doesn't compile. One could also do `virtual class` or something, I guess, since `virtual class` is a combination of reserved keywords.

You are correct. But there is another side too. $ makes the language way uglier than it is now, and C++ is ugly language already.

Re: Towards a more powerful and simpler C++ with Herb Sutter

#5
post #2

Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$". Update: From Herb's blog : "Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing…

Its so much simpler :)

Re: Towards a more powerful and simpler C++ with Herb Sutter

#6
post #5
post #2

Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$". Update: From Herb's blog : "Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing…

Its so much simpler :)

I agree, but $ doesn't make the language way more uglier than what it is now?

Re: Towards a more powerful and simpler C++ with Herb Sutter

#7
The interview covers proposed metaprogramming features in upcoming versions of C++. In particular, it demonstrates metaclass as a way for users to define new kinds of types, instead of relying solely on class/struct/union/enum.

For example, Java has an interface, in which methods are declared but not defined. The proposal for metaclass gives a demonstration of what an interface in C++ could look like:

    interface Shape { 
        int area() const;
        void scale_by(double factor);
    };
Instead of changing the compiler to allow for new interface keyword, we can create a metaclass:

    // the dollar sign ($) prefix indicates reflection and metaprogramming
    $class interface {
        // the constexpr indicates compile-time execution
        constexpr {
            // raise an error if there are data members
            compiler.require($interface.variables().empty(),
                             "interfaces may not contain data");

            // loop over all functions
            for (auto f : $interface.functions()) {
                // raise an error if move/copy functions are present
                compiler.require(!f.is_copy() && !f.is_move(),
                                 "interfaces may not copy or move");

                // function must be public
                if (!f.has_access())
                    f.make_public();
                compiler.require(f.is_public(),
                                 "interface functions must be public");

                // function must be virtual
                f.make_pure_virtual();
            }
        }

        // add a destructor
        virtual ~interface() noexcept { }
    };
Thus I can create a new kind of type directly in my code. This can be part of a library for downstream users without ever changing the compiler.

See the full proposal here:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p070...

Re: Towards a more powerful and simpler C++ with Herb Sutter

#8
post #2

Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$". Update: From Herb's blog : "Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing…

I think the negatives (ugliness) of having $ in a few places where you define metaclasses is outweighed by the positives (cleanliness) of replacing this:

    class foo {
        virtual ~foo() = 0;
        virtual void do_x() = 0;
    };
with this:

    interface foo {
        void do_x();
    };
in thousands of places.

Re: Towards a more powerful and simpler C++ with Herb Sutter

#9
post #2

Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$". Update: From Herb's blog : "Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing…

Next proposal will be about the new C++ logo, which will be, yes, a camel!

Re: Towards a more powerful and simpler C++ with Herb Sutter

#10
post #2

Are they really going to add $ to C++? Unbelievable. What was wrong with "reflexpr"? It is way more C++'ish than "$". Update: From Herb's blog : "Also, a vocal minority in the committee strongly want a syntax that does not include the $ character (not just for $class, but also for $expr reflection) because they have large code bases that use $ in source code that is not C++ code but is processed to emit C++; removing…

It's still up in the air I think - you can see from his blog[1] that others in the the committee prefer a syntax more like

    meta::type interface(const meta::type source) {
        // … basically same code …
    };
[1] https://herbsutter.com/2017/07/26/metaclasses-thoughts-on-ge...
Post reply on HN