librelist archives

« back to archive

Different behaviour between red shoes builds and green shoes on where methods should be defined

Different behaviour between red shoes builds and green shoes on where methods should be defined

From:
Tobias Pfeiffer
Date:
2011-09-15 @ 13:45
Hi all,

I think I stumbled upon something interesting, let's consider this 
(simplified example):

Shoes.app do
   flow do
     menu
     content
   end
end

def menu
   # do stuff
end

It works for me on my red shoes build (Linux, straight from develop). 
However it didn't seem to work for Greg, who also built it from develop 
for OSX. Neither does it work for me on green_shoes. Error something 
like this: undefined local variable or method `menu' for 
#<Shoes::App:0x00000002310f18> (NameError)

If you switch it up however:

def menu
   # do stuff
end

def content
   # do even more stuff
end

Shoes.app do
   flow do
     menu
     content
   end
end

It seems to work (waiting for feedback from Greg but it does with green 
shoes for me). Do I miss something or is this really strange that it 
worked for me but not for Greg or green shoes?

On a sidenote, are there any resources on how to break up shoes code in 
smaller pieces? I'd like to have a separate file for each window/view 
(so the things you visit via URLs - however I'll try to refactor my code 
to use urls next).

Thanks for the attention!
Tobi

Re: [shoes] Different behaviour between red shoes builds and green shoes on where methods should be defined

From:
ashbb
Date:
2011-09-15 @ 14:15
Hi Tobi,

Yeah, good point. ;-)

I don't know about Red Shoes for OSX, sorry.
But I can explain Red Shoes for Windows and Green Shoes.

At first, try out this snippet. This is not a Shoes app, just a ruby code.

  # snippet1.rb
  hello
  def hello; puts 'hello' end

  # snippet2.rb
  def hello; puts 'hello' end
  hello

Yes, snippet1 shows you an error (NameError). Snippet2 works well.
Green Shoes is the same. Green Shoes executes the code in order from the
first line.

But Red Shoes (at least for Windows) reads the whole file (in this case
snippet1.rb or snippet2.rb) at onece and parses a little bit before runs the
first line.
So, Red Shoes can find the menu method.

> are there any resources on how to break up shoes code in smaller pieces?
I like to use module like this.

  # hello.rb
  module Hello
    def hello msg
      para msg
    end
  end

  # hello_on_shoes.rb
  require 'green_shoes'
  require './hello'
  Shoes.app do
    extend Hello
    3.times{hello 'hello'}
  end

Cheers,
ashbb

Re: [shoes] Different behaviour between red shoes builds and green shoes on where methods should be defined

From:
Tobias Pfeiffer
Date:
2011-09-15 @ 20:48
Hey ashbb,

thanks for the answer I was kind of suspecting that and changed my code 
so it worked... it's too bad that it is that way, because this way I 
have to organize my code bottom up. So my most low level methods first 
and than my high level methods, usually I like to have it the other way 
around. I guess it can't be helped then.

Thanks for the tip on breaking up code!

Tobi

On 09/15/2011 04:15 PM, ashbb wrote:
> Hi Tobi,
>
> Yeah, good point. ;-)
>
> I don't know about Red Shoes for OSX, sorry.
> But I can explain Red Shoes for Windows and Green Shoes.
>
> At first, try out this snippet. This is not a Shoes app, just a ruby code.
>
>     # snippet1.rb
>     hello
>     def hello; puts 'hello' end
>
>     # snippet2.rb
>     def hello; puts 'hello' end
>     hello
>
> Yes, snippet1 shows you an error (NameError). Snippet2 works well.
> Green Shoes is the same. Green Shoes executes the code in order from the
first line.
>
> But Red Shoes (at least for Windows) reads the whole file (in this case
> snippet1.rb or snippet2.rb) at onece and parses a little bit before runs the
> first line.
> So, Red Shoes can find the menu method.
>
>   >  are there any resources on how to break up shoes code in smaller pieces?
> I like to use module like this.
>
>     # hello.rb
>     module Hello
>       def hello msg
>         para msg
>       end
>     end
>
>     # hello_on_shoes.rb
>     require 'green_shoes'
>     require './hello'
>     Shoes.app do
>       extend Hello
>       3.times{hello 'hello'}
>     end
>
> Cheers,
> ashbb
>