Thursday, June 25, 2015

Digest for comp.lang.c++@googlegroups.com - 25 updates in 5 topics

ram@zedat.fu-berlin.de (Stefan Ram): Jun 25 01:41PM

>>"void" means a procedure (or, get this, a function that doesn't return anything).
>Yes, in C rhetoric a procedure is function that returns void.
 
It's funny. Pascal or Algol seem to be a languages that are
long dead. But they live on when programmers use their
terminology as a common language. After all, that's where
»procedure« comes from AFAIK. What will be in some decades
when programmers do not learn Pascal or Algol anymore?
Could it be that for future children we will explain:
»What's a procedure? It's just a function returning void!«
 
But wait! C++ cites »ISO/IEC 2382 (all parts), Information
technology --- Vocabulary« as a »normative reference« in
1.2p1.2. And in ISO/IEC 2382-15 15.06.11 we indeed find
»procedure« defined as »A subprogram that does not return a
data value, except as part of the parameter mechanism.« So,
there is no real direct dependency of the word »procedure«
on Pascal or Algol, except for the possibility that ISO/IEC
2382-15 15.06.11 might be influenced itself from the Pascal
or Algol family of languages.
 
C++ also uses »procedure« in 8.3p3, but there, it seems to
be used more in the common-English sense of the word. But
by C++ using ISO/IEC 2382 as a normative reference, the
word »procedure« in a sense has a technical meaning in C++.
bleachbot <bleachbot@httrack.com>: Jun 19 03:16PM +0200

ram@zedat.fu-berlin.de (Stefan Ram): Jun 19 03:36PM

>Here is my attempt to generate all possible sequences:
 
Here's my attempt to print all terms summing up to 100:
 
#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
 
using namespace ::std::literals;
 
template< typename scanner >struct parser
{ scanner s;
parser( ::std::string s ): s{ s } {}
int digit(){ return s.get() - '0'; }
int numeral()
{ int result = digit();
while( ' ' == s.peek() )
{ s.get(); result *= 10; result += digit(); }
return result; }
int start()
{ int result = numeral();
{ char ch;
while( s.get( ch ), ch == '+' || ch == '-' )
{ if( ch == '+' )result += numeral();
if( ch == '-' )result -= numeral(); }}
return result; }};
 
int start( ::std::string string )
{ using parser = ::parser< ::std::stringstream >;
return parser{ string }.start(); }
 
struct term
{ ::std::string value = "1 2 3 4 5 6 7 8 9)"s;

bool inc( int const idx )
{ switch( value.at( idx ))
{ case ' ': value.at( idx )= '+'; return false;
case '+': value.at( idx )= '-'; return false;
case '-': value.at( idx )= ' '; return true; }}

bool increment( int const index )
{ return index < 0 ? false :
inc( index )? increment( index - 2 ): true; };
 
bool increment(){ bool result = increment( 15 ); return result; };
 
void check()
{ if( start( value )== 100 )
::std::cout << value.substr( 0, value.length() - 1 )<< '\n'; }};
 
static inline bool increment( term & t ){ return t.increment(); }
static inline void check( term & t ){ return t.check(); }
 
int main()
{ term t; bool looping = true;
while( looping ){ check( t ); looping = increment( t ); }}
 
prints:
 
1 2 3+4 5-6 7+8-9
1 2 3+4-5+6 7-8 9
1 2 3-4 5-6 7+8 9
1 2 3-4-5-6-7+8-9
1 2+3+4+5-6-7+8 9
1 2+3-4+5+6 7+8+9
1 2-3-4+5-6+7+8 9
1+2 3-4+5 6+7+8+9
1+2 3-4+5+6+7 8-9
1+2+3 4-5+6 7-8+9
1+2+3-4+5+6+7 8+9
ram@zedat.fu-berlin.de (Stefan Ram): Jun 19 04:17PM

>you consider recursion superfluous? And, in general, what's your take,
>is recursion OK or, if another solution (a loop, perhaps) exists,
>recursion should be avoided?
 
In C++, technically, iteration is supported better than
recursion because C++ does not have tail-call optimization,
and some implementations have a rather limited stack size.
 
For example, in C++, technically, the factorial is
implemented better with a loop than with recursion.
 
However, when it is know that the depth of the recursion
does not exceed a small number, like maybe 32, one might use
recursion in C++ when it is better readable or writeable for
humans.
 
Some problems with recursive data structures, like traversal
of trees (filesystems) or AI (like chess) or parsers for
languages with recursive grammars really beg for recursion,
and it might become quite cumbersome to implement them in
such a way that stack usage is O(1) instead of O(n).
ram@zedat.fu-berlin.de (Stefan Ram): Jun 19 05:57PM

C++ seems to differentiate between all those cases (e.g.,
when one needs to find out how something is initialized):
 
A - A class has a default-constructor declared in the
class specifier.¹
 
B - A class does not have a default-constructor
declared in the class-specifier, but the language
»has generated« a default constructor.²
 
C - A class has default-constructor declared in the
class specifier with »= deleted«.
 
D - A class has no default constructor.
 
Did I miss a case?
 
There also is the case of a »defaulted default constructor«!
I believe that this means a default constructor that was
declared with »= default«. Does this count as a subcase of
case A or of case B for the sake of reading the standard?
 
The last case can happen, I believe, when the user has
declared another constructor, so there will be no
default-constructor »generated«. I found it mildly
surprising that having a deleted default-constructor
is not the same as having no default-constructor!
 
The standard also uses »implicitly deleted default constructor«.
This seems to refer to case D?
 
1) I believe that this is also known as a
»user-declared« or »user-defined« default-constructor.
 
