Bubbles_glow

≡ Literary Systems ≡

 
Corner_fold
  • Citation
  • Extension
  • Response
  • Comment
 
Flowchart_grey_24

The Use of Metaphor in Code

Because the act of programming is the construction of purely abstract ideas and algorithms, code has always been fertile ground for a wide variety of metaphors. Without metaphors, it would be far more difficult to think about and relate to code on a human scale. Metaphors are often key points in the literary design of programs, giving us a mental handle on the highly abstract structures whizzing about inside of the machine. Here's a brief parade of some of the famous ones:

Desktops, windows, documents, trees, branches, leaves, queues, loops, methods, objects, memory, actors, visitors, factories, bridges, decorators, facades, observers, proxies, virtual machines.

Each of these metaphors provides a vivid model of the work being done by the code. They lend conceptual integrity to the structures, allowing us to think about them in relation to objects with which we already have experience. Metaphor choice becomes a kind of art, as the naming of different conceptual models can lead to different discoveries or innovations. When dealing with the very abstract, the labels that you use take on a heightened importance, because they are the only handle that you have on the thing itself.

However, because counterintuitive ways are often the best ways in engineering, software metaphors are more useful as a searchlight then a roadmap. The nastiest programming errors are the conceptual ones — by their very nature, lying outside of the metaphor's domain, they are nearly impossible to see. Sometimes paradigms will begin to conflict without anyone being aware of it. A method, for a programmer trained in mathematics, can be used like a mathematical function. You insert a value and the value is transformed and returned without side effects. The discipline of functional programming is based on this idea. But programmers who come from backgrounds in the humanities understand methods as being like verbs. With objects as nouns, the two come together to make complete sentences. Friction happens when these two mindsets come together.