Friday, June 19, 2015

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

legalize+jeeves@mail.xmission.com (Richard): Jun 19 05:17PM

[Please do not mail me a copy of your followup]
 
Victor Bazarov <v.bazarov@comcast.invalid> spake the secret code
 
>Can't help you, sorry. Compiles for me fine. And if you include
><cmath>, compiles on G++ v4.8.3 online as well. Make sure your compiler
>is C++11 compliant (at implements 'decltype').
 
And for gcc/clang be sure to use '-std' with an appropriate value.
(Why this isn't set to -std=c++11 as the default on a compiler that
implements C++11, I don't understand.)
--
"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>
gwowen <gwowen@gmail.com>: Jun 19 01:24PM -0700

On Friday, June 19, 2015 at 5:05:13 PM UTC+1, Victor Bazarov wrote:
 
> I am not sure I am reading the meaning of your statement correctly. Do
> you consider recursion superfluous?
 
Not superfluous, more of a necessary evil.
 
> And, in general, what's your take,
> is recursion OK or, if another solution (a loop, perhaps) exists,
> recursion should be avoided?
 
My personal opinion (and I accept that it is just an opinion) is that if an obvious loop-based solution of similar complexity exists, recursion should be avoided unless:
i) it's clearly a more elegant fit to the problem domain
ii) you can easily bound the stack space and algorithmic complexity
 
There are definitely cases in hard combinatoric problems where recursion simplifies everything - and any other solution will be almost certainly more complex and less comprehensible.
 
In this case, however, the enumeration is trivial (a string of length 8 from a three-symbol alphabet). You don't need recursion to do that, any more than you do to print the numbers from 100 to 0 counting backwards, or print the binary representation of a positive integer.
gwowen <gwowen@gmail.com>: Jun 19 01:26PM -0700

On Friday, June 19, 2015 at 5:17:49 PM UTC+1, Stefan Ram wrote:
> 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).
 
I agree with everything Stefan wrote.
bartekltg <bartekltg@gmail.com>: Jun 20 12:45AM +0200

On 19.06.2015 17:51, gwowen wrote:
>>> [..]
 
>> It is actually gratifying to see that all solutions are quite similar.
 
> Maybe, but I am slightly amazed how many of them use recursion.
 
This may be measurement error, but it looks like my
recursion solution is 30% faster than yours (on my
computer, complicator etc.)
Other things than recursion vs. loops were more important
(for example, complexity: O(3^n) instead of O(n*3^n))
 
I think I should rewrite it to get rid of recursion,
and check, if it will run faster.
 
 
bartekltg
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
David Brown <david.brown@hesbynett.no>: Jun 20 12:41AM +0200

On 19/06/15 21:41, Stefan Ram wrote:
> 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/!
 
pH is indeed the abbreviation for pico Henries, though inductors are
seldom smaller than a few nH. You might use pH for the inductance of
wires, chip pins/balls, pcb vias, etc.
 
Usually it's clear in the context what you mean by pH.
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/!
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
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: