Today, I start a new series: The Next Big Thing. I plan to collect all my ideas for the next generation of programming languages.
If you’ve ever worked with I/O in Java, you will have stumbled over the “Closable” API. The idea is simple: If you request a resource from someone, you must tell that someone when you’re done with said resource. Remember garbage collection? That was the very same idea for memory: People eventually forget to free something or free it twice.
Java has two solutions for this problem: Either there is a
close() method of some kind or there is nothing. “What?”, I hear you say, “When doesn’t Java offer nothing if you need to release a resource?” When the resource is allocated in place A and used in place B. Just today, I had an example where I created an
InputStream, wrapped that in an XML
InputSource and passed that to a class in dbunit which would eventually create an XML parser. In a new thread. What was I supposed to close the stream? There was no way to do it since I didn’t create either the thread nor the parser. The code in dbunit couldn’t do it either because the XML API has no way to say “close input when done.”
What I needed was a way to say: When the thread created deep inside dbunit terminates, then close the stream.
Or more abstract: I needed a way to create a piece of code at runtime and attach that to a certain point in the execution flow of my program.
Sounds like AOP, doesn’t it? Yes but AOP comes with two problems which effectively prevent its wide-spread adoption:
- The syntax for cutpoint definition is too complex
- There is no way to get an error if a cutpoint doesn’t exist. I want my compiler to warn me if the code in dbunit changes.
So that’s my first feature of TNBT: Adding code to specific places in existing code with a simple API. This is also known as “patching”. It would solve the copy’n’paste problem (“Oh, that code does almost what I need … let’s copy it and change one line”). Now you can make your compiler copy the code for you.
- The Next Best Thing – Series in my blog where I dream about the future of software development