Sculpt Your Code in a REPL - Part One

Do what in a what?

You can use a REPL to sculpt your code. A REPL is a read-eval-print-loop. REPLs exist in all sorts of places and many programming languages have them. The most well known REPL is probably the JavaScript console in Firebug which inspired the JavaScript Console in FireFox and Chrome. The ability to quickly test out bits of code in a "live" environment was one of the major advancements in web development with JavaScript. You have probably used a REPL with dynamic languages like Python and Ruby but even statically typed languages have REPLs now-a-days like the one that ships with F# here and the open source C# based REPL called scriptcs. I would even go as far as calling LinqPad REPL-esque.

Why would I want to use that thing?

Developing in a REPL is like developing in a different world. The immediate execution it offers lets you interact with your code much quicker than a traditional compile-configure-run-click-look-loop (aka CCRCLL). With CCRCLL you are at the mercy of whatever UI is covering your code. The UI generally tends to limit your interactions with the code to certain well worn paths. In the REPL you are interacting with your abstractions directly. Create a stopwatch abstraction and start the timer a tickin'. Create a web-scraper and get a scrapin'. Create a <noun> and start a <verbin>'. This feedback loop of creating a thing and immediately trying it out is powerful. (*cough* TDD *cough*)

I like working in a REPL for certain tasks especially when I am experimenting and trying out different approached to a problem. But it's no silver bullet. By itself the REPL is a tool. It's the potters wheel that turns your clay. Much like the potters wheel it doesn't shape the clay for you but simply provides an environmment or platform from which you do the sculpting.

Pretentiousness alarm triggered. Whoop. Whoop.

Whoa whoa. Whoa. I know what your thinking. The portrait of a developer as a young artist is a bit clichéd and has been beaten to death. But it's my metaphor and I have to find a way to apply all those art classes I took so I am going to use it.

Formed by feedback

Much like the clay pot being formed by the pressure applied by your fingers we need something to apply pressure to our digital creations. Since the magic is happening on the other side of the glass we need a stand-in that can interact with the abtraction directly. You could use a unit test framework but that is too formal for the type of experimenting I like to do in the REPL. Wait. Experimenting is how I would describe the interaction there. Let's see if that checks out.

Seems to check out.

To the Code!

Just kidding. First a little homework. Go play with a REPL - JavaScript, Python, C#, whatever. Then think about what you would build to experiment with code. What would give you the feedback you want? How simple would you make it? How complex? What would the API look like?

Give it some thought and in my next post I will show you what I came up. Happy designing!



comments powered by Disqus

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© 2017 Frank Meola

Back to top