Interactive programming 
Author Message
 Interactive programming

Just out of curiousity, how often do you find yourself:

1.) Write ruby in the interactive interpreter
2.) Write ruby in files, occasionally calling the interpreter from a shell
    to test your code



Fri, 18 Nov 2005 09:44:42 GMT  
 Interactive programming
Hi,


Quote:

> Just out of curiousity, how often do you find yourself:

> 1.) Write ruby in the interactive interpreter
> 2.) Write ruby in files, occasionally calling the interpreter from a shell
>     to test your code

I'm a huge fan of irb.  I primarily seem to do 2. but perhaps
more than occasionally.  I tend to keep an irb window open at
all times and frequently try out ideas while writing ruby code
in a file.  I'll do 1. occasionally; I think it's been quick hacks
like some one-off processing of a file that I could just do from
irb and not bother typing into a source file (but more complex
than I wanted to do with -e).

I also on occasion have done a variation of 2. which is to start
IRB at the bottom of my main source file ala:

require 'IRB'
IRB.start

so I can interactively try out objects defined in my main
program....  (I think I've tended to use this variation only
when I haven't had automated unit tests.)

Regards,

Bill



Fri, 18 Nov 2005 10:29:12 GMT  
 Interactive programming

Quote:

> Just out of curiousity, how often do you find yourself:

> 1.) Write ruby in the interactive interpreter
> 2.) Write ruby in files, occasionally calling the interpreter from a
> shell
>     to test your code

I do both, though I use 1. mostly for small programs (no new classes).

I would really like to see Ruby have something like Dr. Scheme -- an
upper window that saves to a file in which one could write classes and
methods (the model) and a lower window that is interactive (the
controller), with the ability to run the code in the upper window in
order to set the environment for the interactive window.

It's possible that FreeRIDE has or will have this, but I haven't yet
set it up because I use a Mac and have not been able to get Fox and
FXRuby working with my preferred Ruby (1.8p2).

Regards,

Mark



Fri, 18 Nov 2005 11:00:37 GMT  
 Interactive programming

Quote:

> Just out of curiousity, how often do you find yourself:

> 1.) Write ruby in the interactive interpreter
> 2.) Write ruby in files, occasionally calling the interpreter from a shell
>     to test your code

You forgot one:

 3.) Pure Test Driven Development, from RubyUnit.

--
  Phlip
    http://www.c2.com/cgi/wiki?TestFirstUserInterfaces



Fri, 18 Nov 2005 12:02:50 GMT  
 Interactive programming

Quote:

> Just out of curiousity, how often do you find yourself:

> 1.) Write ruby in the interactive interpreter
> 2.) Write ruby in files, occasionally calling the interpreter from a shell
>     to test your code

Important:
If you never run Ruby under Windows, skip this post!

DOS shell is rubbish, I use it as a last resort and fear the
sight of a DOS box when it flashes up because it's going
to close before I get to reading what was in it.

I use Ruby Development Environment
http://raa.ruby-lang.org/list.rhtml?name=rde

+ EnglishA.xml language file (while you're there)

It's easy to run irb from within it ...
http://www.rubygarden.org/ruby?RubyDevelopmentEnvironmentExtensions

... but it's hardly necessary because I keep a tabbed page open
(usually called Blank{n} - no need to think of a name or where
to save it), type (e.g.)

  p 6 + 4

hit F5, and the result is displayed in the output window.

If I'm running a script that produces an output file, that file
can be open in another page and if it has changed since the last
time, RDE asks if I want to reload it.  Click YES and there's the
updated output from the script I just ran.
I can have several scripts "in progress", cut and paste chunks
from one to another etc. and test bits before "committing".

If someone posts an irb script, I can copy it into an edit page
and use the RDE RunBy facility to convert it with this Ruby snippet:

ARGF.each{|lin|
  if lin =~ /\s*irb\(\w+\):\d{3}:\S+\s/
    print $'
  else
    print '#.->', lin
  end

Quote:
}

I don't really need it to be any easier than that.

No doubt there are some slick Vi(m) / Emacs setups out there
and I like the FreeRIDE project's aims and values:
http://www.rubyide.org/cgi-bin/wiki.pl

Irb is brilliant, and I don't think I would have
stayed with Ruby had it not been available at the start
but IMHO, it's not for coding with.

daz



Fri, 18 Nov 2005 12:41:40 GMT  
 Interactive programming

Quote:

> Just out of curiousity, how often do you find yourself:

> 1.) Write ruby in the interactive interpreter
> 2.) Write ruby in files, occasionally calling the interpreter from a shell
>     to test your code

i always have an irb window open, but code in files (sometimes i even have
tests! ;-) )

mostly i do stuff like this in the irb window:

  > require 'postgres'
  > PGConn.new # oops error
  > PGconn.new # ah yes - that's how it's spelled

also i often do this

  > require 'rbtree'
  > (RBTree.new.methods - Object.new.methods).sort

or

  > object.methods
  > object.constants

or

  > class Foo; FOO = 42; end
  > class Bar < Foo; end
  > Bar::FOO # does this work?

or sometimes

  > require 'class_in_progress'
  > ClassInProgress.method args # repeat these two many times...

  instead of using the 'if $0 == __FILE__' bit...

you get the idea.  i also do a lot of database manipulate in irb instead of
the native rdbms shell...

in summary - i love irb.

-a
--
  ====================================
  | Ara Howard
  | NOAA Forecast Systems Laboratory
  | Information and Technology Services
  | Data Systems Group
  | R/FST 325 Broadway
  | Boulder, CO 80305-3328

  | Phone:  303-497-7238
  | Fax:    303-497-7259
  | ~ > ruby -e 'p % ^) .intern'
  ====================================



Fri, 18 Nov 2005 12:45:27 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. interactive program optimization for a pure declarative language

2. Controlling an interactive program from Ruby

3. KINDA STUCK IN RMCOBOL(RMCOSTAR) PC INTERACTIVE PROGRAM

4. interactive programming

5. Interactive programs through Popen3

6. partial interactive program

7. exec an interactive program / standard output redirection

8. interactive program execution

9. Logging (recording) an interactive program session

10. command pipeline I/O to interactive program?

11. Dealing with interactive programs

12. How to call interactive programs from TCL

 

 
Powered by phpBB® Forum Software