Recursive code failure
-
I needed some quick irc bot for testing, and I thought using my already working lamp system for that would be enough.
It kept crashing when there was trouble testing with the connection so I looked in the code.
I found this in the smartIRC 1.0.0 pear lib.function reconnect(...)
{
...
// doesn't work somehow.... I only want to retry 4 times! no endless loop (causes segfault)
static $tries = 0;
if ($this->_autoretry == true && $tries < 5) {
$this->reconnect();
$tries++;
} else {
die();
}
...
}
I don't know what kills me, the fact that this is released as 1.0.0-stable, or the fact that, yes, the author actually found it crashing, knew it went in an endless loop, read the code, and yet didn't found what was wrong (thus the comment). I hope he read "recursive coding for dummies" before porting his project to dot net ...
(and yeah, using php for an irc bot is a WTF all by itself, I know)
-
@lepidosteus said:
I needed some quick irc bot for testing, and I thought using my already working lamp system for that would be enough.
It kept crashing when there was trouble testing with the connection so I looked in the code.
I found this in the smartIRC 1.0.0 pear lib.function reconnect(...)
{
...
// doesn't work somehow.... I only want to retry 4 times! no endless loop (causes segfault)
static $tries = 0;
if ($this->_autoretry == true && $tries < 5) {
$this->reconnect();
$tries++;
} else {
die();
}
...
}
I don't know what kills me, the fact that this is released as 1.0.0-stable, or the fact that, yes, the author actually found it crashing, knew it went in an endless loop, read the code, and yet didn't found what was wrong (thus the comment). I hope he read "recursive coding for dummies" before porting his project to dot net ...
(and yeah, using php for an irc bot is a WTF all by itself, I know)Well, you can't blame the author. Recursion is just so hard. How was he or she to know that the correct version was to do this?
function reconnect(...) { static $tries = 0; for (;$tries < 5; ++$tries) { $this->reconnect(); } ...reconnect code... }
-
@bstorer said:
@lepidosteus said:
I needed some quick irc bot for testing, and I thought using my already working lamp system for that would be enough.
It kept crashing when there was trouble testing with the connection so I looked in the code.
I found this in the smartIRC 1.0.0 pear lib.function reconnect(...)
{
...
// doesn't work somehow.... I only want to retry 4 times! no endless loop (causes segfault)
static $tries = 0;
if ($this->_autoretry == true && $tries < 5) {
$this->reconnect();
$tries++;
} else {
die();
}
...
}
I don't know what kills me, the fact that this is released as 1.0.0-stable, or the fact that, yes, the author actually found it crashing, knew it went in an endless loop, read the code, and yet didn't found what was wrong (thus the comment). I hope he read "recursive coding for dummies" before porting his project to dot net ...
(and yeah, using php for an irc bot is a WTF all by itself, I know)Well, you can't blame the author. Recursion is just so hard. How was he or she to know that the correct version was to do this?
function reconnect(...)
{
static $tries = 0;
for (;$tries < 5; ++$tries)
{
$this->reconnect();
}
...reconnect code...
}perhaps a
function reconnect(...) {
for ($i=0;$i<5;$i++) {
if ($success) return true;
.. reconnect code ...
}
return false;
}Would have sufficed.
no recursion though.
-
@stratos said:
@bstorer said:
@lepidosteus said:
I needed some quick irc bot for testing, and I thought using my already working lamp system for that would be enough.
It kept crashing when there was trouble testing with the connection so I looked in the code.
I found this in the smartIRC 1.0.0 pear lib.function reconnect(...)
{
...
// doesn't work somehow.... I only want to retry 4 times! no endless loop (causes segfault)
static $tries = 0;
if ($this->_autoretry == true && $tries < 5) {
$this->reconnect();
$tries++;
} else {
die();
}
...
}
I don't know what kills me, the fact that this is released as 1.0.0-stable, or the fact that, yes, the author actually found it crashing, knew it went in an endless loop, read the code, and yet didn't found what was wrong (thus the comment). I hope he read "recursive coding for dummies" before porting his project to dot net ...
(and yeah, using php for an irc bot is a WTF all by itself, I know)Well, you can't blame the author. Recursion is just so hard. How was he or she to know that the correct version was to do this?
function reconnect(...)
{
static $tries = 0;
for (;$tries < 5; ++$tries)
{
$this->reconnect();
}
...reconnect code...
}perhaps a
function reconnect(...) {
for ($i=0;$i<5;$i++) {
if ($success) return true;
.. reconnect code ...
}
return false;
}Would have sufficed.
no recursion though.
Recursion is more elegant, though:function reconnect(..., $i) { if (++$i < 5) { $this->reconnect($i); } ...reconnect code... }
I mean, if you don't want to use recursion, why not just:
function reconnect(...) { //Five times $this->reconnect(); $this->reconnect(); $this->reconnect(); $this->reconnect(); $this->reconnect(); ...reconnect code... }
And yes, I'm kidding.
-
Well the initial thought I think was to set the _autoconnect false when going recursive but was somehow missed... Using recursions in the first place... I don't know... However Bitching about free&open code is just like bitching about gifts. Don't like it? File a bugreport/patch and become part of the solution.
-
@death said:
Well the initial thought I think was to set the _autoconnect false when going recursive but was somehow missed... Using recursions in the first place... I don't know... However Bitching about free&open code is just like bitching about gifts. Don't like it? File a bugreport/patch and become part of the solution.
They don't get a free pass on being derided just because they released the source. Make fun of them first, then fix it. Stupid is stupid, regardless of context.
-
@death said:
However Bitching about free&open code is just like bitching about gifts.
Dude, if someone gives you a gift, and you take it home all excitedly and untie the string and tear off all the wrapping paper and inside it there's a box and you open the box and inside the box is your gift....... and your 'gift' is a lump of wet turd ...
... you're still entitled to bitch about it even though it was free.
@death said:
Don't like it? File a bugreport/patch and become part of the solution.
BUG REPORT #0001
Subject: Gift.
Problem description: It's a lump of turd, dude. Shit through-and-through.
How do you 'patch' that?