[BUG?] Behavior of application changes when adding non-relevant puts

Hi.

Seems I ran into a Heisenbug - the behaviour of my application changes
when I add or remove non-relevant code somewhere - seems it doesn’t
really matter where. For that reason I can’t really debug or isolate the
bug. :confused:

I’ve uploaded the application at:

http://noegnud.sf.net/flgr/foobar.tar.gz

It’s about 630 lines. It’s a incomplete framework for (german)
textadventures (sorry about the german text - all classnames etc. are
english tho)

At basicthing.rb:315 I added a puts which made the program work:

flexo@majestix foobar $ ruby gold.rb

n
{:ipreps=>, :verb=>[“s\374den”, “s”], :dpreps=>} (sueden == south)
{:ipreps=>, :verb=>[“norden”, “n”], :dpreps=>} (norden == north)
Heisenbug!
Du bist in einem dichtem Nadelwald. (This is the description of the new
room - the player went to north)

The loop at basicthing.rb:248-323 is supposed to iterate through all
actions until it finds a matching one (checking the prepositions and
number of objects) and then executes the action’s proc.

(The action for “n” (short for “Norden” - north in german) is defined
at evolution.rb:20.)

When I remove basicthing.rb:315 I get:

n
{:ipreps=>, :verb=>[“i”, “inv”, “inventar”], :dpreps=>}
{:ipreps=>, :verb=>[“osten”, “o”], :dpreps=>}
{:prefix=>[“runter”, “herunter”, “raus”, “heraus”], :ipreps=>[“vom”,
“von”, “aus”], :verb=>[“n”, “nimm”, “nehm”, “nehme”], :iobj=>:optional,
:dobj=>:required, :dpreps=>}
{:ipreps=>, :verb=>[“unten”, “u”], :dpreps=>}
{:ipreps=>, :verb=>[“s\374den”, “s”], :dpreps=>}
{:ipreps=>, :verb=>[“norden”, “n”], :dpreps=>}
{:ipreps=>, :verb=>[“oben”, “ob”], :dpreps=>}
{:ipreps=>, :prefix=>[“um”], :verb=>[“schau”, “schaue”],
:dobj=>:optional, :dpreps=>}
{:ipreps=>, :prefix=>[“hin”, “rein”, “herein”], :verb=>[“geh”,
“gehe”], :dobj=>:required, :dpreps=>[“nach”, “zum”, “zu”, “in”]}
{:ipreps=>, :verb=>[“westen”, “w”], :dpreps=>}
Ich verstehe nicht.

(“Ich verstehe nicht” == “I don’t understand” - no matching action could
be found)

As you can see it did check for the “move north” action:

{:ipreps=>, :verb=>[“norden”, “n”], :dpreps=>}

But for some reason it decided that it doesn’t match. I can’t figure out
why since adding debug-statements breaks/unbreaks it again…

Actually the “puts” doesn’t really matter - removing or adding more
rooms or objects causes the behaviour to change, removing properties of
objects does, hell, even changing the (ignored) return-value of some
#properties methods does.

Running it with -d also makes the bug go away for me.
So does set_trace_func().

Someone in #ruby-lang reported the opposite behaviour with the same code
(breaks with the puts, runs fine without) and different behaviour
between different ruby versions.

22:41 <@dblack> fn: you can use me as a witness if you want :slight_smile:

I’m not doing really exotic stuff so… looks like a ruby-bug for me.

Would be nice if someone would take a look at it.

-flexo

Felix Nawothnig wrote:

Seems I ran into a Heisenbug - the behaviour of my application changes
when I add or remove non-relevant code somewhere - seems it doesn’t
really matter where. For that reason I can’t really debug or isolate the
bug. :confused:

I took a very quick look at it.

Ruby outputs lots of warnings… what about getting rid of these first?
Output attached. You way want to set the RUBYOPT environmentvar = ‘w’

Another thing is that you make heavy usage of the upper ASCII range 128-255,
this may cause different behavier with different locale.

Sorry, I couldn’t find the bug.

···


Simon Strandgaard

