Carbon Refactoring

The logic of carbon pricing is explained by economists as pricing in an externality. The problems of climate change in this view is one of deep insincerity – a computational civilization continually lying to itself about the ecological substrate at its foundational layer. We have been professionally fooling ourselves for decades. Networks of sensors are in place to measure the state of the system but adjustments only weakly feed back. Carbon pricing has sputtered along without entrenching a self-reinforcing process, while container-based political systems, stuck in Westphalian tile-borders, flap unsteadily through variations of supporting legal regimes. This is exacerbated by what Bratton terms the capitalist pricing problem: the tendency for markets to mistake short term liquidity signals for long term plans, or as Keynes put it, “the market can stay irrational longer than you can stay solvent”.

Carbon debt is technical debt. Technical debt is a term coined by Ward Cunningham and widely used and recognizable in software development. It represents the difficulty of working with the accumulated design limitations of a highly mutable system, including bugs, but also many partial and mutually irreconcilable models of the world in code. Working on a legacy system, one ridden with technical debt, is to face a human created artifact which evades human comprehension, let alone control. Carbon is a technical debt megastructure.

Addressing problems of technical debt involves redesign. An important set of software redesign techniques, those changing the design without change of function, are termed “refactoring”. Michael Feathers describes refactoring legacy code as establishing a design seam, and tests, then changing the system on one side of the seam without changing the behaviour. Each layer of a stack establishes such a seam, and they are omnipresent in software, at all scales. The point of refactoring is not to freeze the function of the system, but to improve the design in small steps to a point where functional improvements are safe, or perhaps just possible at all. Climate change, the long financial crisis begun in 2008, and technical debt are all crises of addressability: of being unable to trace causal relations through a massive codified system.

The story of renewable energy so far has been that of constantly working against the established infrastructure of the industrialized world: every improvement seems to require some other piece to be ripped out. Power stations have been the clearest and most successful point of intervention because the variation of power station inputs facing the need for power distribution creates design pressure for standard interface points at seams. For instance, power plug and voltage standards decouple network endpoints from each other. Though price points of solar vs coal tipped a year or two ago, that this happened despite the cancer-belching external costs being barely priced-in shows the immaturity of the system.

Bratton notes that Bitcoin inadvertently created a more direct link between exchange currency and carbon through the CPU- and hence energy-intensive process of proof-of-work mining. Other designers and startups are since sketching how similar Earth-to-User links could become more established parts of the Stack. Proof-of-stake coins like (some) Ethereum cut the energy usage by cutting the Earth-to-User link. More speculatively, Edward Dodge has proposed using the blockchain as a distributed ledger of carbon account, with mining based on a ton of sequestered CO2. Altcoin CarbonCoin (now seemingly deceased) replaced distributed mining of difficult to calculate numbers with mining by an environmental trust that uses six orders of magnitude less energy and puts profits into carbon mitigation.

A possible system linking these starts with carbon consumption endpoints. Forests and oceans are major carbon sinks, and prospecting rights could be claimed for blockchain coin mining, with satellite photography and other sensors providing the requisite proof of carbon. The mining claim is more important to the network than the legal title to the land, because double-claiming the carbon sink would make the carbon accounting invalid. For natural assets, the mining device need not be in the same location as the trees, though a maturing platform demanding more precision might call for devices on the ground, linking the Wood Wide Web to the internet and the blockchain.  This could be an Internet of Things (IOT) device that mints coins. A larger network of miners might demand a stricter proof of carbon, to retain the advantages of decentralized mining, including the incentives to participate. A previous post covered a design sketch for such a system.

Proof of carbon definitions can be captured as public software contracts, using Ethereum or a similar platform. A related idea is proof of location. The system is not totally trustless – it depends on independently observable weather data, and this might include state bureaus of meteorology for reference temperatures. (Neither is Bitcoin trustless for that matter – there is trust in the development team maintaining the protocol and in the open source process they run.) This also gives locals to the forest or ocean concerned a co-location advantage similar to that of high frequency trading systems to stock exchanges. The world’s greatest carbon sinks are not found in rich world finance capitals: this would give a small home town advantage to those local to say the Congolian rainforest, somewhat mitigating the colonial character of much international finance. (Introducing internet and trading connectivity to forests, who the most radical botanists are now arguing have cognitive processes, suggests future design mutations where animals or forests are also present as users of social and financial networks, perhaps in a mutually incomprehensible way.)

Other such designs are possible, including more centralized ones: the main feature is establishing a direct carbon-tracking data structure touching Earth layer carbon sequestration, Earth layer carbon emission and User-layer action (in the jargon of Bratton’s The Stack).

