Kris Howard: Okay. So, just so I know what I’m deal­ing with here, how many of you have ever knit­ted in your entire life? Oh sweet, like every­body. That’s real­ly good. If you’ve got them, and I know we do have knit­ters in the audi­ence, please feel free to whip it out, knit along— [indis­tinct; mic issue] Feel free to knit through the talk. I love that. 

As for the rest of you mug­gles[laugh­ter] Don’t wor­ry, no pri­or expe­ri­ence is assumed, and I’m not going to teach you either. I’m here to talk about code, after all. So my goal is to con­vince you that this

…is actu­al­ly more sim­i­lar to this

…than most peo­ple realize. 

Because real­ly when it comes down to it, this is actu­al­ly this: 

And to com­put­er pro­gram­mers, that looks a hell of a lot like com­put­er code. And you don’t need take my word for it. I’m sure some of you saw a month ago some engi­neer at Uber tweet­ed this

…and it went viral, and every­body like sent it to me. Because even though I’ve been say­ing it for years when like a dude says it sud­den­ly it’s novel. 

But snark­i­ness aside I’ll intro­duce myself. So, I’ve been work­ing in tech a hell of a lot longer than I’ve been a devel­op­er. I’m sor­ry. A hell of a lot longer than I’ve been a knit­ter. So tech first. I grew up in the US, and I worked in London for a while before I moved to Australia in 2001. And when I got here I had to wait a while for my work visa to be approved. And, young per­son, we did­n’t have Netflix back then. 

So I decid­ed to learn a hob­by. And I thought I’ll learn to knit, right. Like, how hard can it be? I mean grand­mas do it, right. It’s total­ly offline, total­ly sep­a­rate, total­ly simple—I’ll get a nice fuzzy scarf out of it. I can do this. 

So I get a kid’s learn-to-knit book and I start­ed mak­ing a pothold­er. And it near­ly killed me. I think I start­ed over about a dozen times. And by the end of that project, I had three things. 

One, I had a real­ly kick­ass pot hold­er, which has pride of place in my house today. Two, I had mad respect for the grand­mas of the world, like you have no idea. And I had the rev­e­la­tion that knit­ting was just like coding. 

And this just blew my mind and I start­ed see­ing these sim­i­lar­i­ties every­where. And pret­ty soon this men­tal model: 

Became this:

So, today I’m gonna walk you through some of those areas of sim­i­lar­i­ty, and the pat­terns that I rec­og­nized, in the hopes it’ll just inspire your own cre­ativ­i­ty. Look, this isn’t some­thing you’re gonna learn in your job. It’s noth­ing you’re gonna need next week. But I real­ly believe that by look­ing at what you do in a new way, it makes you bet­ter at it. 

So les­son the first, if you learn noth­ing else from linux.conf let it be this. 

This? This is not knit­ting. [laugh­ter] Not knit­ting. This is cro­chet. This is not con­tempt cul­ture. I’m not look­ing down on the hook­ers here. Crochet is a per­fect­ly valid form of expres­sion. It is not knit­ting, though. So it uses a sin­gle hook. It’s got a ball of yarn, you make stuff. Crochet’s real­ly great for com­plex three-dimensional shapes. And if you’re into math go home tonight and Google cro­chet maths,” and then next year you can be up here doing a talk on cro­cheted hyper­bol­ic geometry. 

This is knit­ting. Knitting is done with at least two nee­dles, some­times more. It’s involves the sequen­tial pro­cess­ing of stitch­es from one nee­dle on to the other. 

Now every knit­ter learns when they start out that there are actu­al­ly real­ly only two stitch­es: knit and purl. So the first thing I real­ized right off the bat was knit­ting’s bina­ry. And to a com­put­er geek like us, that implies I can use it to encode pret­ty much any­thing dig­i­tal. And I start­ed see­ing exam­ples of this everywhere. 

