Monday, February 15, 2016

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

Vir Campestris <vir.campestris@invalid.invalid>: Feb 15 11:11PM

On 15/02/2016 21:33, Ian Collins wrote:
>> My usual answer to that problem is "throw more hardware it"! My trip
>> point for a hardware boost is usually around 30 for a full build...
 
> .. 30 seconds ..
 
My last employer but one our tests took a couple of weeks to run on the
server farm.
 
But then, we knew they weren't comprehensive ;)
 
Andy
Paavo Helde <myfirstname@osa.pri.ee>: Feb 16 01:40AM +0200

On 15.02.2016 23:40, Wouter van Ooijen wrote:
>> you have obtained some more insight after implementing cases 1, 2 and 3
>> you are now (hopefully) able to rewrite them as "n+1".
 
> But why aren't I allowed to do that in the first place?
 
In my book, you can take as large pieces as you are comfortable with and
as long as you are confident that all important functionality gets
sufficiently covered by tests. If Uncle Bob feels himself comfortable
with testing each one-line edit separately then that's his business.
 
 
> That I can totally agree on. But Uncle Bob doesn't seem to admit that
> there are *any* projects where TDD is not useful. Or am I
> misunderstanding him?
 
No idea, I haven't followed him much. What I do know is that TDD is a
tool, not a goal, and that a tool can always be misused or overused.
jt@toerring.de (Jens Thoms Toerring): Feb 15 11:40PM

> Sorry if you find it spam. I think it's a case
> of "One man's trash is another man's treasure."
 
If you add your own stuff to wikipedia it's clearly spam. It's
not for you as the author to decide if it's important enough to
be mentioned, no matter how good or beneficial for others you
may consider it to be. It's up to a happy user to add it if
(s)he feels it's important enough. If you want to get some
exposure go and buy some advertisement space somewhere - mis-
using wikipedia for that is spam as clearly as it gets - it
ticks all the boxes.
 
Never ever touch a page (or have any part in changing it,
except maybe when asked by someone else for details) that
mentions any of your work (or you personally) - even if you
feel the treatment to be wrong or unflattering.
 
What about writing an excellent article about serialization
(that may mention your library in some form) that is helpful
to others, and publish it on your own web site? If it's really
good it will get some good rankings in search engines and may
end up linked to by wikipedia after some time. It's a bit of
work, admittedly, but it's the honest way to go.
 
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 15 09:56PM

On 15/02/2016 21:49, Juha Nieminen wrote:
> other types of input for the data it needs to read. We can now make
> all kinds of abstract "file handle" objects that feed it data from
> whatever other resource that might not be a file.)
 
I am, and I am sure many others are, quite capable of creating
appropriate abstractions without using TDD.
 
/Flibble
Wouter van Ooijen <wouter@voti.nl>: Feb 15 11:59PM +0100

Op 15-Feb-16 om 10:49 PM schreef Juha Nieminen:
> other types of input for the data it needs to read. We can now make
> all kinds of abstract "file handle" objects that feed it data from
> whatever other resource that might not be a file.)
 
TDD might have helped *you* in *this case*, but so would any
design/development method that pays attention to testability. (And on
top of that, any design method that pays attention to abstraction and
re-use).
 
Wouter van Ooijen
"K. Frank" <kfrank29.c@gmail.com>: Feb 15 02:55PM -0800

Hello Christof!
 
I've been tripped up in a similar way using std::function<>.
 
On Friday, February 12, 2016 at 6:17:29 AM UTC-5, Christof Warlich wrote:
 
> It prints 0 instead of 42, and I really don't understand why.
 
> It works fine when I store the std::function object as a copy instead of just storing a reference in my container, i.e. when I remove the ampersend from line 5. But that's not an option because I finally want my operator() to return a result in one of the functors member variables.
 
> I'm obviously having some severe misconception w.r.t. the lifetime of the reference: Can anyone help me to understand what's really going on here?
 
As Alf pointed out and you've concluded, when you call
your Container constructor and pass it a Functor
 
1) the compiler creates a temporary std::function<> that
contains, in essence, a copy of your Functor, and
 
2) when you take a reference to this std::function, you
end up with a dangling reference.
 
What I've done in the past to get the behavior I think
you want is to use std::ref.
 
Here's a modified version of your example that illustrates
this:
 
#include <iostream>
using std::cout;
using std::endl;
 
#include <functional>
 
struct Container {
Container (std::function<void()> functor) : functor_(functor) {}
std::function<void()> functor_;
};
 
struct Functor {
Functor (int i) : i_(i) {}
void operator()() {
cout << i_++ << endl;
}
int i_;
};
 
int main() {
Functor functor(42);
functor();
functor();
Container container(std::ref(functor));
container.functor_();
container.functor_();
functor();
return 0;
}
 
Notice that I've added the i_++, so that the state in
Functor gets modified.
 
I've purposely called functor() and container.functor_()
multiple times to illustrate that you pass the state
contained in functor into container, and that you get the
modified state out again, not only in container.functor_,
but in functor, as well.
 
That is, you really do get reference semantics to your
original functor.
 
Notice that Container now uses value semantics, and that
the client of container has to explicitly use reference
semantics via std::ref to get the desired behavior. This
is presumably an imperfection in Container's interface,
but I think it's the price you have to pay for using
std::function, which is inherently value-based.
 
