Knitting as Programming

or how I learned programmers owe it all to fiber

a knit octopus sweater in blue and white
Knit by Abbey Perini, pattern is Embrace Octopus Sweater by Maia E. Sirnes

As part of my bootcamp, I was asked to present for 10 minutes on any topic. I’ve been crocheting since 2013 and knitting since 2018, and I had noticed some similarities between the way I approached a project in either fiber arts or programming. What I did not expect to find was a rich history of fiber arts and programming influencing each other.

The Beginning

Historically, fiber arts and programming have been very intertwined, starting with the Jacquard Loom, an attachment for powered fabric looms. It was the first machine to use a chain of punch cards to automate instructions. It enabled the loom to make intricate patterns in textiles based on the punch cards it was fed. It inspired Charles Babbage in making his analytical machine. A century later, his designs and Ada Lovelace’s notes were read by the people who built the first computer.

The relationship between fiber arts and programming gets even more overt with Core Rope Memory (also called Little Old Lady Memory). Used in the 1960’s by NASA, software written by MIT programmers was woven into core rope memory by female workers.

a woman weaves wire to create core rope memory
a woman weaves wire to create core rope memory

The direction the current was forced through the wires induced field forces to circulate in a clockwise or counterclockwise direction. One direction is a stored 1, while the other is a stored 0. The result was non-volatile storage, which could retain a large amount of information without power — roughly 2.5 megabytes per cubic meter. This was an 18-fold improvement over magnetic-core memory, the standard solution used at the time.

Now

Ravelry was established in 2007 with free membership and only fiber arts ads. Today, Ravelry is the locus of the fiber arts community with over 9 million users. Their website was the first to allow people to exchange information, tools, materials, and patterns in pdf format on a large scale and in every language, revolutionizing the industry. Furthermore, they offer discussion groups, so people can get help with patterns and techniques.

Owned and operated by 6 women, they employ a tech stack of about 10 Gentoo Linux servers, MySQL 8.0, Ruby on Rails, Manticore Search, Amazon S3 for image storage and a CDN, Redis, memcached, nginx, and haproxy.

By removing barriers to entry, Ravelry is credited with creating an explosion of interest in knitting and crochet, driving innovation in easier to follow patterns. I’ve personally talked with local yarn store owners about their experience before and after Ravelry, and they describe it like night and day. Knitters are now primarily 25–35 years old. Local, regional, and international knitting groups, fiber festivals, and yarn crawls have cropped up everywhere. Indie dyed yarn is now a huge business. There’s renewed interest in fiber shows, which educate people on where their yarn comes from. The audience for blogs and podcasts related to fiber arts in general has grown exponentially.

A Knitting Primer

a diagram of K2P2 ribbing
a diagram of K2P2 ribbing
K2P2 Ribbing

Patterns as Programming

  • Pattern repeats are for loops, typically surrounded by brackets, asterisks, or parentheses.
  • It’s common to see while loops like ‘until the end of the round’ or ‘to n stitches before marker’.
  • Higher level languages like Python and Javascript use symbols and keywords to tell the computer what the desired output is, just like knitting charts.
  • Like assembly languages, operands are pushed and popped onto the needles.
  • Patterns are tested and retested by users for correctness, scalability, and the look of the finished object (aka expected output).
  • Pattern developers prefer open source software (Darktable, Gimp, Libre, Stitchmastery, etc.).
  • Different placements of yarn and needles produce different outputs.

This shawl was created using 8 stitches — all knit based (no purl). One row was written like this: k3, SM, (k2tog, yo) 2 times, [k1, yo, ssk, yo, sk2p, yo, k2tog, yo] to 5 stitches before marker, k1, (yo, ssk) 2 times), SM, k3

a lacey Dowland shawl knit in sparkly burgundy yarn
a lacey Dowland shawl knit in sparkly burgundy yarn
Knit by Abbey Perini, pattern by Dowland by Dee O’Keefe, yarn is Meeker Street by The Jewelry Box

There have even been two (no longer supported) programming languages designed specifically for hand knitting — KnitML, a markup language, and KEL, inspired by Groovy, a Java language.

Patterns as Regular Expressions

Patterns as Tools for Teaching Programming

“Knitting patterns have evolved from vague, chatty discourse written for experts to precise, line-by-line procedures that are akin to programs.”

— “Following a thread: Knitting patterns and program tracing” by Michelle Craig, Andrew Peterson, Sarah Peterson

Craig, Peterson and Peterson go on to say that programmers can learn from the way the online knitting community has developed standard conventions for communicating concepts like iteration, conditions, and documenting design decisions. Specifically, the way they’ve come about while trying to make the patterns understandable to beginners. For example, using termination cases with “until” makes the while loop easier to understand. They also say that creating a knitted final object is analogous to tracing, as it demonstrates an understanding of the pattern.

Conclusion

I hope you enjoyed this brief overview of the history of fiber arts and programming. For general recognition and brevity’s sake, I stuck to knitting, but my first fiber love will always be crochet. I personally believe in crafting as therapy for anyone, and we could all use a little self-care these days. If you’ve never thought of yourself as a fiber artist, but have a penchant for coding, try picking up some yarn and tools. You may be surprised.

If you’re already a programming fiber artist with Ravelry projects, check out my project, Knitworthy!

Additional Fun

Knitting is an acceptable Lisp

A programmer worked with his daughter to convert text instruction to charts using Perl

Additional Sources

…did someone say animated CSS button?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store