Knitting is computing. Bear with me, I’ll explain.
Computing is using certain hardware, following a set of instructions to manipulate input and produce a desired result.
Knitting is using certain hardware, following a set of instructions to manipulate input and produce a desired result.
See, it’s the same! Knitting ‘hardware’ is needles, our ‘input’ is yarn, and our result is… a scarf, perhaps.
Knitting patterns are exactly like computer programs – they’re a set of instructions. Yes, that would make knitting pattern writers programmers.
As a woman in tech, I’ve witnessed many surprised faces belonging to men who have just learned that I am a programmer. None have ever expressed surprise that I am able to knit!
Unravelling the Mystery
Let’s take a look at a much simpler knitting pattern that will create a slightly textured fabric.
worked over even number of sts
row 1: [yo, k2tog] rep
row 2 & 4: k all sts
row 3: [ssk, yo] rep
rep rows 1-4 for pattern
This pattern consists entirely of familiar concepts; variables, conditionals, iterators, and functions.
Let’s look at the variables. These are
sts (stitches) and
row (row). Our knitting needles holds an
array of stitches which are knit over a
number of rows. So, after we knit (process) each of our
sts in turn, our
Our pattern contains conditionals. Which
row we are on determines which instructions we follow. If
row == 1, we
[yo, k2tog] rep, if
row in (2, 4), we
k all sts, and if
row == 3 we
[ssk, yo] rep.
Each of the instructions for the rows ends with
rep, our iterator.
rep means to repeat the previous instruction. In this case, we continue to repeat the instruction, processing stitches, until we complete the row.
We also have functions. These are the actual yarn manipulations – we see them in the pattern as
ssk. Each of these is a different way to process a stitch in a row. As a knitter, you must learn how to perform each manipulation.
yo is a manipulation that increases the number of
sts in a
row by 1.
ssk manipulate two stitches at the same time, decreasing the number of
sts in a row by 1, and
k means to knit – leaving the number of
sts as it is.
Examining the pattern using this knowledge, we can determine that given any even value for
sts.length will remain unchanged at the end of each row. If we were to keep repeating rows 1-4, we would end up with a rectangular piece of fabric which would get longer with each iteration. That’s our scarf!
A History Intertwined
Computing and textile manufacture have a shared history. Back in the 18th century, the textile industry was undergoing a revolution. A silk fabric inspector, Jacques de Vaucanson, turned his efforts to mechanising the cloth-making processes. He succeeded in creating a water-powered automatic loom. Unfortunately, this invention was largely ignored for several years – until it was picked up by Joseph-Marie Jacquard. Jacquard improved upon this automatic loom and patented the invention in 1804.
This Jacuqard machine could be attached to a loom, and, given some input, could create woven fabric according to any given pattern. This was a breakthrough in textile manufacture. Due to the way in which it employed punched cards, exceedingly complex patterns could be fed to the machine and easily re-used.
You may know that early computers also used punched cards for reusable input. This came directly as a result of the mechanisation of textile manufacture. Charles Babbage was heavily inspired by Jacquard, and used much of the same technology when he designed his Analytical Engine – the world’s first computer.
Punched cards are very familiar in computing as they represent binary data – either the hole is open, or it is closed. 1 or 0. This fact defined human-machine interaction. Ada Lovelace–the world’s first programmer and accomplished mathematician, who just so happened to be a woman–surmised that these punched cards could represent not just numbers and mathematical operations, but arbitrary data.
We may say most aptly that the Analytical Engine weaves algebraical patterns just as the Jacquard loom weaves flowers and leaves.
– Ada Lovelace
Weaving Things Together
There is not currently any one ‘universal’ notation for knitting patterns. Even different cultures have differing names for stitches; for example, an English double crochet stitch is an American single crochet stitch. There are also different ways to signify the size of needle required for a pattern, and different names for the thickness of yarn.
When we write our code, we usually use a specific language which is formally defined. This ensures that our code can be executed, and understood by other engineers. Could a ‘universal language’ be developed for knitting, and could we write tools to parse and validate our written patterns, and identify mistakes?
Each kitting pattern is generally written to be performed on specified hardware. Could we develop tools that allow knitting patterns to be transcompiled for use with differing hardware? For example – increasing or decreasing the number of rows or stitches to achieve a desired size, given any combination of needles and yarn.
Furthermore, is it possible that our knitting language could actually be used as a general purpose language for performing computations? In order for this to be true, our knitting language must be Turing Complete. In her Masters thesis “Algorithmic Complexity in Textile Patterns”, Heidi Metzler investigates whether or not knitting can be used to simulate a universal Turing machine. If it is possible, then knitting patterns must be Turing Complete!
In conclusion, knitting and computing are more similar than you might think! I hope that this article has given you food for thought, and perhaps some new perspective. If it weren’t for the textile industry and the contributions of women, perhaps computational theory wouldn’t be where it is today.
If you find yourself looking for a new hobby, why not knitting? You could even create yourself a nice scarf…