Refuge Stack

The Stack is a computational planet-system terraforming itself. Managing it is absurd, and changing it happens everyday. Humans working to deflect the system away from climate change processes that would kill them isn’t hubris so much as self-defense. Energy and commodity networks have always accumulated social power. Now it is here, computational society has obligation spam and sincerity leveraging algorithms organized in networks, and power also accumulates around them. To computationally address one from the other is an act of geopoetical network realism. If it results in gangs of telemarketing red guard killer whales demanding carbon coin reparations, we’ll have to cross that bridge when we come to it.

Reducing Abstraction in Code

Abstraction is something we are taught to value as programmers, and the process of finding common patterns across parts of a system is one programmers are usually good at. There is another equally important process of improving systems by collapsing redundancy and abstraction. Gilbert Simondon names this “concretization”.

Primitives

Concretization removes parts and makes machines more specific. A simple example is the abbreviation of clutter by replacing with clearer syntax. Say in Python

if available == True:
   reserve()

to

if available:
   reserve()

Or in JUnit:

assertTrue(false);

to

fail();

These are behaviour-preserving design improvements, or in other words, refactorings. They often turn up in novice programmer code or code written by people new to a language or toolset. Other primitive concretizing refactorings might be dead code removals, such as Remove Unused Parameter.

Another primitive concretization step is recognizing that a variable with a highly general type can be typed more precisely. A String, byte[] or a void* are highly general types, in that they can hold pretty much anything. Replacing with a more specific type usually relies on a precondition, either implicitly or explicitly.

int age = Integer.parseInt(ageStr);

In this case the potential throwing of NumberFormatException entails an implicit precondition. The concretizing step is the refactoring that introduces the typed variable.

Wait, but isn’t the problem with using Strings and primitive objects everywhere that they lack abstraction? Yes. They indicate that the code lacks an explicit model, or in other words, abstractions. They also indicate the code lacks concretizations – specifics from the problem domain that make it a well-focused machine. (Lacking both abstraction and concretization indicates ontological slime, a wonderful term from William Wimsatt, and perhaps the topic of another post.)

For a multi-line example of primitive concretization, consider this refactoring available when going from Java 1 to 5:

Iterator expenseIter = expenses.iterator();
while (expenseIter.hasNext()){
  Expense expense = (Expense)expenseIter.next();
  sum += expense.getExpenseValue();
}

to

for (Expense expense: expenses){
  sum += expense.getExpenseValue();
}

This mirrors the evolution of Java itself as a technical object and iteration as a technical concept. I’ve written about Simondon and the history of looping at more length elsewhere. Specialization and reduction are near-synonyms more frequently used in programming, but because of the clearer relationship to abstraction, and the connection to Simondon, I stick with concretization here, at the cost of a few more syllables. (Reification is a different concept, in my opinion.)

Interleaving Abstraction and Concretization

The adjunction of a supplementary structure is not a real progress for the technical object unless that structure is concretely incorporated into the ensemble of the dynamic system of its operation. – Simondon, Mode of Existence of Technical Objects, Mellamphy trans.

Design improvements often include both abstracting and concretizing steps. The feeling is of abstraction clearing space and concretization then making better use of it.

Michael Feathers’ use of characterization tests is an example of starting a design process with concretization.

    @Test
    public void removesTextBetweenAngleBracketPairs() {
        assertEquals("", Pattern.formatText(""));
    }

Characterization tests stabilize the function of the machine by pinning down very specific behaviors in the form of facts. This then allows a round of refactorings and rewrites. The immediate next step would often be abstracting refactorings such as Extract Method and Extract Class (naming a clump of things introduces an abstraction and an indirection).

Arlo Belshee’s Naming Is A Process also interleaves abstracting and concretizing steps.

Missing to Nonsense – Abstraction
Nonsense to Honest – Concretization
Honest to Honest and Complete – Concretization
Honest and Complete to Does the Right Thing – Abstraction
Does the Right Thing to Intent – Concretization
Intent to Domain Abstraction – Abstraction

A number of these steps, especially in the later half, themselves consist of interleaved abstracting and concretizing sub-steps. Eg in Honest and Complete:

1/ Use Introduce Parameter Object. Select just the one parameter you want to encapsulate. Name the class Foo and the parameter self. (Abstraction)
2/ Use Convert To Instance Method on the static. Select the parameter you just introduced. (Abstraction)
3/ Improve the class name (Foo) to at least the Honest level. (Concretization)
4/ Go to the caller of the method. Select the creation of the new type. Introduce parameter to push it up to the caller’s caller. (Abstraction)
5/ Convert any other uses of the parameter you are encapsulating to use the field off the new class. (Concretization)