To comment a little bit further:
 
std::function seems like a great idea -- it holds anything
that "acts like a function." So you can use functions,
explicit function objects, lambdas, etc.
 
But when would you want to use a function object instead of
a plain function? The common reason is because you want your
function object to contain some state. You can use the value
semantics of std::function, and, in effect, make a copy of
your function object if all you want to do is pass state in
(a common use of function objects), but not if you want to
get (mutable) state back out into your original function object.
 
The only way I know how to do this (in a reasonably
straightforward way) with std::function is to make the client
explicitly use reference semantics with std::ref.
 
This seems to be a limitation of std::function (not that I
have a proposal to fix it), and it tripped me up along the
same lines you describe in your post when I first tried to
take advantage of the convenience of std::function.
 
> Thank you so much,
 
> Chris
 
 
Happy Hacking!
 
 
K. Frank
Jerry Stuckle <jstucklex@attglobal.net>: Feb 14 09:43PM -0500

On 2/14/2016 6:35 PM, Chris Vine wrote:
> missed that. But the point is not that ISPs stop port 25 traffic
> leaking out of their system (I have not come across that), but that the
> spam blocker of the next ISP in the link will do so.
 
It is not unusual in the U.S. - and from what I understand, many other
parts of the world.
 
> in town, to dispatch my mail remotely.
 
> I think you need to resist the temptation to show you are clever.
 
> Chris
 
It is *totally* relevant. If he tries to use his code on my (or any of
hundreds of other ISP's in the U.S.), his code will fail miserably. It
may not cause a problem for *you* - but *you* are not every user (or
even a majority of users, if you're in the U.S.) trying to use his code.
 
--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================
Paavo Helde <myfirstname@osa.pri.ee>: Feb 15 09:37AM +0200

On 15.02.2016 3:33, Geoff wrote:
> Windows:
> system("start
 
> mailto:yourname@example.com?subject=Order&body=Order%20details%20here");
 
Yes, ability to open things in a default way (including mail URL-s) is
built into Windows and can be invoked via the start command in the CMD
shell. However, from another program one should prefer ShellExecute()
instead of system(), to avoid a nasty black DOS box on the screen, and
to avoid nasty quoting problems (for example, the '&' in the above URL
must be escaped as '^&' when used in the CMD shell).
 
> system("exec
 
> mailto:yourname@example.com?subject=Order&body=Order%20details%20here");
 
> but I haven't tested this.
 
I haven't either, but the man page looks like this is the way in
X-Windows world:
 
XDG-EMAIL(1)
NAME
xdg-email - command line tool for sending mail using the user's
preferred e-mail composer.
 
And yes, this requires that the user has the ability to send e-mail from
this computer in the first place and the computer has been set up
properly. If there is a doubt the user cannot do this, I would display
the URL and tell the user to copy-paste it into a browser on a machine
where he can send e-mails.
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Feb 15 10:04AM

On Sun, 14 Feb 2016 17:33:02 -0800
> system("exec
 
> mailto:yourname@example.com?subject=Order&body=Order%20details%20here");
 
> but I haven't tested this.
 
OK that does seem to be the way to do it. Excellent. 'xdg-email
--help' gives me this:
 
xdg-email -- command line tool for sending mail using the
user's preferred e-mail composer
 
Synopsis
 
xdg-email [--utf8] [--cc address] [--bcc address] [--subject
text] [--body text] [--attach file] [ mailto-uri | address(es)]
 
So this on a unix-like system would do what he wants:
 
xdg-email --subject Order --body "My order is attached" \
--attach "order-file.txt" order@supplier.net
 
From a cursory look at it I could not get my email client to accept
line breaks in the message body, so attaching a file might work better
for the OP.
 
Chris
Chris Vine <chris@cvine--nospam--.freeserve.co.uk>: Feb 15 10:14AM

On Mon, 15 Feb 2016 10:04:44 +0000
Chris Vine <chris@cvine--nospam--.freeserve.co.uk> wrote:
[snip]
> From a cursory look at it I could not get my email client to accept
> line breaks in the message body, so attaching a file might work better
> for the OP.
 
Ah, it does accept line breaks, it's the shell that's problematic. If
he executes it via 'exec' and cognates rather than 'system' he will
probably be OK.
Geoff <geoff@invalid.invalid>: Feb 15 10:11AM -0800

On Mon, 15 Feb 2016 10:14:26 +0000, Chris Vine
 
>Ah, it does accept line breaks, it's the shell that's problematic. If
>he executes it via 'exec' and cognates rather than 'system' he will
>probably be OK.
 
Thanks for testing that.
 
Ultimately, I'd probably still prefer just planting a URL mailto: or
just a link to a web server for feedback. An http: link has much
greater utility since the form and cgi is under the vendor's control
and doesn't require any support from inside the application, it's
completely portable and can be redirected if necessary to whatever
server the vendor desires. If, as the OP has hinted at, it's some kind
of order where money or a credit card could be involved, it can be
securely transacted as a web form over SSL rather than an email,
especially where the user's identifiable information is going to be
transmitted. This gives the vendor complete flexibility on the web
server to control the form fields or change its purpose. Web servers
are cheap and easily obtained these days, any serious application
would have a web presence an users are inclined to expect it. Email
addresses are transitory and coding one into an application is
probably unwise.
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: