16 May 2012 Skud   » (Master)

Knitting as programming

I’ve seen a few people, over the years, compare knitting to programming. It usually goes something like this:

Wow, have you ever looked at a knitting pattern? It looks kind of like source code! Those knitters must be real geeks!

And it’s often accompanied by a snippet of a set of actual knitting instructions that look like incomprehensible gibberish to the uninitiated, but which your grandma could probably read and turn into a jumper or a scarf or an attractive toilet-paper-roll cover (my Nanna actually knitted these!)

In case you haven’t seen this kind of knitting pattern before, here’s an example:

1st Row: P. 3, * k. 1, p. 1, k. 1, p. 3, repeat from * to last 4 sts. (k. 1, p. 1) twice. etc.

A typical knitting pattern from the 1940s. This one is Sun-glo pattern #2616, "Country Club", a sporty cabled sweater in two colours, in case you were wondering.

There was even a post a little while ago entitled Knitters and coders: separated at birth? that talked about knitting patterns as code, and worked through some examples using regular expressions. It was a good post, but I don’t think it went far enough, so I want to riff on it a bit.

Here’s the thing. Let’s say you have a pattern that says:

row 10: k2 p3 *(c6f p6) rpt from * 8 times c6f p3 k2

(Or as the aforementioned article would put it would put it, (c6f p6){9}.)

You read those instructions and do what they say, producing a row of knitting that incorporates a number of cable twists against a purl background.

Is what you’re doing programming? Of course not! It’s the reverse of programming: you’re reading a series of low-level instructions and doing what they say. It would be more accurate to say you’re an interpreter, or possibly a compiler, since it’ll usually save you time and trouble to read a pattern right through before you begin. (Ask me how I know. Ugh.) You might even be called a human computer.

But let’s be clear: even though what you’re doing when you read a pattern is a complex technical skill, and involves code, it’s not programming.

Despite that, I very firmly believe that knitting is like programming. I just think that the common analogy drawn — of printed knitting patterns as source code — is not a very good one for describing the intellectual process of knitting as it is practiced by the current generation of geeky crafters.

To explain this I’m going to have to take a detour, so please bear with me. What follows is based on conversations I had years ago with my friend Rose White, aka @yarnivore, who studies hacker culture and presented at CCC (a hacker conference in Germany) on the subject of guerilla knitting. Watch Rose’s guerilla knitting talk on Youtube. I’m going to proceed to paraphrase Rose for the next few paragraphs here, so credit goes to her, and all blame for any errors to me.

In her presentation, Rose talks about knitting patterns as intellectual property through history. When knitting was first developed in the middle ages, it was a secret skill known only to the members of exclusive knitting guilds, who didn’t share it with anyone else. However, as Rose points out, knitting is easy to reverse engineer, so it didn’t take long for non-guild people to figure it out and start doing it. As one of the great knitters once wrote:

“Really, all you need to become a good knitter are wool, needles, hands, and slightly below-average intelligence. Of course, superior intelligence, such as yours and mine, is an advantage.” — Elizabeth Zimmerman

And so, from about the 16th or 17th century onward, you start to see more people knitting for themselves and their families, or as a cottage industry. Throughout this period, a number of traditional knitting styles and patterns were developed, but the fundamental thing about them was that, for the most part, they were the sort of patterns you could pass from person to person without writing them down.

Take a sock as an example. The simplest sock is a tube of fabric knitted until it’s long enough, then closed up at one end. Of course, it’ll fit better if you find a way to make it bend at an angle around the heel, and there are a number of techniques you can use for that. Ribbing at the cuff will help it stay up better. If you want a long, shapely sock you can add more stitches around the calf and reduce them at the ankle. You’ll save yourself some discomfort and possible blisters if you find a way to graft the toe end instead of sewing a lumpy seam. And of course you’ll probably want to embellish your sock according to the local fashion: perhaps a fancy coloured band around the top, or twisted cables down the side, a repeating texture all over.

This is just the icing on the cake, though: socks are all just tubes, when you get down to it. Fundamentally, there’s nothing about knitting a sock that needs a pattern; for hundreds of years, all anyone needed was a “slightly below-average intelligence”, an already-knitted one to look at every so often for reference, and perhaps a few pointers from someone who’d done it before. Gloves, jumpers, and other knitted garments are much the same. For the most part they’re just a series of tubes. Ba-dum-tish!

Fast forward to that point in the industrial revolution when most textile production has become mass production, most working class people are pulling long hours in factories and mills, and it’s cheaper to just buy a pair of socks than to knit your own. At this point, knitting becomes a bit of a luxury activity, and you start to see this in the proliferation of Victorian-era knitting books for ladies, specialising in delicate items like lace doilies and silk purses. No longer were people knitting practical items based on traditional patterns you could figure out with “below-average intelligence”; it became hip to show off your accomplishments by knitting increasingly complex and fiddly items, the patterns for which you could find in the finest publications for the discerning gentlewoman.

And then, in the 20th century, something truly awful happened. You see, the yarn companies realised that if they started publishing patterns themselves, they could use them to sell more yarn. But they didn’t want people using just any yarn. The idea was that you’d buy, say, a Patons pattern and then buy the Patons yarn to knit it with. To make sure that consumers were locked into the Patons brand, they’d make sure that the patterns were obfuscated so you wouldn’t be able to figure out how to substitute another company’s yarn.

This is fundamentally bullshit, and it’s amazing that they ever got away with it, but by this stage people had lost touch with a lot of the traditional methods, and so they didn’t have much choice. Just so the non-knitters understand how diabolical this is, let’s pause for a moment to talk a bit more about how knitting works. If you already knit and know about gauge and yarn substitution, you can skip down to below the next image.

Knitting is basically formed by repeating a single stitch (the knit stitch), which loops a length of yarn through itself in such a way as to form a stretchy fabric. To create a piece of knitting, you “cast on” a certain number of stitches, then knit, either back and forth, or round and round in circles. Each stitch looks like a “V” on one side and a sort of nubbly or wavy effect on the other side. If you want to see this, take a close look at your socks, which probably have Vs on the outside, nubbles on the inside, and alternating Vs/nubbles in the rib around the top. (A “purl” stitch is just a backwards knit stitch, with the V and nubbly sides reversed.)

Depending on the thickness of your yarn and needles, your stitches might be tight or loose. Big needles give looser stitches, and small needles give tighter ones with the same yarn. The measurement of this tightness or looseness — how many little V shapes you have per unit of distance — is called gauge or sometimes tension. For instance, worsted weight yarn on 4.5mm needles normally knits up at a gauge of 5 stitches per 2.5cm/1″, while finer yarn knit on smaller needles will have more stitches in the same distance.

As long as you know the gauge of your project and the yardage it requires, it’s fairly simple to substitute one yarn for another. However, 20th century yarn companies didn’t want you to know this, and they went out of their way to make sure you were locked in to their proprietary system.

Warning -- Use the wool specified, otherwise success of garment cannot be guaranteed. 3 skeins "Sunbeam" or "Wilga" blanket wool, shade No. 2101... etc.

So, this is the system that created knitting patterns like the one I linked at the top of this article, where yarn companies write the patterns and knitters interpret the code and execute it, without much input into the process, not even a choice of what yarn to use.

If being an instruction-executing machine doesn’t sound too appealling to you, you’ll be pleased to hear that there is an alternative. Modern knitters, especially those online, are increasingly returning to traditional techniques, making their own patterns, and adapting existing patterns to their own needs. One of the great leaders in this trend was the late, great Elizabeth Zimmermann, quoted above. EZ, as she is known, helped popularise, or perhaps re-popularise, traditional forms of knitwear in the United States, and along the way taught knitters to throw off the shackles of mid 20th century commercial knitting patterns and think for themselves again.

One of EZ’s best known patterns is for a sweater knitted to what she calls the Elizabeth Percentage System, or EPS. It’s so simple that almost anyone can understand it, and I often use it as an example when explaining the technical side of knitting to non-knitting geeks. It goes something like this:

  • Knit a gauge swatch and measure how many stitches per inch you have. Now measure your torso around your widest point, or your favourite existing sweater. Multiply the number of stitches by the number of inches. This is your key number (K).
  • Using a circular needle, cast on K stitches. This will be the hem around the bottom of your sweater. Knit until you get to the armpits (measure yourself or a favourite sweater to figure out how far that is).
  • For each sleeve, cast on 20% of K, then increase gently (2 stitches every 6 rows should about do it) til you get to 33% of K, then knit straight until your sleeves are long enough.
  • Join the sleeves to the body, and knit the yoke area (i.e. upper chest and back), decreasing — in one of several possible ways, all of which can be derived arithmetically — until you get to 40% of K, which is the neck opening, and cast off.

