For scripting languages, what is the most effective way to utilize a console when developing? Are there ways to be more productive with a console than a ‘compile and run’ only language?
Added clarification: I am thinking more along the lines of Ruby, Python, Boo, etc. Languages that are used for full blown apps, but also have a way to run small snippets of code in a console.
Well for Ruby the
irbinteractive prompt is a great tool for ‘practicing’ something simple. Here are the things I’ll mention about the irb to give you an idea of effective use:Automation. You are allowed a
.irbrcfile that will be automatically executed when launching irb. That means you can load your favorite libraries or do whatever you want in full Ruby automatically. To see what I mean check out some of the ones at dotfiles.org.Autocompletion. That even makes writing code easier. Can’t remember that string method to remove newlines?
''.ch<tab>produces chop and chomp. NOTE: you have to enable autocompletion for irb yourselfDivide and Conquer. irb makes the small things really easy. If you’re writing a function to manipulate strings, the ability to test the code interactively right in the prompt saves a lot of time! For instance you can just open up irb and start running functions on an example string and have working and tested code already ready for your library/program.
Learning, Experimenting, and Hacking. Something like this would take a very long time to test in C/C++, even Java. If you tried testing them all at once you might seg-fault and have to start over.
Here I’m just learning how the
String#[]function works.Testing and Benchmarking. Now they are nice and easy to perform. Here is someone’s idea to emulate the Unix
timefunction for quick benchmarking. Just add it to your.irbrcfile and its always there!Debugging – I haven’t used this much myself but there is always the ability to debug code like this. Or pull out some code and run it in the irb to see what its actually doing.
I’m sure I’m missing some things but I hit on my favorite points. You really have zero limitation in shells so you’re limited only by what you can think of doing. I almost always have a few shells running. Bash, Javascript, and Ruby’s irb to name a few. I use them for a lot of things!