ruby -w gold.rb
./basicthing.rb:106: warning: (…) interpreted as grouped expression
./noun.rb:61: warning: `*’ interpreted as argument prefix
./noun.rb:4: warning: method redefined; discarding old noun
./noun.rb:12: warning: method redefined; discarding old syn
./basicthing.rb:153: warning: instance variable @dark not initialized
Du befindest dich in einem dichtem Fichtenwald. Es hat gerade geregnet und Wasser tropft von den Bäumen. Die Erde unter dir ist aufgewichen und du hinterläßt sichtbare Spuren in ihr.
Ich kann nach: Osten, Norden, Westen, Süden

Hi,

Are you on Windows? What version of Ruby?

C:\t_\luciana\foobar>ruby -v
ruby 1.8.2 (2004-05-19) [i386-mswin32]
Windows 2000

This line:
basicthing.rb:254> words.shift
Deletes the words before they could used as commands.
The @actions is a Hash, which means that what changes
from an execution to another is the order of its
elements. The “Norden” action may come after the
words.first is nil.

If you’re on Windows, a Ruby upgrade may be necessary.

Cheers,
Joao

— Felix Nawothnig felix.nawothnig@t-online.de
wrote:

···

Hi.

Seems I ran into a Heisenbug - the behaviour of my
application changes
when I add or remove non-relevant code somewhere -
seems it doesn’t
really matter where. For that reason I can’t really
debug or isolate the
bug. :confused:


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

Ruby outputs lots of warnings… what about getting rid of these first?

Looked through it - they are not related to my problem. The lines
causing
warnings work exactly as they are supposed to.

Another thing is that you make heavy usage of the upper ASCII range
128-255, this may cause different behavier with different locale.

Maybe it would cause outputting some strange chars - but certaintly not
the problem I’m encountering.

-flexo

···

On 05/30/2004 11:21:58 PM, Simon Strandgaard wrote:

Hi –

This line:
basicthing.rb:254> words.shift
Deletes the words before they could used as commands.
The @actions is a Hash, which means that what changes
from an execution to another is the order of its
elements. The “Norden” action may come after the
words.first is nil.

I don’t think that happens though, because the previous
line is:

  next unless cmd[:verb].include? words.first

so if ‘n[orden]’ isn’t part of cmd, the shifting should
not happen.

But somehow I think you may be onto something with this hash order
thing… One thing I noticed on Ruby 1.8.0 is that it seems to work
with or without the extra line, but the hash order does change.

David

···

On Mon, 31 May 2004, Joao Pedrosa wrote:


David A. Black
dblack@wobblini.net

Felix Nawothnig wrote:

Ruby outputs lots of warnings… what about getting rid of these first?

Looked through it - they are not related to my problem. The lines
causing warnings work exactly as they are supposed to.

Another thing is that you make heavy usage of the upper ASCII range
128-255, this may cause different behavier with different locale.

Maybe it would cause outputting some strange chars - but certaintly not
the problem I’m encountering.

Some other issues I see, which could be dangerous.

‘evolution.rb’, you use bind/call/ancestors in a creative way.
Your Object#evolve are also suspicious.
If I were you I would unittest this file carefully.

‘noun.rb’, Kernel.send/define_method.
Also suspicious to me.

‘basicthing.rb’ send feels kludgy.

It isn’t clear to me what is going on, because of the above
things you are using. I would try to use OOP, rather than
Kernel.send/bind… etc.

···

On 05/30/2004 11:21:58 PM, Simon Strandgaard wrote:


Simon Strandgaard

Except… ‘n’ is an abbreviation of another command (nimm), so the
shift does happen, in the case of ‘n’, even if it shouldn’t. So
your analysis is right, and there’s one ‘n’ option too many :slight_smile:

Fascinating Heisenbug – the size of the file seems to change the hash
return order, which in turn determines whether this problem will or
will not bite.

David

···

On Mon, 31 May 2004, David A. Black wrote:

Hi –

On Mon, 31 May 2004, Joao Pedrosa wrote:

This line:
basicthing.rb:254> words.shift
Deletes the words before they could used as commands.
The @actions is a Hash, which means that what changes
from an execution to another is the order of its
elements. The “Norden” action may come after the
words.first is nil.

I don’t think that happens though, because the previous
line is:

  next unless cmd[:verb].include? words.first

so if ‘n[orden]’ isn’t part of cmd, the shifting should
not happen.


David A. Black
dblack@wobblini.net

Hi –

Simon Strandgaard neoneye@adslhome.dk writes:

Felix Nawothnig wrote:

Ruby outputs lots of warnings… what about getting rid of these first?

Looked through it - they are not related to my problem. The lines
causing warnings work exactly as they are supposed to.

Another thing is that you make heavy usage of the upper ASCII range
128-255, this may cause different behavier with different locale.

Maybe it would cause outputting some strange chars - but certaintly not
the problem I’m encountering.

Some other issues I see, which could be dangerous.

‘evolution.rb’, you use bind/call/ancestors in a creative way.
Your Object#evolve are also suspicious.
If I were you I would unittest this file carefully.

‘noun.rb’, Kernel.send/define_method.
Also suspicious to me.

‘basicthing.rb’ send feels kludgy.

It isn’t clear to me what is going on, because of the above
things you are using. I would try to use OOP, rather than
Kernel.send/bind… etc.

Not a big fan of introspection and/or intercession, I guess :slight_smile: In any
case I think there’s more to it than this – after all, those are
perfectly legitimate Ruby techniques, and although they can be used
incorrectly, using them does not fully explain why this change:

$ diff basicthing.rb basicthing.rb.changed
315c315
< #puts “Heisenbug!”

···

On 05/30/2004 11:21:58 PM, Simon Strandgaard wrote:


                  puts "Heisenbug!"

would cause a dramatic difference in runtime behavior (in Ruby 1.8.1).
If Ruby’s comment-parsing changes as a result of using send, I think
it’s in everyone’s interest to be aware of this :slight_smile:

(Not that I know exactly what’s happening – I wish I did – still
scrutinizing it…)

David


David A. Black
dblack@wobblini.net

Hi,

Hi –

Simon Strandgaard neoneye@adslhome.dk writes:

Felix Nawothnig wrote:

Ruby outputs lots of warnings… what about
getting rid of these first?

Looked through it - they are not related to my
problem. The lines
causing warnings work exactly as they are
supposed to.

Another thing is that you make heavy usage of
the upper ASCII range
128-255, this may cause different behavier
with different locale.

Maybe it would cause outputting some strange
chars - but certaintly not
the problem I’m encountering.

Some other issues I see, which could be dangerous.

‘evolution.rb’, you use bind/call/ancestors in a
creative way.
Your Object#evolve are also suspicious.
If I were you I would unittest this file
carefully.

‘noun.rb’, Kernel.send/define_method.
Also suspicious to me.

‘basicthing.rb’ send feels kludgy.

It isn’t clear to me what is going on, because of
the above
things you are using. I would try to use OOP,
rather than
Kernel.send/bind… etc.

Not a big fan of introspection and/or intercession,
I guess :slight_smile: In any
case I think there’s more to it than this – after
all, those are
perfectly legitimate Ruby techniques, and although
they can be used
incorrectly, using them does not fully explain why
this change:

$ diff basicthing.rb basicthing.rb.changed
315c315
< #puts “Heisenbug!”

                  puts "Heisenbug!"

would cause a dramatic difference in runtime
behavior (in Ruby 1.8.1).
If Ruby’s comment-parsing changes as a result of
using send, I think
it’s in everyone’s interest to be aware of this :slight_smile:

(Not that I know exactly what’s happening – I wish
I did – still
scrutinizing it…)

I think it’s the Hash. Specifically, the order of its
elements. By putting some code like

puts “Heisenbug!”

or by removing it

#puts “Heisenbug!”

Ruby can change the order of the Hash elements, thus
causing some bug (which isn’t a bug of Ruby, of course
:slight_smile: to appear.

This is interesting because a “perfect” code can
“become” buggy anytime.

Philosophically, it’s interesting. :slight_smile:

Cheers,
Joao

···

— David Alan Black dblack@wobblini.net wrote:

On 05/30/2004 11:21:58 PM, Simon Strandgaard > wrote:


Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/

Simon Strandgaard neoneye@adslhome.dk writes:
[snip]

It isn’t clear to me what is going on, because of the above
things you are using. I would try to use OOP, rather than
Kernel.send/bind… etc.

Not a big fan of introspection and/or intercession, I guess :slight_smile: In any
case I think there’s more to it than this – after all, those are
perfectly legitimate Ruby techniques, and although they can be used
incorrectly, using them does not fully explain why this change:

I like meta programming/eval with Ruby… However I test things
carefully in order to convince myself that it works correct.
If I see no tests then I am of cause sceptical.

Weird things may occur when instance_eval’ing a randomized string :slight_smile:

···

David Alan Black dblack@wobblini.net wrote:


Simon Strandgaard

I think it’s the Hash. Specifically, the order of its
elements.
By putting some code like

puts “Heisenbug!”

or by removing it

#puts “Heisenbug!”

Ruby can change the order of the Hash elements, thus
causing some bug (which isn’t a bug of Ruby, of course
:slight_smile: to appear.

Yep, that’s it. Thanks very much.

This is interesting because a “perfect” code can
“become” buggy anytime.
Philosophically, it’s interesting. :slight_smile:

Indeed. :slight_smile:

Now, the “real” bug is in my code (ofcourse :slight_smile: - the words list has to
be reset on every iteration. Doh. :slight_smile:

-flexo

···

On 05/31/2004 01:20:50 AM, Joao Pedrosa wrote:

Sorry, gateway test, please ignore.

···


David A. Black
dblack@wobblini.net