Friday, April 28, 2023

Digest for comp.lang.c++@googlegroups.com - 19 updates in 1 topic

Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 03:35AM +0200

Am 27.04.2023 um 20:18 schrieb Scott Lurndal:
 
> Indeed, in the real world one attempts to make the code readable
> to all colleagues (and for open source, the whole world), regardless
> of each colleagues skill level.
 
My code is easy to read if you know C++20 concepts.
"Öö Tiib" <ootiib@hot.ee>: Apr 27 09:58PM -0700

On Friday, 28 April 2023 at 04:36:15 UTC+3, Bonita Montero wrote:
> > to all colleagues (and for open source, the whole world), regardless
> > of each colleagues skill level.
> My code is easy to read if you know C++20 concepts.
 
I you are such a rockstar programmer then perhaps provide cite of that
opinion.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 07:17AM +0200

Am 28.04.2023 um 06:58 schrieb Öö Tiib:
 
 
> I you are such a rockstar programmer then perhaps provide cite of that
> opinion.
 
I use concepts how they're meant, i.e. constraining all generic
types in a way that the code gets meaningful errors if the caller's
type don't match that constraints.
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Apr 28 01:47AM -0700

On Friday, 28 April 2023 at 05:58:36 UTC+1, Öö Tiib wrote:
> > My code is easy to read if you know C++20 concepts.
> I you are such a rockstar programmer then perhaps provide cite of that
> opinion.
 
It's a general problem with modern C++. Unless you are very familiar with
the language, code is hard to read, because it's not similar to other
languages. However you can argue that that is the case for C++ - there's
not much point in a language which just has a slightly different syntax for
counted loops but is otherwise essentially C.
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Apr 28 01:55AM -0700

On Friday, 28 April 2023 at 05:58:36 UTC+1, Öö Tiib wrote:
> > My code is easy to read if you know C++20 concepts.
> I you are such a rockstar programmer then perhaps provide cite of that
> opinion.
Bonita's prototype
template<std::input_iterator InputIt, typename IsEnd, typename Consumer>
requires std::is_integral_v<std::iter_value_t<InputIt>>
&& requires( IsEnd isEnd, InputIt it ) { { isEnd( it ) } ->
std::convertible_to<bool>; }
&& requires( Consumer consumer, InputIt inputIt ) { { consumer(
inputIt, inputIt ) }; }
 
We've got three templated type, InputIt, isEnd, and Consumer.
 
InputIt must be an input iterator.
 
The we've got the constriants.
InputIt must have an integral value type
isEnd must be a callable type which returns a boolean compatible type whe called with an InputIt
Consumer must be a callable typewhich takes two InputIts.
 
It's not too hard.
Muttley@dastardlyhq.com: Apr 28 09:01AM

On Thu, 27 Apr 2023 18:21:09 +0200
>and g++ you now get descriptive errors which show which constraint is
>violated. You don't even have to understand how to write concepts to
>understand the resulting errors.
 
So you're saying that a new construct needs to be added to the language in
order to allow sane compile errors? Riiiiight...
 
 
>Idiot.
 
>> Your psychological analysis is as bad as your code.
 
>I'm right on that because you're overburdened with a lot of new things.
 
No, I'm just able to filter out the crap.
Muttley@dastardlyhq.com: Apr 28 09:03AM

On Thu, 27 Apr 2023 13:15:50 -0700
 
>Bonita is an interesting person. Seemingly "loves" to insult, but....
>Bonita is anything but stupid. One time I loosely compared her to the
>cruel puppet:
 
Oh he's (and its almost certainly a man) not stupid. Just has no understanding
of other people and likes to show off.
Muttley@dastardlyhq.com: Apr 28 09:13AM

On Thu, 27 Apr 2023 18:50:30 +0200
>> software development.
 
>I'm 51 and I'm programming since I'm 10 and I'm skilled far
>beyond you. What impression do you think you make on others,
 
You think you're skilled because you can play around with various language
constructs. Software development involves writing code that actually does
something useful beyond some demonstation snippet. What have you done?
 
>except for those who are not better at programming than you ?
 
You're like the amateur guitar player who can play a few riffs from [some band]
really well to impress people at a party. But put him on on a stage and ask him
to do an entire concert and he'd fall apart.
Muttley@dastardlyhq.com: Apr 28 09:14AM

On Thu, 27 Apr 2023 11:45:01 -0700 (PDT)
>code as particularly readable? =20
 
>https://github.com/martinus/robin-hood-hashing/blob/master/src/include/robi=
>n_hood.h
 
Templates mixed up with macros. Ugh.
Muttley@dastardlyhq.com: Apr 28 09:15AM

On Fri, 28 Apr 2023 01:55:18 -0700 (PDT)
>alled with an InputIt
>Consumer must be a callable typewhich takes two InputIts.
 
>It's not too hard.
 
You think having to spend time figuring out metacode in a function prototype
is acceptable?
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 11:16AM +0200

I straightened the code a bit:
 
#pragma once
#include <type_traits>
#include <iterator>
#include <concepts>
 
template<typename Iterator, typename Consumer>
concept linify_input_iterator =
std::input_iterator<Iterator>
&& requires( Iterator inputIt ) { { *inputIt == char() } ->
std::convertible_to<bool>; }
&& requires( Consumer consumer, Iterator inputIt ) { { consumer(
inputIt, inputIt ) }; };
 
