Upgrading Your REPL24 Nov 2015
Read, evaluate, print, loop. A simple tool at the end of it all. Most languages come with one. Node, Ruby, and Python all have one. Even Lisp and Haskell come with them. There are even attempts at Java and C# ones. However, the default REPL is a little lackluster. All it usually does is read, evaluate, print, and loop, after all. There’s no autocomplete and no syntax highlighting, two features I greatly enjoy.
or is there…
For some reason, my install already had autocomplete enabled. If that
isn’t the case for you, create a file
.irbrc in the
directory and add the following line:
Suddenly, auto-complete! It also adds auto-indentation for blocks. Now, this is nice, but syntax highlighting would be nice, too. Unfortunately, there doesn’t seem to be a way to add this in a default Ruby install.
Fortunately, there is
Have you heard of pry yet? Not only is it a fantastic REPL
with auto-complete by default, but also syntax highlighting. It
also has a handful of functions built-in to ease developer life.
Want some documentation?
show-method are there
for you. Not enough? There are a number of plugins to help.
binding.pry in your code, and instantly pause at that
line. The gem
pry-nav adds some commands to step, continue, etc.
like a proper debugger.
There are tonnes of other plugins, check them out.
The story is very similar in python as well. Add a snippet to a
.pythonrc file, and we have auto-complete.
try: import readline except ImportError: print("Module readline not available.") else: import rlcompleter readline.parse_and_bind("tab: complete") from imp import reload
NOTE: If you’re on Windows, you’ll have to
pip install pyreadline, but don’t change the original snippet.
Syntax highlighting: Ruby has
pry, and Python has
Recently, IPython split into a [few smaller projects]5], which is a good thing! This means that there is less crud on your system! (Unless you want the crud, no judging. jupyter does look cool.)
If you thought
pry had a lot of features, you have to check out
Sure, it has syntax highlighting, but there is so much more. So much more, in fact, that I’m not even going to explain it here. I’ll let them do that for themselves.
Is there an upgraded Node REPL out there? You bet. You could even make your own from all the NPM packages out there.
REPLs deserve upgrading, and you deserve an upgraded REPL.