2) I believe that this is also known as an
»implicit« default-constructor or an
»implicitly declared« default-constructor.
ram@zedat.fu-berlin.de (Stefan Ram): Jun 19 06:19PM

>> class specifier.¹
>"...declared in the class _definition_." (the "class specifier" is
>something completely different, I believe).
 
9p1:
 
»class-specifier:
class-head { member-specification/opt }«
 
e.g.
 
struct Example { Example(){} }
 
9p2 says:
 
»A class-specifier is commonly referred to as a class definition.«
 
However, an author might extend the term »class definition«
to non-member functions that are closely related to the class.
ram@zedat.fu-berlin.de (Stefan Ram): Jun 19 06:21PM

>»A class-specifier is commonly referred to as a class definition.«
>However, an author might extend the term »class definition«
>to non-member functions that are closely related to the class.
 
Or other authors might use the term »class definition«
for »class-specifier and a following semicolon«.
ram@zedat.fu-berlin.de (Stefan Ram): Jun 19 07:41PM

>the test, one of the MIDDLE SCHOOLERS asked the teacher "what is pH?
>Plant height?"
>*Facepalm*
 
That's easy, because the upper-case and lower-case makes it unique:
 
The unit »Henry« is the SI derived unit of inductance we all know
and love. Its symbol is the /upper-case/ »H«.
 
The /lower-case/ SI unit-prefix »p« stands for »pico« (1E-12 in C++).
 
So, »pH« must be the /pico-Henry/!
Christian Gollwitzer <auriocus@gmx.de>: Jun 19 03:09PM +0200

Am 18.06.15 um 02:28 schrieb Jason C. McDonald:
 
> Well, I knew something could be cleaned up. Thanks for that. The funny
> thing about algorithms like this is that they are often considered so
> obvious that no one writes them down anywhere anymore.
 
Well for this one I know where I learnt it: in high school we were
taught about number representation in different bases (binary, ternary,
hexadecimal) and this algorithm was shown to us by the teacher. Note
this was the math course that every one had to take, not a special
computer science class. But in general I agree with you.
 
> problems with "just use X library": we wind up training an entire
> generation of programmers that, if tasked with rebuilding any basic
> functionality such as this, would be at a total loss.
 
Well sometimes it's better to know the library, sometimes better to
build on simple blocks, ths varies and a great deal of software
engineering is the decision, which way to go.
 
Have fun,
 
Christian
"Jason C. McDonald" <indeliblebluepen@nospam.invalid>: Jun 19 12:03PM -0700

On 06/19/2015 06:09 AM, Christian Gollwitzer wrote:
> hexadecimal) and this algorithm was shown to us by the teacher. Note
> this was the math course that every one had to take, not a special
> computer science class. But in general I agree with you.
 
I have yet to meet an American high schooler who learned about other
number bases. I've been a math tutor at my college, and half of the HS
grads can't even multiply. I learned about other bases on my own - none
of my classes in HS or college even taught me about them.
 
American education has some seeeeerious problems. (And thus why I work
in educational software, ha ha.)
 
 
> Well sometimes it's better to know the library, sometimes better to
> build on simple blocks, ths varies and a great deal of software
> engineering is the decision, which way to go.
 
I agree, with the caveat that one should try and know HOW the library
works as much as possible. If you look at programmers who exclusively
use high-level languages such as Python and Java, they don't know HOW it
works, WHY it works, how how to make it work BETTER. Nothing gets
innovated that way. >.>
 
On the flip side, it is definitely true that one should not duplicate
work unnecessarily. Had I known the library had a built-in, I would have
only undertaken this algorithm as an experiment, ha ha. (I actually am
building a language and its library nearly from scratch, thus the
fascination.)
 
 
--
The number of ways in which code can be potentially screwed up is
theoretically infinite.
www.indeliblebluepen.com
Christopher Pisz <nospam@notanaddress.com>: Jun 19 02:17PM -0500