So for exam­ple I could com­bine knits and purls to make rib­bing for a beanie, like for hat. So this is called the Decoder Hat by Zabet Stewart, and it encodes up to twelve char­ac­ters, in ASCII, in bina­ry, at eight stitch­es per char­ac­ter. So obvi­ous­ly that is a pret­ty hard mem­o­ry lim­it, a mes­sage length of only twelve char­ac­ters, deter­mined of course by the size of your own head. 

Now if you want­ed to knit some­thing longer, you could knit a scarf. So this scarf here is the source code to rav​el​ry​.com, which is basi­cal­ly Github for knit­ters, with knits as the ones and purls as the zeros. 

Now, if you’re more of a black­hat you could even knit a virus. In 2001 a team of activists did just that. They knit­ted the source code to the Code Red com­put­er virus into a fluffy red scarf. You could wrap it around your neck and walk across any bor­der in the world. No fire­wal­l’s pickin’ that up. 

If you want­ed some­thing more styl­ish you could do cables, I’m a big fan of cables. The hat on the left here rep­re­sents the num­bers from zero to fif­teen in bina­ry nota­tion depend­ing on where the cable cross­es occur. And the scarf on the right has a hid­den mes­sage in bina­ry revealed by cables that actu­al­ly look like lit­tle ones and zeros. 

If you pre­fer col­or you could use the width of knit­ted stripes in dif­fer­ent col­ors to encode a char­ac­ter set. The stripes on this guy’s jumper of course spell out the clas­sic first pro­gram­ming exercise—say it with me, Hello, world.” 

If you want to get super lit­er­al you can actu­al­ly knit ones and zeros into your scarf. I’m hap­py to tell you the aver­age scarf, depend­ing on how tall you are, will hold about 120 bytes of infor­ma­tion. Just shy of a tweet. 

Of course not all data is text. Did you know in World War II the Belgian resis­tance recruit­ed lit­tle old ladies who lived near train­yards to watch the German trains and secret­ly knit their move­ments into their projects. It’s true, I saw it on QI

In more mun­dane exam­ples, on the left here is the Scoreboard scarf, which is a record of a sports team’s sea­son, with all of their points in one col­or and all their oppo­nents points in anoth­er col­or. I real­ly hope he’s bar­rack­ing for the grays. And on the right is a sky scarf, where the col­or of every row is the col­or of the sky above the knit­ter on the day that they knit­ted it. 

Now my last exam­ple of knit­ted and encod­ed data actu­al­ly won me a sec­ond prize at the Sydney Royal Easter Show a few years back. So ladies and gen­tle­men, I give you the knit­ted QR code mit­ten. It does work. It was sur­pris­ing­ly dif­fi­cult to get it to work. I mean, QR codes rely on things being real­ly square and knit­ted stitch­es as some of us know are inher­ent­ly wider than they are tall. So I had to do a lot of pro­to­types on dif­fer­ent thick­ness­es of wool, and even­tu­al­ly got— I hit upon the solu­tion, which in tech­ni­cal terms was to stretch the hell out of it…and then even­tu­al­ly got one that reads. So if you scan it, it points to a URL on my web­site that has the pat­tern for the mit­tens. So they’re self-replicating. 

Okay, so back to my sto­ry. So once I had the basic mechan­ics of knits and purls down it was time to learn to read pat­terns. Now the very first line of any knit­ting pat­tern looks some­thing like this, Cast on 24 stitch­es.” And that means to cre­ate that ini­tial row of loops on the nee­dle. Well I looked at that and my brain imme­di­ate­ly rec­og­nized well that’s just a for loop. You know, it’s code exe­cut­ing repeat­ed­ly a cer­tain num­ber of times. So my brain kind of trans­lat­ed it into code. You know some­thing like this, like a very sim­ple lit­tle for loop with a vari­able that calls stitch.castOn() 24 times. 

Okay. I can do that. 

