Introducing The Hacking Sandbox

When I started programming in Python long ago, one of the features which really hooked me up was the quality interactive interpreter offered with the language implementation. It was (and still is) a fantastic way to experiment with syntax, semantics, modules, and whatnot. So much so that many first-class Python practitioners will happily tell you that the interactive interpreter is used not only as a programming sandbox, but many times as the their personal calculator too. This kind of interactive interpreter is also known as a REPL, standing for Read Eval Print Loop, and many languages have pretty advanced choices in that area by now.

After much rejoice with Python’s REPL, though, and as a normal human being, I’ve started wishing for more. The problem has a few different levels, which are easy to understand.

First, we’re using Python Twisted in Ensemble, one of the projects being pushed at Canonical. Twisted is an event-driven framework, which among other things means it works a lot with closures and callbacks. Having to redefine multi-line functions frequently to drive experiments isn’t exactly fun in a line-based interactive interpreter. Then, some of the languages I’ve started playing with, such as Erlang, have limited REPLs which differ in functionality significantly compared to what may be done in a text file. And finally, other languages I’ve been programming with recently, such as Go, lack a reasonable REPL altogether (there are only unusable hacks around).

Alright, so here is the idea: what if instead of being given an interactive REPL, you were presented with your favorite text editor, and whenever you wrote the file down, it was executed and results presented? That’s The Hacking Sandbox, or hsandbox. It supports 11 different programming languages out of the box, and given its nature it should be trivial to support any other language.

Here is a screenshot to clarify the idea:

Note that if you open a sandbox for a language like C or Go, the skeleton of what’s needed to run a program will already be in place, so you just have to “fill the blanks”.

For more details and download information, please check the hsandbox web page.

10 thoughts on “Introducing The Hacking Sandbox

  1. Gustavo Niemeyer Post author

    Neat, I hadn’t seen it. Certainly feels like it would help with some of the described problems related to multi-line input.

    Thanks for the reference.

  2. Jollyplum

    Nice, I’m not sure if you’ve seen ipython :
    http://ipython.scipy.org/moin/
    Just for python, however it has a plethora of functionality.
    One of the slickest things for me, is its interoperability with an editor.
    You just type :
    %edit
    In the interactive prompt and it will load up vim (configurable) and you can hack away to define a function or some code to be executed.
    Press return and the whole lot is fed directly into the current interactive sessions.
    It even works the other way round :
    %edit some_function
    brings up the code defining that function.

    Beyond that, interactive history, tab completion, ability to write bash with one escape character and pipe the output to a flexible object, a distributed computing solution and much much more :)

  3. Filipe La Ruina

    Great! Probably going to fork it to add some more language support (PHP).
    Great idea!

  4. Gustavo Niemeyer Post author

    @Jollyplum, thanks for the notes. I did know about ipython, but not about that editing feature you described. Sounds very interesting indeed.

    @Filipe, great to hear. Please submit a pull request once you have something.

  5. Facundo Batista

    Jollyplum: ipython is a very (very) good tool, indeed.

    However, for any non-English speaker, is quite unusable.

    This is because we tend to use or experiment with non-ASCII strings, and Unicode is broken in ipython. And not broken in a way that crashes, but in a way to produces the wrong results (which is worse).

    For further reference, see http://bugs.launchpad.net/bugs/339642

  6. Sidnei da Silva

    Hi Gustavo,

    I’ve just participated on my first Coding Dojo and we lacked a bit of a proper setup. Then I realized that your hsandbox project could potentially be something to build upon. Two things would be needed: a countdown timer and test results output. I guess that would be pretty easy to add, but haven’t looked at the implementation. What do you think?

    Another idea I had (not related to the Dojo) was to integrate some VCS and save a new revision for each execution. Could be very handy.

  7. Gustavo Niemeyer Post author

    Hey Sidnei,

    Tweaking hsandbox for handling Dojos certainly sounds like a very interesting idea, but it’d probably deserve a fork. The goal of hsandbox is really to serve as a playground for experimenting with snippets, so I’d rather not diverge too much from it at this point.

    Regarding VCS support, though, it does sound like a neat enhancement in line with its purpose. If you have any interest in pursuing it soonish, it’d probably nice to support it through a generic “commit hook” which enables the user to plug whatever VCS is desired. Something that just does, e.g. “bzr commit …”.

  8. Amit Kumar

    I think you are looking for DreamPie

    I have used it for a couple years exactly for this reason. Hacking short, but multiline functions, is part of just about all code development I do. I wish I had something similar for Go.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>