On 6/19/2015 2:03 PM, Jason C. McDonald wrote:
> of my classes in HS or college even taught me about them.
 
> American education has some seeeeerious problems. (And thus why I work
> in educational software, ha ha.)
 
When I go out on online dates, my first question is "Can you tell me
what 1/8 * 3/4 is?"
 
I'm still single....
 
On okcupid, 90% of women answered they match question "Which is bigger,
the Sun or the Earth?" with "The Earth"..
 
 
--
I have chosen to troll filter/ignore all subthreads containing the
words: "Rick C. Hodgins", "Flibble", and "Islam"
So, I won't be able to see or respond to any such messages
---
"Jason C. McDonald" <indeliblebluepen@nospam.invalid>: Jun 19 12:34PM -0700

On 06/19/2015 12:17 PM, Christopher Pisz wrote:
 
> On okcupid, 90% of women answered they match question "Which is bigger,
> the Sun or the Earth?" with "The Earth"..
 
> > SNIP
 
3/32. I was taking a state standardized test in middle school, and after
the test, one of the MIDDLE SCHOOLERS asked the teacher "what is pH?
Plant height?"
 
*Facepalm*
 
--
The number of ways in which code can be potentially screwed up is
theoretically infinite.
www.indeliblebluepen.com
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 25 08:23AM -0400

On 6/24/2015 8:51 PM, Richard wrote:
 
> Meh. Might as well just write
 
> int main() {}
 
> The use of auto and -> here feels gratuitous.
 
It's not gratuitous if it makes you special. Like the :: in front of
'std'. ;-)
 
V
--
I do not respond to top-posted replies, please don't ask
"Lőrinczy Zsigmond" <zsiga@nospam.for.me>: Jun 19 11:27AM +0200

> but the contents of the memory is left unchanged. That can be A BAD
> THING(tm) if you rely on the values to be specific, like 'NULL' for
> pointers or 0s for counters.
 
So we are back to square one:
 
1. The fields are initialised, but initialisation actually means:
they contain memory-garbage.
2. So it's a good idea to 'memset' it with zero.
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 19 07:40AM -0400

On 6/19/2015 5:27 AM, Lőrinczy Zsigmond wrote:
 
> 1. The fields are initialised, but initialisation actually means:
> they contain memory-garbage.
> 2. So it's a good idea to 'memset' it with zero.
 
A better idea would be to use one's brain instead of a bigger hammer.
If you need the memory to contain a specific value, be it zero or
nullptr (which is *not necessarily* "all bits zero", BTW) or something
else, set the member to that value. Explicitly.
 
V
--
I do not respond to top-posted replies, please don't ask
legalize+jeeves@mail.xmission.com (Richard): Jun 19 04:25PM

[Please do not mail me a copy of your followup]
 
=?windows-1250?Q?L=F5rinczy_Zsigmond?= <zsiga@nospam.for.me> spake the secret code
 
>So we are back to square one:
 
>1. The fields are initialised, but initialisation actually means:
> they contain memory-garbage.
 
No. Because they are left out of the initializer list they are *not*
initialized.
 
>2. So it's a good idea to 'memset' it with zero.
 
No. You should initialize them in the initializer list.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
scott@slp53.sl.home (Scott Lurndal): Jun 19 04:37PM

>> they contain memory-garbage.
 
>No. Because they are left out of the initializer list they are *not*
>initialized.
 
To be pedantic, that differs based on the scope of the
object being initialized. For a file-scope (static)
object, they _will_ be initialized on any modern implementation.
 
Personally, I'll either initialize the fields in the constructor
or have a 'new' operator overload that zeros the allocated region.
 
Not a big fan of using initializer lists for POD MOS.
legalize+jeeves@mail.xmission.com (Richard): Jun 19 05:15PM

[Please do not mail me a copy of your followup]
 
slp53@pacbell.net spake the secret code
 
>To be pedantic, that differs based on the scope of the
>object being initialized. For a file-scope (static)
>object, they _will_ be initialized on any modern implementation.
 
Where is this guaranteed in the standard?
 
If it isn't guaranteed, then it they are free to change it and
compilers are changing a lot these days.
 
Code should be written to be correct by design, not correct by accident.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
scott@slp53.sl.home (Scott Lurndal): Jun 19 06:05PM


>Where is this guaranteed in the standard?
 
>If it isn't guaranteed, then it they are free to change it and
>compilers are changing a lot these days.
 
If it were changed, it would break 40 years of code. Not a good idea.
legalize+jeeves@mail.xmission.com (Richard): Jun 19 06:09PM

[Please do not mail me a copy of your followup]
 
(Richard) legalize+jeeves@mail.xmission.com spake the secret code
>>object being initialized. For a file-scope (static)
>>object, they _will_ be initialized on any modern implementation.
 
>Where is this guaranteed in the standard?
 