Of course, you can elaborate in various ways: ribbing at hem, cuffs and collar; textured stitches across part or all of the garment; coloured designs in the yoke area; leave a gap at the front and knit back and forth to make a cardigan. The options are endless, but the fundamental design is the same.

Now, people will possibly point out that EZ’s EPS pattern is copyright, but there’s a lot of bullshit about copyright in the knitting community, so let’s be clear right now: ideas cannot be copyrighted, though the expression of them (the specific words EZ wrote in her books and newsletters) can be. The idea of EZ’s EPS sweater is simple, based on traditional techniques, easy to reverse-engineer, and in fact could be done by anyone with “below-average intelligence” as she herself points out. There’s nothing tricky about it, it’s just simple craft.

But taking this simple kind of design and elaborating on it is where knitting really becomes like programming. When I knit a sweater this way, I’m not executing instructions written by someone else. I’m creating my own code, designing and implementing my own project from the ground up.

I start out by considering my requirements: What sort of garment do I want: pullover, cardigan, long coat? What design elements do I want to incorporate: pockets, a hood, shaping to make it more fitted at the waist, a warm shawl collar, those awesome thumb-holes in the sleeves that let you pull them down and wear them as fingerless mittens? What materials and tools do I have at my disposal? Can I take the opportunity to try out a new technique or refine my skills?

I prototype my design by knitting a swatch or something small like a hat, using the same stitches and yarn as I’m thinking of using for my finished project. From this, I figure out my gauge, and using one of the many tools available I can calculate the yardage I’ll need, without ever relying on a yarn company to tell me how much of their product I ought to buy. Modern yarn sellers list the yardage of their yarn on the label, or failing that, websites like Ravelry have all the information I could need.

To implement my design, I draw on a variety of design patterns — yeah, knitting’s had them far longer than OO programming has — that I’ve learned through classic books like EZ’s or Barbara Walker’s, and through blogs like TechKnitting: short row shaping for better fit, twisted rib for extra stretch in the cuffs and collar, underarm grafting to make a seamless join, endless options for buttonholes, cast-off techniques for all occasions. Some knitting techniques even follow agile principles, like EZ’s “thumb trick” for mittens or her “afterthought pockets”, which are inserted when and where needed without requiring Big Design Up Front.

When it comes to this kind of knitting, an experienced knitter is one who takes a modular approach, mixing and matching existing patterns and individual techniques, to build a finished product. It’s someone who can look at a pattern and figure out how to knit it in a different yarn, a different gauge, and a different size, without breaking a sweat over the calculations. It’s someone who geeks out on the knot topology, the 3D spatial reasoning, and the materials science of it all… and knows how to put them to practical use. It’s the difference between being a code monkey and being an engineer.

So when we talking about how “knitting is like programming”, let’s take a minute to go beyond reading and executing code and think about how much further knitters’ technical skills really extend.


Epilogue: Since I suspect a bunch of geeky knitters will read this, I’m going to lay out my current technical challenge and see if anyone has any thoughts.

I’m knitting a triangular shawl beginning at one of the tips, started by casting on 3st and increasing at the start of every second row. It has integral i-cord borders, which I’m doing by yf, sl 3 at the end of each row, then on the next row I k3 then continue as usual.

On the straight side of the shawl this makes a nice border, firm but stretchy. But on the diagonal side (i.e. the side with the increases) the i-cord, which after all only has half as many rows as there are in the main part of the knitting, is stretched really tight. I’m worried that it’s going to limit my ability to block the shawl as vigorously as I’d like to.

My current best idea is that every second time I do the i-cord on the tightly-stretched diagonal side, I insert an extra row. That is, I would go yf sl3 at the end of the previous row, turn, k3, slip them back on the original needle, then knit the three stitches again and continue. I figure this gives me 3 i-cord rows for every 2 I had previously, which is not far from the sqrt(2):1 ratio of the side lengths. Anyone done this before?

Syndicated 2012-05-16 13:22:36 from Infotropism

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!