Belshee’s process, using names as the signposts for improving code, is a wonderful combination of practical walkthrough and a theory of programming. It even seems to put living flesh on my skeletal wish for Name Oriented Software Development, though, eg, stronger tool and language support for consistent dictionaries are needed to realize the full vision.

Executable Theory

This kind of divergence of functional aims is a residue of abstract design in the technical object, and the progress of a technical object is definable in terms of the progressive reduction of this margin between functions in plurivalent structures. – Simondon, ibid

Every abstraction, even one as small as an extracted method, is also a theory. These little theories then need to be applied and refined to ensure a coherent system. What Simondon saw in the evolution of mechanical engines and other industrial era machines, we can observe at smaller scale and higher frequency when engineering in our more plastic computational material.

Simondon describes machines as becoming more concrete over time, finally reaching a highly focused state where each part cleanly supports the functions of others in an overall system. He also states that the introduction of a new theory is the invention of a new machine. So perhaps he would disagree that the process is cyclical.

We can, perhaps, reconcile this if we think of each software function or class as a small widget in a larger system. In this sense of the widget = machine = function, every new method is a new Simondonian machine. This also suggests that software rarely progresses to the refined machines he describes, but is more usually an assembly of semi-refined widgets. Which sounds about right.

Once you realise abstraction and concretization are complementary, anti-parallel processes, you start noticing it everywhere. I suspect casual design phrases like “nice abstraction” are actually misleading. Ohm’s Law is a nice abstraction; modern chips that rely on parasitic capacitance in a material context of silicon are well-built machines. In working software, a nice abstraction is also a nice concretization: a well-formed widget within a coherent machine.

All problems in computer science can be solved by another level of indirection, except of course for the problem of too many indirections. – David Wheeler

Refactoring the Argo

Le vaisseau Argo ~ The ship Argo

A frequent image: that of the ship Argo (luminous and white), each piece of which the Argonauts gradually replaced, so that they ended with an entirely new ship, without having to alter either its name or its form. This ship Argo is highly useful: it affords the allegory of an eminently structural object, created not by genius, inspiration, determination, evolution, but by two modest actions (which cannot be caught up in any mystique of creation): substitution (one part replaces another, as in a paradigm) and nomination (the name is in no way linked to the stability of the parts): by dint of combinations made within one and the same name, nothing is left of the origin: Argo is an object with no other cause than its name, with no other identity than its form.

Another Argo: I have two work spaces, one in Paris, the other in the country. Between them there is no common object, for nothing is ever carried back and forth. Yet these sites are identical. Why ? Because the arrangement of tools (paper, pens, desks, clocks, calendars) is the same: it is the structure of the space which constitutes its identity. This private phenomenon would suffice to shed some light on structuralism: the system prevails over the very being of objects.

— Roland Barthes, Roland Barthes

The Argo, Constantine Volanakis

The Argo (luminous and white) is a software system and the Argonauts its human components. They trim its sails and move its oars; its rudder steers by the use of a helmsman.

When each piece comes in turn to be replaced, it is substituted for a better part; newer and hence luminous, but in keeping with the shape of the old. The system is rebuilt anew without an act of raw greenfield creation.

The Argonauts are skilled and far from friendly ports: they repair the ship as they sail it. This too is why one traveller will tell of the grand trireme Argo, and others of a swift catamaran, an Argo with a glorious triangular sail, growing ever swifter, ever smoother as time passes. But most will tell of strange hybrid ships, nautical chimera where names and shapes are stretched before losing now redundant pieces entirely, and reforming around a new coherence.

Some stories tell of another Argo, also sailing and perpetually repaired. When each part eventually decays and breaks, it is replaced with the most perfect imitation, in shape, strength, flex, texture and colour. Some say this Argo has a beautiful unity lacking in the first, where the bastard styles and material of past and future ships are always found together. This Argo is easier to find than the others, for though its Argonauts are strong and brave in battle, they never sail more than a few weeks from Thessaly. It is there, in the forest on the outskirts of Iolcus, that a copse of tall trees grow fast and strong. They are excellent for building triremes, and the Argonauts’ only source of timber. Jason has long ago died, and been replaced with other princes, with their own usurped claims. None of them have held the Golden Fleece.


(I learnt of this Barthesian image from Jenny Turner’s review of Maggie Nelson’s The Argonauts.)