Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Announce: Expressive C++, a readability/safety/convenience dialect of C++.

45 views
Skip to first unread message

Alf P. Steinbach

unread,
Feb 25, 2017, 7:09:03 PM2/25/17
to
<url: https://github.com/alf-p-steinbach/Expressive-Cpp>

Expressive C++ is a header only library. It implements a less unsafe,
more convenient and readable-for-non-C++-expert-folks dialect of C++. To
do this it depends on the following language extensions, which are
supported by g++, Visual C++ and CLang, and probably also by far more
compilers: • `__COUNTER__`, • `#pragma once`, • `#pragma push_macro`, •
`#pragma pop_macro`, and • use of the `$` character in identifiers.

The shortest possible Expressive C++ program is

$just{}

which is • shorter than a standard `main`, and • safer than a standard
`main` ¹in the case of an exception being thrown out of it, and more •
directly readable, without distracting bits such as the `int` in

int main(){}

And this is the general philosophy: ²not always shorter like here, but
safer and to the non-expert more directly readable, and generally more
convenient than the raw C++ that Expressive C++ code translates to.

Flavor ³example:

#include <p/expressive/use_weakly_all.hpp>
#include <iostream>
#include <vector> // std::vector
#include <string> // std::string
$use_weakly_all_from( std );

void cpp_main( ref_<const vector<string>> args )
{
for( $each arg $in enumerated( args ) )
cout << "Arg " << arg.index() << " is '" << arg.object() <<
"'.\n";
}

$start_with_ascii_arguments( cpp_main )

The `ref_` type builder, and others like it, allows one to use the
principle of substitution to construct types, as in non-C languages in
general. It also supports the practice of putting `const` first, even in
nested parts. The resulting type specifications can be naturally read in
the forward direction, unlike in raw C and C++.

The $ words like $each and $in above, are pseudo keywords, keywords for
the Expressive C++ dialect, implemented as macros. Expressive C++ also
offers some stuff implemented with ordinary C++ code, using C++ core
language features up to and including C++14. For example, the expression

$invoked{ $var x=1; while( x*x < 50 ) ++x; return x - 1; }

… uses an Expressive C++ pseudo keyword macro, `$invoked`, to produce a
lambda, and to pass it to some ordinary C++14 machinery that invokes
that lambda and produces its return value with the type implied by the
return statement – which e.g., as here, allows a loop in an expression.

Enjoy, even though this is just a version 0.3-or-something.


- Alf

Notes:
¹ If any statements are added, then unlike a raw `main` any exception
out of the `$just` block is caught and reported on the standard error
stream, with guaranteed stack rewinding/cleanup, and a suitable process
exit code that adheres to the OS conventions is produced.
² I've not yet found a good way to express the `:?` operator within the
limits of a macro approach.
³ Sorry about the limitation to “ascii” here. Implementing portable
Unicode command line support, which raw C++ `main` doesn't offer for
systems other than *nix, is much work, and I haven't got to that yet.

Mr Flibble

unread,
Feb 25, 2017, 10:30:01 PM2/25/17
to
Use of dollar sign ($) in identifiers is implementation defined as to
whether it works so is unportable and should be avoided.

/Flibble

Marcel Mueller

unread,
Feb 26, 2017, 8:31:11 AM2/26/17
to
On 26.02.17 01.07, Alf P. Steinbach wrote:
> Expressive C++ is a header only library. It implements a less unsafe,
> more convenient and readable-for-non-C++-expert-folks dialect of C++. To
> do this it depends on the following language extensions, which are
> supported by g++, Visual C++ and CLang, and probably also by far more
> compilers: • `__COUNTER__`, • `#pragma once`, • `#pragma push_macro`, •
> `#pragma pop_macro`, and • use of the `$` character in identifiers.

I did not get why making the code look as ugly as Perl/php/PowerShell
sould be desirable.
Readability and maintainability does not generally benefit from magic
behind the scenes. Things may get even worse regarding compiler error
messages.


Marcel

Alf P. Steinbach

unread,
Feb 26, 2017, 8:53:42 AM2/26/17
to
On 26.02.2017 14:30, Marcel Mueller wrote:
> On 26.02.17 01.07, Alf P. Steinbach wrote:
>> Expressive C++ is a header only library. It implements a less unsafe,
>> more convenient and readable-for-non-C++-expert-folks dialect of C++. To
>> do this it depends on the following language extensions, which are
>> supported by g++, Visual C++ and CLang, and probably also by far more
>> compilers: • `__COUNTER__`, • `#pragma once`, • `#pragma push_macro`, •
>> `#pragma pop_macro`, and • use of the `$` character in identifiers.
>
> I did not get [it]
[snip]


I've started on tutorial-like documentation:

<url:
https://github.com/alf-p-steinbach/Expressive-Cpp/blob/master/README.md>

I think reading that might help to start clear things up, at least when
one keeps in mind that the rest of the library is similarly justified by
very real problems with raw C++, especially for beginners.

One needs to be aware of the shortcomings etc. that are addressed,
before one can understand the advantages and trade-offs, and I hope that
the docs I've started on do communicate this in a good way. :)


Cheers & hth.,

- Alf

Mr Flibble

unread,
Feb 26, 2017, 9:28:29 AM2/26/17
to
This library attempts to solve a problem that doesn't actually exist.
At its best it is simply obfuscation and at its worst it is plain
fucktardary. This library SERVES NO PURPOSE AT ALL.

/Flibble

Öö Tiib

unread,
Feb 26, 2017, 5:08:21 PM2/26/17
to
On Sunday, 26 February 2017 02:09:03 UTC+2, Alf P. Steinbach wrote:
>
> void cpp_main( ref_<const vector<string>> args )

I see '$proc cpp_main' here in your online tutorial.

I did like your threaded tree tutorial bit better. Will there be
more chapters of it? ;)
0 new messages