Skip to main content

KnitPicker - a knitting stitch counter programming project

The art of knitting lace is an intricate process; it takes great skill with knitting and the ability to keep track of complex knitting instructions. One day, my wife Sophie was knitting a particularly complex pattern, and she complained about not being able to keep track of how many stitches she should have for a particular row or how many should be left in the next row. Enter the programmer!


I’ve been throwing together little utilities for myself for ages. Sometimes I want to calculate some value that would take too long by hand; sometimes I want to sort a list in some particular way. Other times I have trouble deciding what to have for dinner, so I’ll write up a list of options and then pop in a random number to pick from it. I have one such script from ages ago that I used regularly when living in Montreal.


It was clear to me that Sophie needed software to handle her problem. With instructions spanning up to a hundred stitches, it’s the sort of thing that’s hard to keep track of in your head, and would take quite a bit of paper to work out by hand. Computers are great at keeping track of numbers and even better at doing arithmetic.


Knitting instructions use a very simple notation: k1 means “knit one stitch,” psso means “pass slipped stitch over,” and so on. These simple steps are listed in sequence to form a row of knitting, and this is the sort of thing a computer is great at processing. The kind of software that does this sort of processing is called a parser. A parser takes a string of characters and breaks it up into individual components called tokens.


I’m not a great parser writer, but I knew of a handy bit of software called Lex. It can analyze different pieces of each token and easily extract numerical information. This made it the right tool for the job, and its ease of use was an added bonus.


I wrote up a quick bit of Lex code, threw together a quick UI with Apple’s Interface Builder, and made the text field update its book-keeping every time the user typed in a new character. This made for a live-updating stitch counter that a lace knitter could use as they worked their way through a pattern. And so KnitPicker was born.


There are some limitations to the software at the moment, such as the lack of support for patterns that contain instructions on repeating a particular section. I had planned to eventually add such support, but never got around to it. Sophie had stopped knitting lace due to problems with carpal tunnel syndrome, no one else was using the software and I had other things to concentrate on.


Had there been other users demanding such a feature, no doubt it would have been added. I did take some time to research the problem, and I’m confident it would not be a big deal.


You can find KnitPicker at my main website, along with other things I’ve thrown together. All in all it was a good learning experience, and for a short while provided Sophie with a useful tool. It’s fun when you can meld your partner’s interests with your own and work out something productive.

Comments

Popular posts from this blog

Losing a loved one, as an atheist

When I was around 11 or 12, I started to question the received wisdom that there was a deity. I came to the conclusion that all signs pointed to no. Do I outright, unequivocally and without reservation deny the existence of such an entity? No. However, I don’t see it as a likely scenario, and until I’m presented with hard evidence, I have enough reason to say that there isn’t. Some people take comfort in their religious beliefs, especially their belief in an afterlife. I have no interest in an afterlife, either for myself of my loved ones. In the past five years I’ve lost both my grandmother and mother, both of whom I loved dearly. No amount of belief in an afterlife would soothe my pain. I mourn at the fact that they are lost from my life, right here, right now. I imagine it’s the same even for those who believe that the dead pass on to somewhere else. You can’t escape the fact that their tangible presence is forever gone from your life. Unless you believe in ghosts, but that’s a

Am I Jonesing for the Internet?

I’m feeling a little agitated and jittery today. My internet access is down due to some nasty snow and wind. Are the two related? They might be. I know I’m certainly missing my twitter friends and feeling less in touch with the world. How long is this weather going to hold? I can’t look that up. Sure, I could pull out a radio and listen in, if I had one. I might somewhere, but I’m at the mercy of the broadcaster to decide when to report the weather and how much of it to report. Some argue that internet access should be a basic human right. Does this point of view hold water? I suppose it could be argued that since the internet allows us to draw together into a larger community that it is an essential part of improving the human condition. Its use in political organizing and to connect dissidents in repressive regimes can certainly help make the case for it as a basic human right. Is the jitteriness really from not having the internet? My doctor did just increase my dose of modafi

Aldebaran Colony

This is a quick little story I whipped together one day as a writing exercise. That's mainly the sort of stories I'll be putting up; 1000 word vignettes that I wrote during a day. Here it is: Why they had thought they needed a podiatrist on the colonization team was something Harry Jones couldn’t figure out. He wasn’t even one of the best podiatrists, although he had his moments. It wasn’t as if he wasn’t happy to be along. He was, in fact, overjoyed when he was given the news. It had just come as a bit of a surprise to him that he had been selected to join the ten thousand other people on the colony ship bound for Aldebaran 5. The ship had been equipped with a new Petrescu-drive engine, which would allow them to cross the distance between earth and the Aldebaran system in about 15 seconds. There had been some hushed conversations between the scientists setting up the engines, but Harry was confident that the colonists’ best interests were being kept in mind. After all, it was