Knitting is Like Coding


Once upon a time, I thought I might like to be a computer programmer. I felt a special affinity for computers and desired nothing in the world but the life-sustaining essentials and a connection to the internet. Later, my life plans evolved into a desire to be a digital artist, straddling the categories of graphic design and illustration. When I was in college, my love of the computer waned somewhat, and a preference for hand-made things began swelling up in its place. It’s funny how things change.

Disclaimer: I’m not a coding expert by any stretch, but I’ve dabbled a bit in the course of my education. With a sense of things coming full-circle, it often strikes me how pattern writing is much like computer programming, and as pattern readers, we behave much like computers. What is a knitting pattern, if not a code with peculiar syntax rules (that look like gibberish to the untrained eye), and a series of functions that we execute line-by-line, often involving sophisticated looping instructions? Aren’t k’s and p’s the foundation of knitting in much the same way 1’s and 0’s comprise the language of computers?

When writing a pattern, I believe knitting pattern designers must bear similar things in mind to programmers writing a computer program. We want to reduce our instructions to their simplest, most logical form in order to avoid redundancy, promote efficiency, and reduce the potential for glitches to occur. Ideally, instructions for the production of a knitted hat, mitten, or sweater consist of very few simple rules.

Frankly, I think knitters could benefit from a more stringent style of pattern-writing. I think briefer instructions could better get across the elegant simplicity that many patterns actually consist of. Unfortunately, I think new rules would be hard to impose on the wide world of knitters, but bear with me anyway for the sake of argument. We just need to include variables and while loops to reduce a 21 line pattern to a 1 line pattern. Variables are entities with values that can be set initially, and then changed. While loops are instructions that are repeated until a condition is met (such as a variable finally equalling 0).

For instance, a description of the decreases at the top of a hat often goes something like this:

Row 1: (k10, k2tog) rep around

Row 2: knit

Row 3: (k9, k2tog) rep around

Row 4: knit

Row 5: (k8, k2tog) rep around

and so on… until you get down to Row 21, at which point you k2tog all the way around, or (k0 k2tog) rep around.

Obviously, this is much more efficient than writing out k, k, k, k, k, k, k, k, k, k, k2tog, k, k, k, k, k, k, k, k, k, k, k2tog, k, k, k, k, k, k, k, k, k, k, k2tog, k, k, k, k, k, k, k, k, k, k, k2tog… I didn’t even finish Row 1, but you get the point.

bleuarts3smBut one could be even more concise by just defining a function called “Hat Decrease” for a hat with 72 sts around as something sort of like this, where x is the number of stitches between the k2tog decreases (in fact the only thing that’s changing from row-to-row in the pattern above):

Hat Decrease( sts=72, x=10 ): { while ( x > 0 )  kx; k2tog; x = x-1; k sts; sts = sts – 6; }

Translation: set the number of stitches in the row to 72 and variable x to 10, then — while x is greater than zero, knit x number of stitches, then k2tog, then subtract 1 from x, then knit the number of stitches in the row, then subtract 6 from the number of stitches in the row, and repeat.

Ah well… a girl can dream, right?

Written by Lauren Chesis

Lauren Chesis

Leave a Reply

Your email address will not be published. Required fields are marked *