Answering my own question: 8.5 Initializers, paragraph 10:
 
"Note: Every object of static storage duration is zero-initialized at
program startup before any other initialization takes place."
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
The Terminals Wiki <http://terminals.classiccmp.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
Noob <root@127.0.0.1>: Jun 19 08:27PM +0200

On 18/06/2015 21:44, Paavo Helde wrote:
 
> Who are the 'we' who do keep saying that? The C++11 version is 4 years in
> the past and there are no big changes planned for next releases.
 
AFAICT, neither gcc nor VS fully support C++11 even today.
Wouter van Ooijen <wouter@voti.nl>: Jun 19 09:26PM +0200

Noob schreef op 19-Jun-15 om 8:27 PM:
 
>> Who are the 'we' who do keep saying that? The C++11 version is 4 years in
>> the past and there are no big changes planned for next releases.
 
> AFAICT, neither gcc nor VS fully support C++11 even today.
 
What are you missing in GCC?
 
The only thing I could find at https://gcc.gnu.org/projects/cxx0x.html
(C++ 11) is "Minimal support for garbage collection and
reachability-based leak detection", but the linked description doesn't
make me feel that I am missing a compiler feature, it seems to be an
issue about what constitutes a valid C++ program.
 
https://gcc.gnu.org/projects/cxx1y.html seems to claim full C++ 14 support.
 
Wouter van Ooijen
Victor Bazarov <v.bazarov@comcast.invalid>: Jun 19 02:10PM -0400

On 6/19/2015 1:57 PM, Stefan Ram wrote:
> when one needs to find out how something is initialized):
 
> A - A class has a default-constructor declared in the
> class specifier.¹
 
"...declared in the class _definition_." (the "class specifier" is
something completely different, I believe).
 
> I believe that this means a default constructor that was
> declared with »= default«. Does this count as a subcase of
> case A or of case B for the sake of reading the standard?
 
Class B, I'd say.
 
> default-constructor »generated«. I found it mildly
> surprising that having a deleted default-constructor
> is not the same as having no default-constructor!
 
And in C++11 you need to specify what you mean by "having no
default-constructor" since the absence of the default c-tor can be due
to different causes.
 
> The standard also uses »implicitly deleted default constructor«.
> This seems to refer to case D?
 
Most likely.
 
 
> 2) I believe that this is also known as an
> »implicit« default-constructor or an
> »implicitly declared« default-constructor.
 
V
--
I do not respond to top-posted replies, please don't ask
gwowen <gwowen@gmail.com>: Jun 25 05:51AM -0700

On Thursday, June 25, 2015 at 11:13:41 AM UTC+1, David Brown wrote:
 
> The whole point of this syntax was for more complex expressions,
> especially for template functions,
 
Lambda's, particularly. There its extremely handy because
 
auto l_obj []() -> int { .... }
 
Let's you be explicity about the return type of the lambda's operator(), while letting compiler worry about the type of the functor/closure itself.
 
> where the return type depends on the
> parameter types - thus you can't express the return type until after the
> parameters are written.
 
I can't think what you mean here. e.g.
 
template<class T> T::valuetype f(const T&t) {
...
} // works ok
"Öö Tiib" <ootiib@hot.ee>: Jun 25 05:57AM -0700

On Thursday, 25 June 2015 13:07:39 UTC+3, gwowen wrote:
 
> and what does
 
> auto do_stuff( Degrees angle ) -> void;
> denote?
 
It denotes nonsense obfuscation. Same as that one:
 
typedef void Nothing;
Nothing do_stuff( Degrees angle );
 
All useful languages are very easy to use for expressing nonsense.
 
> void burn_down_harddrive(Harddrive&j);
> double cosine( Degrees angle);
 
What you meant by repeating code that I wrote and that you snipped?
 
> "void" means a procedure (or, get this, a function that doesn't return anything).
 
Yes, in C rhetoric a procedure is function that returns void. Decades ago when I learned C it did sound like lunatic's delirium ... but now I'm used to it. I just can't never learn to think that way.
 
> "any other type" means a function that does return something, and I don't have to scan to the end of the argument list to see what.
 
Can't get everything and functions name is more important to find from that pile than return type. Alf writes:
 
auto cosine( Degrees angle )
-> double;
 
I like them on same line, ')->' is fine enough visual separator for me.
 
> > if to look at it then it is tolerable when
> > used consistently in whole code base.
 
> Almost anything is tolerable. The question was, what's the advantage?
 
The advantage is that function's name is put before rest of the clutter. It is same what lot of language neutral programming tools do.
 
In C++ we have lot of Yoda-speak ... like "template class" (that means class template) and "const reference" (that means reference to immutable) and "const pointer" (that means pointer to immutable).
We are used to it but that does not make it right and I still feel like translating those everytime I hear.
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: