The shape of the code
Almenon
Posted on November 3, 2018
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” 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.
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.
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.
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.
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.
Personally, I like the idea of code as a star. GET IT? A STAR??
…. I’ll show myself out.
What’s your shape?
Posted on November 3, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.