So anoth­er real­ly com­mon instruc­tion you see is Repeat to end of row.” Well that’s a while loop. So you get code exe­cut­ing repeat­ed­ly again based on a giv­en boolean con­di­tion, and the con­di­tion in this case being have you got­ten to the end of the row yet?” If not, keep going. So again, real­ly sim­ple lit­tle while loop. While the expres­sion not at end of row” is true, just keep knitting. 

So that was all mak­ing sense. So once I fin­ished my pothold­er even­tu­al­ly, I was itch­ing to move onto gar­ments. And I picked out a jumper pat­tern, I opened it up, and the first thing I saw was this: Cast on 242 (256, 270, 284) stitch­es.” So I puz­zled through that and I real­ized these cor­re­spond to sizes. 

So, there are four gar­ment sizes at the start of the pat­tern. So here’s an exam­ple for a cardi­gan. So let’s assume I want to knit the 38″ chest size. Then I just need to cast on the num­ber of stitch­es that cor­re­spond. So the first one of every group before. So real­ly, this is a switch state­ment. This is code that allows the val­ue of a vari­able or expres­sion to change via mul­ti­way branch. 

And so I set a vari­able for my stitch size and then based on that I cast on the appro­pri­ate num­ber of stitch­es. So in this case 242

Now some pat­terns espe­cial­ly if they’re for kids and adults have a lot of switch state­ments. And each case usu­al­ly involves more than just a sin­gle vari­able chang­ing. So you might have whole sec­tions of the pat­tern you use or don’t use. And that leads me to the next con­cept, sub­rou­tines. So you know, in a pro­gram we might call these pro­ce­dures or func­tions or meth­ods. Well these are every­where in knit­ting. You know, if a pat­tern uses a par­tic­u­lar stitch pat­tern, they get declared in a sep­a­rate block at the start and then just invoked wher­ev­er you need. 

So here’s an exam­ple where a pat­tern has two spe­cif­ic stitch pat­terns, Twisted Rib” and Twisted Rib in the round.” And then in the actu­al instruc­tions, the twist­ed rib func­tion is invoked with the phrase Work in Twisted Rib.” 

Now anoth­er way that pat­terns declares sub­rou­tines is with charts, espe­cial­ly if they’re com­pli­cat­ed. So here’s some exam­ples from a cable cardi­gan, you know. There might be one chart for the front, one for the sleeve, and one for the col­lar. Now the real fun hap­pens (and the knit­ters know this) when you have more than one of these sub­rou­tines hap­pen­ing at the same time. And that actu­al­ly takes us into the realm of corou­tines, which some of you know are a spe­cial class of sub­rou­tines. So sub­rou­tines start and fin­ish and don’t hold state. But corou­tines can exit my call­ing or yield­ing to oth­er corou­tines and then lat­er come back to the point where they left off. It’s like hit­ting the pause but­ton. And you can also have mul­ti­ple instances of a giv­en corou­tine at once. 

Now in knit­ting you real­ly see this use with very com­pli­cat­ed lace and cable pat­terns. I start­ed knit­ting this mon­ster last year. It’s called mar­gen [sp?]. It involves twen­ty dif­fer­ent charts with fifty-six instances of them in use at any giv­en time. Knitters, this is row one:

Each one of those let­ters cor­re­sponds to a dif­fer­ent chart, which vary in length from two rows long to sixty-six. You could even look at this is a type of inter­leaved mul­ti­thread­ing (pun very much intend­ed) where the CPU, which in this case is my brain, has to take a new instruc­tion from each corou­tine in turn. And depend­ing on how much RAM I have avail­able, things can grind to a halt. This is not the type of pat­tern you knit at the pub. 

So I’m going to switch a lit­tle bit now and talk about pat­tern lan­guages and how they relate to pro­gram­ming lan­guages in gen­er­al. So in case you did­n’t know there’s no sin­gle world­wide knit­ting author­i­ty. Everybody writes their pat­terns dif­fer­ent­ly. There’s mul­ti­ple com­pet­ing stan­dards. That’s kind of anoth­er way it’s like programming. 

