The shape of the code
Tags: programming, softwaredevelopment, coding, philosophy
Published: 2018-11-03 17:15:58

---
title: The shape of the code
published: true
description: random musings on the shape of code, if it had a shape
tags: programming, software development, coding, philosophy
---

Code has a shape. For a small script, it might be a simple arrow. Stuff goes in, stuff goes out. A large script might be a mess of spaghetti, arrows going every which way. Intersections, crossings, dead ends, all forming a scary mess. As the code grows and grows the knots get tighter and tighter, until eventually it becomes impossible to untangle. “[Abandon all hope ye who enter here](https://stackoverflow.com/questions/35772001/how-to-handle-the-signal-in-python-on-windows-machine/35792192#comment81619892_35792192)” the comments warn, because a single change could cause the whole system to catch on fire. Due to lack of testing and pressure from on high, most code ends up like this.

![alt text](https://thepracticaldev.s3.amazonaws.com/i/hsi2jthwsq1k6qyh9l17.png "https://xkcd.com/844/")

But in good systems, it’s less of a knot and more of a grid. Input follows sensible proper paths and logical output is returned. From the output, more code can be applied with yet more logic. If the code is good, eventually another library picks it up as a dependency, and that library picks that library up, and you end up with gigantic skyscrapers of code. Prime example: any popular npm package. It’s like reading the geneaology of Adam: vscode uses gulp-chmod, which uses gulp-symdest, relying on vinyl-fs, in turn relying on glob-stream, which uses micromatch, but that uses braces, and that has expand-range, which of course uses fill-range, and randomatic, and finally is-number. It’s a tower.

![alt text](https://thepracticaldev.s3.amazonaws.com/i/ph44g1ijxx769q81pdxr.jpeg "you better hope is-number doesnt get hacked, or else the whole tower might fall")

Or maybe the shape of code is a pyramid — vscode doesn’t have just one dependency, it has tons of dependencies. One library relies on many other libraries, which in turn relies on other libraries, so on, expanding exponentially.


![alt text](https://cdn-images-1.medium.com/max/800/1*Hd1p9SEP797mkIx6_ZHpdA.jpeg "If you printed out books of all the code in the world and stacked them up it would be at least this high")

Exponentially…. That sounds like a tree! An upside down tree, sure, but this is computer science land. And as long as we are there why a tree? You can view code as a fractal — the more in depth you look into it, the more confusing it gets.

![alt text](https://thepracticaldev.s3.amazonaws.com/i/8tdfchs29evfumqq0ybc.jpeg "psychedelic AND healthy!")


But why a fractal brocoli? Maybe it’s a onion. You peel back one layer of code, and there’s another layer. A function in that layer calls a library in a deeper layer, which makes a web request to the backend which hands it off to a ancient stored procedure in the legacy database and pretty soon you have twenty files open in the editor and you’re cying just like you’re peeling a real onion.

![alt text](https://thepracticaldev.s3.amazonaws.com/i/f6iqhg1ia7nldm13t0ei.jpeg "Onions: a powerful metaphor for both ogres and code")

Personally, I like the idea of code as a star. GET IT? [A STAR??](https://en.wikipedia.org/wiki/A*_search_algorithm)

…. I’ll show myself out.

 ------------------------------

What’s your shape?