Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Knit 1, Perl 1

Knit 1, Perl 1

Knitting and programming; a creative hobby with sticks and string, and writing complex logic in computer languages - could they be any more different? Actually, they’re not so dissimilar. Let me show you where knitting and programming intertwine!

Katy Ereira

June 10, 2017
Tweet

More Decks by Katy Ereira

Other Decks in Programming

Transcript

  1. @maccath | Katy Ereira | #PHPSC17 Knit 1, Perl 1

    Where Knitting & Programming Intertwine
  2. @maccath | Katy Ereira | #PHPSC17 Programming is... Writing a

    set of instructions that when run on certain hardware perform manipulations and calculations that produce a desired result
  3. @maccath | Katy Ereira | #PHPSC17 Knitting is... Following a

    set of instructions using certain needles and yarn to perform manipulations that produce a desired result
  4. @maccath | Katy Ereira | #PHPSC17 Ok; so knitting is

    more like computing than programming.
  5. @maccath | Katy Ereira | #PHPSC17 But like computer programs,

    knitting patterns are a set of instructions.
  6. @maccath | Katy Ereira | #PHPSC17 These can be represented

    in different ways; many of which draw parallels with computer code.
  7. @maccath | Katy Ereira | #PHPSC17 Worked over even number

    of sts. Row 1: [yo, k2tog] rep. Row 2 & 4: k all sts. Row 3: [ssk, yo] rep. Rep rows 1-4 for pattern. Knitting pattern
  8. @maccath | Katy Ereira | #PHPSC17 Worked over even number

    of sts. Row 1: [yo, k2tog] rep. Row 2 & 4: k all sts. Row 3: [ssk, yo] rep. Rep rows 1-4 for pattern. Knitting pattern - variables
  9. @maccath | Katy Ereira | #PHPSC17 Worked over even number

    of sts. Row 1: [yo, k2tog] rep. Row 2 & 4: k all sts. Row 3: [ssk, yo] rep. Rep rows 1-4 for pattern. Knitting pattern - conditionals
  10. @maccath | Katy Ereira | #PHPSC17 Worked over even number

    of sts. Row 1: [yo, k2tog] rep. Row 2 & 4: k all sts. Row 3: [ssk, yo] rep. Rep rows 1-4 for pattern. Knitting pattern - iterators
  11. @maccath | Katy Ereira | #PHPSC17 row = 5 %

    4 = 1 row 1 row 2 row 3 row 4
  12. @maccath | Katy Ereira | #PHPSC17 Worked over even number

    of sts. Row 1: [yo, k2tog] rep. Row 2 & 4: k all sts. Row 3: [ssk, yo] rep. Rep rows 1-4 for pattern. Knitting pattern - methods
  13. @maccath | Katy Ereira | #PHPSC17 Row = 5 %

    4 = 1 Row 1 Row 2 Row 3 Row 4 k2tog yo yo k2tog
  14. @maccath | Katy Ereira | #PHPSC17 Row = 6 %

    4 = 2 Row 1 Row 2 Row 3 Row 4 Row 5
  15. @maccath | Katy Ereira | #PHPSC17 function pattern(array $sts, int

    $rows) { if (count($sts) % 2 != 0) { throw Exception(“The number of stitches must be even!”); } // ... } Knitting pattern - pattern method, conditionals
  16. @maccath | Katy Ereira | #PHPSC17 function pattern(array $sts, int

    $rows) { // ... for ($row = 1; $row <= $rows; $row++) { // ... } } Knitting pattern - pattern method, iterator
  17. @maccath | Katy Ereira | #PHPSC17 function pattern(array $sts, int

    $rows) { // ... for ($row = 1; $row <= $rows; $row++) { if ($row % 2 == 0) { evenRow($sts); continue; } // ... } } Knitting pattern - pattern method, more conditions
  18. @maccath | Katy Ereira | #PHPSC17 function pattern(array $sts, int

    $rows) { // ... for ($row = 1; $row <= $rows; $row++) { // ... if ($row % 4 == 1) { rowOne($sts); continue; } // ... } } Knitting pattern - pattern method, more conditions
  19. @maccath | Katy Ereira | #PHPSC17 function pattern(array $sts, int

    $rows) { // ... for ($row = 1; $row <= $rows; $row++) { // ... rowThree($sts); } } Knitting pattern - pattern method, more conditions
  20. @maccath | Katy Ereira | #PHPSC17 function evenRow($sts) { foreach

    ($sts as $st) { k($st); } } Knitting pattern - even round method
  21. @maccath | Katy Ereira | #PHPSC17 function rowOne($sts) { for

    ($i = 0; $i < count($sts); $i += 2) { yo(); k2tog($sts[$i], $st[$i+1]); } } Knitting pattern - row one method
  22. @maccath | Katy Ereira | #PHPSC17 function rowThree($sts) { for

    ($i = 0; $i < count($sts); $i += 2) { ssk($sts[$i], $st[$i+1]); yo(); } } Knitting pattern - third row method
  23. @maccath | Katy Ereira | #PHPSC17 // Cast on 20

    stitches $stitches = array_fill(0, 20, new Stitch()); // Knit for this many rows $rows = 10; // Let’s knit! pattern($stitches, $rows); Knitting pattern - usage!
  24. @maccath | Katy Ereira | #PHPSC17 Credit: Hedgehog Fibres -

    https://www.flickr.com/photos/29825916@N05/10784075824/
  25. @maccath | Katy Ereira | #PHPSC17 4 O 3 2

    O 1 O yo k2tog ssk k A Knitting Chart
  26. @maccath | Katy Ereira | #PHPSC17 4 O 3 2

    O 1 rows repeat pattern sts O yo k2tog ssk k key A Knitting Chart
  27. @maccath | Katy Ereira | #PHPSC17 Credit: Karen Blakeman -

    https://www.flickr.com/photos/rbainfo/5427088569/
  28. @maccath | Katy Ereira | #PHPSC17 “ The term "Jacquard"

    is not specific or limited to any particular loom, but rather refers to the added control mechanism that automates the patterning. The process can also be used for patterned knitwear and machine-knitted textiles, such as jerseys.
  29. @maccath | Katy Ereira | #PHPSC17 “ [The] use of

    replaceable punched cards to control a sequence of operations is considered an important step in the history of computing hardware. Jacquard's invention had a deep influence on Charles Babbage.
  30. @maccath | Katy Ereira | #PHPSC17 There are challenges faced

    by knitters, which could be untangled through programming.
  31. @maccath | Katy Ereira | #PHPSC17 Formalisation of Knitting Patterns

    • Translation ◦ “I’d like this pattern to use abbreviations I understand.” • Charting ◦ “I’d like to convert this written pattern into a visual chart.” • Validation ◦ “Will this pattern work, or does it contain mistakes?”
  32. @maccath | Katy Ereira | #PHPSC17 Arithmetic and Calculations •

    Sizing ◦ “How many rows do I need to knit to reach my correct size?” • Shaping ◦ “What stitches do I need to make in order to shape this garment to fit my body?” • Adaptation and alteration ◦ “What size needles should I use in order to knit with this thicker yarn?”
  33. @maccath | Katy Ereira | #PHPSC17 Job Replacement • Test

    knitting ◦ Programmatically knit the pattern and analyse the output; does it work, will it fit? • Technical editing ◦ Validate the pattern; spot knitting mistakes and standardise terminology. • Knitwear design ◦ Create knitting charts and garment templates; easy design & create patterns.
  34. @maccath | Katy Ereira | #PHPSC17 There are difficulties faced

    by programmers, which could be ironed out through knitting.
  35. @maccath | Katy Ereira | #PHPSC17 Staying Sane • Stress

    reduction / avoiding burnout ◦ Participating in a meditative hobby such as knitting can help you unwind • Solving difficult problems ◦ Performing a different activity can free your mind to come up with crafty solutions • Brain training ◦ Strengthen your intellectual fibre by exercising your brain
  36. @maccath | Katy Ereira | #PHPSC17 Knit for Health and

    Wellness - http://www.knitforhealthandwellness.com
  37. @maccath | Katy Ereira | #PHPSC17 Indulge Your Geekiness •

    Mathematical/Geometric Knitting ◦ Moebius scarves, non-orientable surfaces, klein bottles, pi shawl • Coded Knitting ◦ Encoding data in knitting • Fandom Knits ◦ Dr Who scarves, cosplay, geeky motifs
  38. @maccath | Katy Ereira | #PHPSC17 Yarning for more? Knitting

    Help: http://www.knittinghelp.com/videos/learn-to-knit Craftsy knitting classes: http://www.craftsy.com/classes/knitting Knitty - free online knitting magazine: http://knitty.com Ravelry - social network and pattern library: http://ravelry.com k2g2 - “the convergence of brains and crafts”: http://www.k2g2.org