Paul Carvalho wrote:
> I hardly think that bringing up the difference between global and 
> instance variables to someone who doesn't know how to start IRB is a 
> good idea right now.  I think you should follow your own advice and 
> keep things simple right now.
>
> I don't consider myself a newb anymore but I still can't be bothered 
> working out the difference between global and instance variables in my 
> scripts.  $ie works quite nicely for me and I am really not interested 
> in sorting out the difference right now.  Global/class/instance/local 
> variables all have their place and everyone has their own ideas about 
> how to use them based on their level of programming experience.  Do 
> you really think this is the right time to spring them on David?
I concur with this advice. I usually teach global variables first (these 
start with "$") and then local variables (no special marking). I don't 
get into instance variables (start with "@") until we actually have an 
object, like for example a test case in a testing framework, which 
provides the context for understanding the scope of the instance variable.

When i taught testers Python, i started with local variables and this 
worked well, but there are subtle but significant differences to how the 
two languages handle toplevel "local" scope that push me to start with 
globals in Ruby. A local variable at "top level" in Python had the same 
context whether in the shell, in the current file being executed or in 
another file being loaded. These are all different contexts in Ruby, and 
i try to encourage testers early on to be able to trust that code 
executed in any of these ways will do the same thing, but this is only 
true of they use global variables.

Bret


_______________________________________________
Wtr-general mailing list
Wtr-general@rubyforge.org
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to