Skip to content

Instantly share code, notes, and snippets.

@JesseAldridge JesseAldridge/
Last active Sep 21, 2018

What would you like to do?

I have a highly simplistic proof of concept:

Right now it's just -- I have these six hardcoded functions:

One of which is just:

class IsLetter(Block):
  def call_(self, ch):
    return ch.isalpha()

Now I can run the following test against all six of the functions and return the one that makes the tests pass:'a') == True'8') == False'#') == False

One obvious problem is different functions take different parameters. The solution of course is to only call functions that have an appropriate signature:

class Block

  def call(self, *a):
    # If the passed arguments match the child class's call signature
    #   Call the child class's call method
    # Otherwise do nothing

What if a function requires initialization before it can be used? Well instead of calling them functions, let's call them "blocks", where block basically means "code module" or "collection of functionality".

class FindAllFiles(Block):
  def init_(self, dir_path):
    # read all the files in the passed directory into an index

  def call_(self, query_string):
    # search the index for the passed `query_string` and return the results

And let's add an initialization step to our test.

def init(block):
  # Create test directory with a couple test files.
  # filename: "test_dir/1.txt"
  # content:  "some text"
  # filename: "test_dir/2.txt"
  # content:  "other text"


  # now do any initialization the block needs to do before being used

def test(block):
  return ('some') == ['test_dir/1.txt'] and'other') == ['test_dir/2.txt'] and'text') == ['test_dir/1.txt', 'test_dir/2.txt'] and'nothing') == []

Ok, cool, so that works. What else can we do with this thing? Can we build a web app? Let's start with "hello world":

function test(block, done) {;
  request('localhost:5000', function (error, response, body) {
    if (!error && response.statusCode == 200) {
      done(body == 'hello world');

This test could be satisfied by this code:

var Hapi = require('hapi');

var server = new Hapi.Server();
    host: 'localhost',
    port: 5000

    method: 'GET',
    handler: function (request, reply) {
        reply('hello world');


Interestingly, this exact code snippet can be found on StackOverflow: (I wrote the test without knowing that.)

Even more interestingly, StackExchange produces regular dumps of their entire database for use by the public:

The vast majority of the code snippets are even conveniently wrapped in <code>...</code> tags, which makes them easy to extract:

If you're still with me, I think you will agree that while there are a ton of obvious problems here, there are also a lot of very exciting possibilities. The most important of which I think is allowing people to obtain functioning software not by explaining in detail how to do something but by describing what the end result should be. Few people have the skills necessary to do the former, but I think just about anyone should be able to do the latter.

So that's where I'm at right now.

The obvious problems I'm thinking about today, as we speak:

How can I install every well known software package in an accessible way?

Actually I lied earlier, the hello world snippet does not exactly match the StackOverflow result. The port number is different and the path is /hello instead of /. So somehow I would need to identify meta-variables in code snippets or something.

How far can I take this approach? I've demonstrated that it can work in trivial cases. But real world code is vastly more complicated than the cases I've described here. I'll have to get back to you on that one...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.