So the mind-blowing thing is that the his­to­ry of pro­gram­ming lan­guages actu­al­ly begins with tex­tiles. And I know some of you are prob­a­bly famil­iar with this. What is this?

This is a jacquard loom, invent­ed in 1798 by Joseph Marie Jacquard. And what is on the front of it? Punch cards. Jacquard devel­oped this forty years before Babbage wrote of using it for the Analytical Engine. So have a look at those punch cards, and then look at this mod­ern knit­ting stitch chart. 

Pretty sim­i­lar. So when exe­cut­ed this pat­tern cre­ates a stitch called moss stitch.” The blank squares are a knit stitch and the dots are purls. This is effec­tive­ly bina­ry. This is knit­ter’s machine code, you know. First-generation pro­gram­ming lan­guage. There’s no com­pil­er or assem­bler need­ed. It’s super easy for the CPU—remember, my poor brain—to exe­cute this. I see a blank, I knit. I see a dot, I purl. 

This is anoth­er exam­ple from 1935, a checker­board design. Instead of using sym­bols this uses col­ors, because this is actu­al­ly a mul­ti­col­or design. And charts like this are great for that because it pro­vides a form of error-checking. I can TDD by hold­ing my knit­ting up at any time and makin’ sure it looks like what it’s sup­posed to look like. 

It’s also data com­pres­sion. It saves a lot of space. So if this series of steps were writ­ten out in words it would take up a lot of paper and ink. And I know that because this par­tic­u­lar pat­tern includes it: pages, and pages, and pages. 

So as pat­terns got more com­pli­cat­ed pub­lish­ers real­ized they could save space in this way. And they could pro­vide even more infor­ma­tion by adding more sym­bols in. 

So this exam­ple’s from the 50s and it uses five dif­fer­ent typo­graph­ic sym­bols to rep­re­sent dif­fer­ent instruc­tions, to get an addi­tion­al lev­el of abstrac­tion here. This is a second-generation pro­gram­ming lan­guage. It’s like assem­bly for knit­ters. You know, I could read it but to actu­al­ly knit it I have to trans­late those sym­bols into the appro­pri­ate actions. And since these par­tic­u­lar sym­bols aren’t widely-used, it’s not very portable. Like I’m sure the oth­er knit­ters in the room are going, Roman numer­al 2, what the hell is that?” Like, it’s hard. And so it’s also no longer a one-to-one match with the out­put. I can’t eas­i­ly hold my knit­ting up and make sure it looks right. I know there’s dark lines on there but with­out those it’d be real­ly hard to do error-checking. 

So mod­ern knit­ting charts like this one try to bal­ance abstrac­tion and porta­bil­i­ty with faith­ful­ness to the out­put. We still don’t have a worldwide-agreed stan­dard but we’re get­tin’ there, so the sym­bols are pret­ty wide­ly used. And they look like what they’re rep­re­sent­ing. Like the cir­cles are for yarn overs, which make holes. Forward and back­wards slash­es rep­re­sent decreas­es, because they lean to the left or the right. A cen­tered three-to-one decrease is that sort of bird foot-lookin’ thing. So it con­tains a lot more infor­ma­tion. Like between the sym­bols and the col­ored lines you get like nine pieces of infor­ma­tion in a very com­pact lit­tle space. Looks good. 

But some knit­ters think this can be tak­en fur­ther. The prob­lem they say is that grid. So remem­ber this from my intro. This is called feath­er and fan stitch. And you see it kind of undu­lates up and down real­ly nice­ly. But you don’t get that in an orthog­o­nal grid, you know. You get this: 

Which is con­cise and read­able and all those good things…but does­n’t look like the end prod­uct. So a new syn­tax has pro­posed called Stitch Maps. It’s basi­cal­ly the fourth gen­er­a­tion of knit­ting pat­tern lan­guages, knit­ting charts. And it looks like this: 

And the idea’s that stitch maps let you see how parts of a stitch pat­tern fit togeth­er. So not just the sequence along a giv­en row, but how they inter­act row to row, or clock cycles if you like. And the real­ly cool thing is that stitch maps are com­piled from a domain-specific lan­guage called knit­s­peak. So you can actu­al­ly go to the Stitch Maps web site there, and enter a stitch pat­tern like this: 

This is knit­s­peak, it looks just like a nor­mal knit­ting pat­tern. And it will com­pile that and turn it into a visu­al­iza­tion that looks like this: 

So this is pret­ty much state of the art when it comes to knit­ting charts. 

But what about text pat­terns? So they’ve evolved quite a bit, too. So the first text pat­tern I can find in the English lan­guage was pub­lished in 1655. This is what it looks like, The order how to knit a Hose:” 

Which is basi­cal­ly how to knit a sock. So I know it looks impen­e­tra­ble, but if you’re a knit­ter you can kin­da, sor­ta start trans­lat­ing it, it makes a lit­tle bit of sense. But the UX is ter­ri­ble. It’s long and vague and hard to follow. 

So 200 years lat­er, we’re get­tin’ there. This is 1846. It’s a lot more read­able, you know. The cast on row’s clear­ly marked. We’re using some abbre­vi­a­tions to make things more con­cise. That’s all good. But what’s not great is you know, we’ve still got white­space and indent­ing all over the place. And the abbre­vi­a­tions aren’t just not-intuitive, they’re mis­lead­ing. The P3 here? P does­n’t stand for purl. It stands for plain stitch, which nowa­days we call knit. And the B stands for back­stitch, which is purl. So it’s exact­ly reversed. This is like the whole big-endian/little-endian thing. Like, if I give this chart to anoth­er knit­ter and they don’t know the intend­ed schema, they get the exact reversed output. 

So this is a mod­ern knit­ting pat­tern, anal­o­gous to a third-generation pro­gram­ming lan­guage. So, clear and easy to fol­low, stan­dard abbre­vi­a­tions, bro­ken down into mod­ules, you can swap em in and out. User expe­ri­ence is pret­ty good but…those switch state­ments. I just hate them. And there are so many of them. So again, some knit­ters think we can do better. 

Enter KnitML. KnitML is an open source project with a goal to pro­mote a new inter­na­tion­al stan­dard, an inter­me­di­ate for­mat for knit­ting pat­tern expres­sion. Knitting pat­terns are algo­rithms. And by for­mal­iz­ing a stan­dard in this way, we can allow com­put­ers to make deci­sions about them. And that allows for all sorts of use­ful oper­a­tions. I could down­load a pat­tern with just my size select­ed. I could have it in English or French or German. I could use charts or words, whichev­er I pre­fer. I could even use the abbre­vi­a­tions I like. It could even com­pute out those occa­sion­al­ly mathematically-complex things like increase 17 stitch­es even­ly over 113,” you know. 

And it would have advan­tages for design­ers too, because they could write a pat­tern in the way that makes sense to them, know­ing that their audi­ence could down­load it in the way they pre­fer. And more cru­cial­ly, they could use tests and val­i­da­tion to check for errors. So many knit­ting pat­terns have errors. And they could even use a visu­al­iz­er to pre­view the output. 

So this is what KnitML looks like. And…it’s not par­tic­u­lar­ly com­pact. And it does­n’t look like a tra­di­tion­al knit­ting pat­tern. But remem­ber this is just for com­put­ers to use; it’s an inter­me­di­ate for­mat. It’s not expect­ed that humans would ever direct­ly manip­u­late this. Instead the project pro­vides a tool called KnittingEL, which is Knitting Expression Language, and this is how the design­ers express their pat­tern. And it sort of looks like a pub­lished knit­ting pattern. 

But the project pro­vides Java-based soft­ware to con­vert KnittingEL pat­terns to KnitML which can then be passed on to sup­port­ing soft­ware, as I men­tioned, like val­ida­tors, ren­der­ers, and visualizers. 

