SO. I do lots of crafty shit. I also do lots of coding shit. I knit/crochet on the TTC (where I meet ALL the cool people of Toronto), and at lunch. Invariably, one of my colleagues will look at my pattern and go "DEAR ME, THAT'S CODE"
(everyone sounds like this in my head).
(everyone sounds like this in my head).
And if you've done any kind of programming, it is! A knitting/crochet pattern is a list of instructions that you run through in some order to execute a thing.
An example:
An example:
So as I was talking* about a few weeks back, @Helena_LB got me into crochet and I made this splendid shawl!
*complaining
*complaining
The shawl, in addition to being a thing your stylish babushka would 100% wear is also a while loop. In coding, if you have a pattern that needs to repeat until a (set of) condition(s) is met, but you don't necessarily know when that will be, you use a while loop.
For this shawl, I started off with a single pattern of stitches and continued that pattern until the shawl was the size I wanted it. I am also still not convinced crochet isn't witchcraft.
In code, it might look like this:
while shawl != the right size:
add(1 new stitch)
crochet(1 row of pattern)
add(1 new stitch)
add(tassels)
(note: != means 'does not equal')
while shawl != the right size:
add(1 new stitch)
crochet(1 row of pattern)
add(1 new stitch)
add(tassels)
(note: != means 'does not equal')
Here, I start the pattern, and keep adding to it until I have the size I want. The loop is then complete and I can add the tassels.
pattern here: https://www.ravelry.com/patterns/library/almost-a-granny-triangle-scarf
pattern here: https://www.ravelry.com/patterns/library/almost-a-granny-triangle-scarf
With knitting, I make a lot of hats and mittens. These have repeating patterns over a finite, usually pre-determined number of iterations.
Do you know what that means?
Aw yiss. For loop time.
Do you know what that means?
Aw yiss. For loop time.
With a for loop, you're running through a (set of) pattern(s) x number of times. The x is the index, and you need to figure out what that is ahead of time.
These are called Newfoundland mittens...according to Nanny it's "because the Newfoundland women used to knit them, love"
These are called Newfoundland mittens...according to Nanny it's "because the Newfoundland women used to knit them, love"
For these mittens, we need 11 alternating rows of pattern, breaking after the 4th repetition (or iteration). We could set the index variable like this:
index = [1 2 3 4 5 6 7 8 9 10 11]
For row 4, we'll need to change the loop to put in the thumb
index = [1 2 3 4 5 6 7 8 9 10 11]
For row 4, we'll need to change the loop to put in the thumb
Our loop might then look like this:
for i =1:length(index)
if index(i) == odd
knit(pattern)
else if index(i) == 4
knit(thumb pattern)
else if index(i) == even
knit(pattern2)
for i =1:length(index)
if index(i) == odd
knit(pattern)
else if index(i) == 4
knit(thumb pattern)
else if index(i) == even
knit(pattern2)
Note: index(i) is calling the "ith" variable in "index". We've set i to the length of the index (11), so if i = 1, we go to the 1st element of "index", which = 1!
Also, I've snuck some if/else statements in there. Where we want the pattern to change between even and odd iterations, we've told the loop to check the number of the index, and decide which pattern to use based on that.
Important: if you put the special instructions for iteration 4 AFTER the even-number statement, we're going to have a pair of thumb-less mittens. Which is sub-optimal.
Alternate code here:
index = [1 2 THUMB 3 4 5]
for i = 1:length(index)
if index(i) == THUMB
knit(thumb pattern)
else
knit(pattern + pattern2)
end
knit(pattern)
index = [1 2 THUMB 3 4 5]
for i = 1:length(index)
if index(i) == THUMB
knit(thumb pattern)
else
knit(pattern + pattern2)
end
knit(pattern)
This one's a bit more streamlined and crams both inline and offset patterns together. After the loop ends, we add on an extra pattern round to get the 11th row.
Pattern with lots of pictures here: https://docs.google.com/document/d/1xk-TviCRIDXfrStyQbr-4xWet_0FA5r2bR5mU9oM0sc/edit
Pattern with lots of pictures here: https://docs.google.com/document/d/1xk-TviCRIDXfrStyQbr-4xWet_0FA5r2bR5mU9oM0sc/edit
And, because craft and code are two branches on the same nerd-tree, we combine. Like this hat!
We start off at the bottom with a for-loop of ribbing, then a for-loop of pattern stitches that continues for 3 iterations, then finish with a while loop until it's head-sized.
We start off at the bottom with a for-loop of ribbing, then a for-loop of pattern stitches that continues for 3 iterations, then finish with a while loop until it's head-sized.
A common for/while loop combo is the dreaded scarf. A lot of people recommend starting with scarves. This is a terrible idea. Scarves take for fucking ever. And then you have to keep going.
Here's one I made for my mother-in-law, and gets us to debugging. There's a bug in this code (dear Liza, dear Liza), and I didn't notice until WAY TOO LATE:
The raised stitches are supposed to go over/under/over, but they don't. Here, what past-Sarah could have done was undone all of the work up to this point, then started from before the bug, fixing the iterations in question.
(Narrator: she didn't)
(Narrator: she didn't)
...and if I've said it before, I will SURELY say it again: https://twitter.com/sciencebanshee/status/1074676967562194945
Another type of knitting is colourwork. These fancy bastards are a pair of mittens I made last winter:
Colourwork, to me, is a lot like data visualization/plotting. You have data (stitches) and need to take them from one space (the pattern) and put them into another space (reality).
And this brings me to one of my favourite sources of dudgeon. Most of the needleworkers I know are ladies, and many, though far from all, of the coders I know are dudes.
It wasn't always this way. Back In The Day, coding, like needlework, was seen as "women's work": https://www.history.com/news/coding-used-to-be-a-womans-job-so-it-was-paid-less-and-undervalued
And the contributions of these human computers were often overlooked. This was *especially* true for women of colour: https://www.pbs.org/wgbh/americanexperience/features/chasing-moon-women-who-brought-us-moon/?utm_source=FBPAGE&utm_medium=social&utm_term=20190617&utm_content=2405156068&utm_campaign=American+Experience&linkId=69034461
And this makes me think about my grandmother, who crocheted, knitted, sewed, and embroidered, often designing and altering patterns to suit her; but who didn't consider herself particularly well-educated.
There's a fuckload of math and engineering here.
There's a fuckload of math and engineering here.
A necessary sidenote: needlework is metal as hell: https://www.atlasobscura.com/articles/knitting-spies-wwi-wwii
So where are we today? I work with a bunch of excellent folks, many of whom are women, who absolutely kick ass at coding. It's great. And we're getting into interesting questions re. computers and creativity: https://www.theatlantic.com/technology/archive/2018/03/the-making-of-skyknit-an-ai-yarn/554894/
(amazing SkyKnit patterns here. All songs and tributes forever to @JanelleCShane): https://www.ravelry.com/patterns/library/skyknit-the-collection
And there are people talking about this all over the internet! https://twitter.com/web_goddess/status/1144003866020605952
So. If you're a crafter who's curious about coding, or a coder who's curious about crafting, DO IT. It'll be a party.
Thanks for reading and I'll see you around #ScienceTwitter, #KnittingTwitter, and #ScientistsWhoKnit.
Much love.
Much love.