template<typename Iterator, typename IsEnd, typename Consumer>
requires linify_input_iterator<Iterator, Consumer>
&& requires( IsEnd isEnd, Iterator it ) { { isEnd( it ) } ->
std::convertible_to<bool>; }
void linify( Iterator begin, IsEnd isEnd, Consumer consumer )
{
using namespace std;
if( isEnd( begin ) ) [[unlikely]]
return;
for( Iterator scn = begin; ; )
for( Iterator lineBegin = scn; ; )
if( *scn == '\n' ) [[unlikely]]
{
consumer( lineBegin, scn );
if( isEnd( ++scn ) )
return;
break;
}
else if( *scn == '\r' ) [[unlikely]]
{
consumer( lineBegin, scn );
if( isEnd( ++scn ) || *scn == '\n' && isEnd( ++scn ) )
return;
break;
}
else if( isEnd( ++scn ) ) [[unlikely]]
{
consumer( lineBegin, scn );
return;
}
}
 
template<typename Iterator, typename Consumer>
requires linify_input_iterator<Iterator, Consumer>
inline void linify( Iterator begin, Iterator end, Consumer consumer )
{
linify( begin, [&]( Iterator it ) -> bool { return it == end; },
consumer );
}
 
template<typename Iterator, typename Consumer>
requires linify_input_iterator<Iterator, Consumer>
inline void linify( Iterator begin, Consumer consumer )
{
linify( begin, [&]( Iterator it ) -> bool { return !*it; }, consumer );
}
 
 
The common parts of all three functions are now in a concept,
the individual parts of the first function are still there.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 11:17AM +0200


> You think having to spend time figuring out metacode in a function prototype
> is acceptable?
 
This makes the code more readable and usable since you directly see
what are the required constraints on the generic types and if you
supply variables that don't have these properties you get more mea-
ningful errors.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 11:18AM +0200


> So you're saying that a new construct needs to be added to the language in
> order to allow sane compile errors? Riiiiight...
 
Generic code may lead to errors from inside the functions.
So you have a more meaningful error from outside the function
and you won't have to deal with the details.
Malcolm McLean <malcolm.arthur.mclean@gmail.com>: Apr 28 02:49AM -0700

> >understand the resulting errors.
 
> So you're saying that a new construct needs to be added to the language in
> order to allow sane compile errors? Riiiiight...
 
It's because of the way that templates developed in C++ from what was originally
a very limited idea to a sophisticated system. The syntax will accept any type.
However the surrounding code can only rarely accept any type whatsoever.
Worse, you can sometimes have subtle bugs, for example when passing an
integral type to a function which needs to do real arithmetic. The compiler is
of course incapable of understanding this.
Muttley@dastardlyhq.com: Apr 28 10:25AM

On Fri, 28 Apr 2023 02:49:10 -0700 (PDT)
>Worse, you can sometimes have subtle bugs, for example when passing an
>integral type to a function which needs to do real arithmetic. The compiler is
>of course incapable of understanding this.
 
Thats why template specialisation was created.
Muttley@dastardlyhq.com: Apr 28 10:27AM

On Fri, 28 Apr 2023 11:18:55 +0200
 
>Generic code may lead to errors from inside the functions.
>So you have a more meaningful error from outside the function
>and you won't have to deal with the details.
 
Compiler writers are quite capable of making their compilers give useful
errors. Clang is a lot better at it than gcc for example , the latter whom
often dumps pages of borderline unparsable garbage to the screen. Thats not
a problem with C++, its a problem with gcc.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 12:57PM +0200


> Compiler writers are quite capable of making their compilers give useful
> errors. ...
 
Do you ever have debugged generic function-objects inside generic code
like you use ? The errors are much less useful than coming from a con-
cept. And you even don't have to understand concepts but just the error.
 
> Clang is a lot better at it than gcc for example, ...
 
You don't know what you're talking about. Imagine I wouldn't have con-
cepted my code and the isEnd Function-Object doesn't return a bool or
the consumer function-object doesn't accept two of the given forward
-iterators. The errors are more complicated to read than those resul-
ting from a concept. And if you have code like of common runtimes it
looks at Swahili to inspect that; then I'd rather perfer clean concepts.
Muttley@dastardlyhq.com: Apr 28 11:04AM

On Fri, 28 Apr 2023 12:57:41 +0200
>cept. And you even don't have to understand concepts but just the error.
 
>> Clang is a lot better at it than gcc for example, ...
 
>You don't know what you're talking about. Imagine I wouldn't have con-
 
You're an arrogant ass sometimes. Every piece of personal code I write I compile
on MacOS and Linux (clang and gcc) and clang is far better at error reporting
than gcc in generic code but there's still plenty of room for improvement.
Bonita Montero <Bonita.Montero@gmail.com>: Apr 28 02:11PM +0200


> You're an arrogant ass sometimes. Every piece of personal code I write I compile
> on MacOS and Linux (clang and gcc) and clang is far better at error reporting
> than gcc in generic code but there's still plenty of room for improvement.
 
The errors of any compiler when supplying types that don't match the
criteria are a lot harder to read than when the compiler says you which
properties are missing according to the concept - with any compiler.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: