(working title)
Concept
Most of programming involves reading lots of source code, until the context of the system has been loaded into your brain, and then making changes.
What if you could just tell the IDE what bit of code you wanted to understand, and all the dependencies would magically materialize before your eyes?
A contextual programming environment would allow a running system to be inspected so that the programmer could understand where all the pieces fit, what interacted with what, etc.
In addition, the author (or another friendly programmer) could anticipate your difficulty in understanding a bit of code and create pre-setup "perspectives" which show a useful slice of the system, with annotations, for easy digestion.
Twisted Example
Here's an example of a seemingly sensible, but once you try to read it, a quite contextless piece of code:
1 class ProxyRequest(http.Request): 2 """Used by Proxy to implement a simple web proxy.""" 3 4 protocols = {'http': ProxyClientFactory} 5 ports = {'http': 80} 6 7 def process(self): 8 parsed = urlparse.urlparse(self.uri) 9 protocol = parsed[0] 10 host = parsed[1] 11 port = self.ports[protocol] 12 if ':' in host: 13 host, port = host.split(':') 14 port = int(port) 15 rest = urlparse.urlunparse(('','')+parsed[2:]) 16 if not rest: 17 rest = rest+'/' 18 class_ = self.protocols[protocol] 19 headers = self.getAllHeaders().copy() 20 if not headers.has_key('host'): 21 headers['host'] = host 22 self.content.seek(0, 0) 23 s = self.content.read() 24 clientFactory = class_(self.method, rest, self.clientproto, headers, 25 s, self) 26 reactor.connectTCP(host, port, clientFactory)
This implements a web proxy in Twisted, and I can run it and it works.
Of course, I have no idea what's going on. When I look at the source code, I say: "What the hell? Where are all these variables coming from? What the hell is class_? Where in god's name am I?! What is this doing?!!?"
Authorization Example
Authorization is an example of a problem where you want code to show up in two places at once. Take a look at this snippet from Rails' Declarative Authorization library:
A simple example, but already you can see that it's hard to know if you've specified all of the methods that need to be protected, since the code is in a different file from the controllers that it's protecting.
Ideally, you'd want two perspectives. An overview:
Controller: Whatever Methods: a, b, c, d, e Role Steve: a, b, c, e Role Admin: * Role Guest: a, c
And an Inline view in the controller, so you could see who has access to each method:
Inspecting Exceptions
When developing in a dynamic language, exceptions can suddenly be spawned from anywhere in the system and fly into your code's face, causing it to terminate.
The two approaches are to catch too many exceptions and log them, so that your program doesn't accidentally quit, or do lots of testing.
Better solution: inspect the program and show the programmer all possible exceptions that could be thrown; the programmer can choose which ones to catch and handle.
