SPECS - a "resyntaxed" C++

I stumbled across this the other day. It's basically "what would C++ look like if we could rebuild the syntax from scratch." It's an interesting read, and highlights how crazy the syntax can be.
http://users.monash.edu/~damian/papers/HTML/ModestProposal.html
Would take some getting used to (writing type-safe code that starts with "obj"), but I guess I like it. It's definitely more consistent.

by extension, standard C++ syntax code is expected within a "C++" language declaration. This is useful when writing SPECS programs that include header files for one or more C++ standard libraries.
It would be interesting if someone, as a proof of concept, actually made a working parser that could work with C++ standard library headers and translate SPECS source code to be compatible to compile with an existing C++ compiler.
It would be necessary to do this to let a language like this get some early adopters, while still having all the optimizations that C++ compilers are known for.

Note however that different types of variables cannot be instantiated in the same declaration. The infamous C++ example:

char* c1, c2, c3();

has no direct equivalent in SPECS. We consider this to be a feature.
Ha. Good. Thanks for sharing.
I thought this was a great idea too:
After the [case] block [ion a switch statement] executes control jumps to the end of the switch statement (not to the next case, as in C++). The break statement will also cause control to jump to the end of the switch statement. The continue statement can be used in a case block and causes control to jump immediately to the beginning of the next case block, thereby implementing a more general, but safer form of fall-through than the C++ default behaviour.


So basically they switched it so the more common case where you break at the end of a case block is the default, and the less common case of falling through requires a continue statement.
Having such a switch statement would be inconsistent with other languages (not just C++) so why not call it something else? That would even allow us to add it to our beloved C++ language without breaking backwards compatibility.
You can ask for (some) compilers to enforce this already.

Pass -Wimplicit-fallthrough and get a warning if you don't mark cases with [[fallthrough]] (or, depending on settings, write a comment to that effect.)
https://en.cppreference.com/w/cpp/language/attributes/fallthrough
Looks a lot like the article writers are trying to sneak some Pascal thinking in to C++.
I like the idea of making declarations explicit. I've seem multiple mistakes like these here from beginners:
1
2
3
4
5
6
7
8
9
10
int main()
{
    int foo();  // meant to call foo.

    // Meant to define a new function called bar
    int bar(); {
        cout << "hello world\n";
    }
    ...
}


I think this could be avoided by requiring function declarations to have extern or static. As mbozzi pointed out with fallthrough, there's probably a command line option to g++ to warn about this. :)

Dave
I guess the other notable example of a language aimed at fixing the problems that C++ has or had, is the D language.
Topic archived. No new replies allowed.