So here’s one for exam­ple. This is an open source visu­al­iz­er called Knitter that process­es a KnitML pat­tern and pro­duces a three-dimensional mod­el of the result­ing knit­ted fab­ric. And you can even stretch it and see how it responds. 

This is just the tip of the ice­berg when it comes to open source knit­ting. Like if you go to Github tonight and look—and this screen­shot is old, there’s prob­a­bly more. Hundreds of repos to play with. You know, Go lan­guage imple­men­ta­tions of knit­ting pat­tern parsers. You’ve got cus­tom row coun­ters for your smart­watch. Apps for JPEGs into knit­ting charts. The source code for knit­ting ipsum gen­er­a­tor for your next web site. Instructions for wiring your own row counter which only slight­ly looks like a bomb. 

A knit­ted and felt­ed bag—this is a cool one—with a sewn-in Arduino where you actu­al­ly upload your knit­ting pat­tern, press the but­ton, and it lights up LEDs in pat­terns to indi­cate the next stitch­es that you’re meant to knit. 

Here’s one I myself designed and knit­ted, a beanie for Camp JS (Oh, I have it.) that uses a Gemma micro­con­troller, six LEDs, and a coin cell bat­tery to make myself vis­i­ble up on the misty moun­tain. Is it light­ing up? Oh no, maybe my— I’ll pow­er it up lat­er. Battery’s come undone.

Sweaterify is fun. This is a tool. Lets you upload an image and imag­ine it into an ugly Christmas sweater, and you can even down­load it. But more impor­tant­ly this was built by Mariko Kosaka, who did amaz­ing talk at JSConf last year called Knitting for Javascripters. It’s on YouTube. You should total­ly watch it. And in it she talked about one of the most pop­u­lar crossover knit­ting and pro­gram­ming activ­i­ties, which is hack­ing old knit­ting machines from the 70s and 80s. 

So these are very pop­u­lar. You can pick one up on eBay cheap. Brother made a ton of them. And hack­ing them usu­al­ly involves mak­ing your own ser­i­al cable and using it to upload your own cus­tom designs to the machine. And peo­ple are putting these to some very cool and very weird uses. 

So on the cool side the NeuroKnitting project plot­ted brain­wave activ­i­ty into a knit­ted pat­tern. They used a wear­able EEG to record users’ affec­tive states while lis­ten­ing to Bach’s Goldberg Variations, and then knit­ted that into a scarf on a hacked knit­ting machine. So that is his brain waves while lis­ten­ing to the music. 

Now on the weird side—and warn­ing: night­mare fuel—you’ve got artists like Andrew Salomone and his Machine-Knit Identity-Preserving Bitmap Balaclava. He Photoshopped images of his own head from every angle into a sin­gle rec­tan­gu­lar bitmap and then knit­ted it on a hacked knit­ting machine. 

So my favorite knit­ting tech project recent­ly is KnitYak. You guys might’ve seen it on Kickstarter. So Fabienne Serriere, fbz on Twitter, she’s using a hacked indus­tri­al knit­ting machine in a ship­ping con­tain­er in Portland (because of course) to knit provably-unique scarves using ele­men­tary cel­lu­lar automa­ta. So as a backer I get to choose my own col­ors, rule, and start­ing row. And the rule deter­mines how each sub­se­quent row changes depend­ing on the stitch­es that are encountered. 

So this is where things get real­ly inter­est­ing. Because one of the rules that I can select is Rule 110. And as some of you may know, around the year 2000 Matthew Cooke pub­lished a proof that Rule 110 is Turing com­plete and is capa­ble of uni­ver­sal com­pu­ta­tion. And it can be knit­ted. So giv­en an infinitely-long ball of wool, I can sim­u­late any Turing machine and by exten­sion the com­pu­ta­tion­al aspects of any pos­si­ble real-world com­put­er. Which is pret­ty mind-blowing. 

And that’s me. Thank you very much.

Further Reference

Session page