Section outline

    • In which we take a list of things and perform an action for each of them.

      Exploring Young’s preface using JS

      🏭 Guided activity
      What did you google?

      • preface.split(' ').length
      • preface.split(',')[0]
      // First, split the preface to sentences.
      sentences = preface.split('. ')
      
      // Second create an empty container for sentence lengths.
      sentence_lengths = [];
      // Third, get the length of each sentence and add it to collection.
      sentences.forEach(sentence => {
          len = sentence.length;
          sentence_lengths.push(len);
      })
      
      // Finally, print the number of "w"s each sentence is long.
      sentence_lengths.forEach(len => {
          bar = "w".repeat(len);
          console.log(bar);
      });

      🏭 Guided activity
      What characterizes a list?

      The comma: ,

      It looks kind of like a dot . but which is falling . ,. What else might be falling?

      IMG_20220926_104843

      Photo by Mace Ojala (CC BY-NC-SA)

      Read the following code aloud by saying all the words which are familiar from English language.

      • Say autumn = [] as “let autumn be the empty list”
      • Say "==" as “equals”
      autumn = [];
      preface.split("").forEach(letter => {
          if (letter == ",") {
              autumn.push("🍂")
          } else {
              autumn.push("🍃")
          }
      })
      
      forest = autumn.join("")
      console.log(forest)

      It is an autumn simulator! Observe a new, important concept: the if/else conditional.

      🏭 Guided activity
      What variation of the above program could you do for another text that Young’s preface? Try an email, your thesis, or a transcript of a famous speech.

      🏭 Guided activity
      Discuss what is a list, according to Young?

      Further into the introduction chapter, Young’s introduces lists as cultural techniques, Kulturtechnik (Siegert, Krämer etc.)

      • How to explain this persistence?
      • What can its varying historical functions teach us about the list’s ability to survive shifts in ways of knowing?
      • By collecting and materializing information, do lists create fields of knowledge?
      • How do they structure the way data and knowledge circulate?
      • What are the ethics of listing, a technique that has been complicit in the administration of human populations and in the ‘disenchantment’ of the modern world?
      • Does list-making offer opportunities for challenging dominant systems of classification or ways of knowing?
      • What is the role of the list in digital media environments, and in human artistic expression

      Young moves from “what lists are?” to “what lists do?” (pp. 16-17). A media practice question!

      [!tip] Check out the rest of Young’s work about lists

      Booleans: true and false

      Above we encountered the equality test \==, as well if/else branching. The binary logic of true and false is possibly the most quintessential idea of the digital, and of computer and computer programming. True and false are often represented with 1 and 0.

      document.querySelector('video').loop = true;
      animals.includes('sirens');

      The two booleans values are used to make decisions, and it is the essence of computer control and decision making… and not only in computers. The values are combined with logical operations or, and and not. All of this talk about truth, falsehood, and, or and not is perfectly familiar from everyday speak and thought, although more loosely applied. Informal logic is perfectly familiar from the everyday, and a truly classic topic in Philosophy! 💕 We can connect different logical value with “and” (&&), “or” (||), and “not”.

        operator   what’ the result?
      true or false  
      true and false  
        not true  

      Conditional execution

      “Control flow” of a program, “branching” based on decisions in familiar, if-else logic. In this are or programming, reading code aloud can really help understanding.

      in JavaScriptS syntax

      if (condition) {
          do_this;
      } else {
          do_that;
      }

      The condition can be a lot of things which can be expressed as either true or false.

      Informally

      if (tired) { // tired is a boolean; either true or false
          sleep;
      } else {
          make_techno_on_synthesizer;
      }
      Diagram by Mace Ojala (CC BY-NC-SA)

      A special case: by default do nothing

      if (tired) {
          sleep;
      }
      Diagram by Mace Ojala (CC BY-NC-SA)

      Examples of conditional execution

      animals = ["belonging to the emperor", "embalmed", "tame", "suckling pigs"]

      Example 1. Branching

      if (animals.length > 15) {
          console.log("Oi it's crowded here!");
      } else {
          animals.push("sirens");
      }

      Example 2. Empty else

      if (! animals.includes("sirens")) {
          animals.push("sirens");
      }

      Example 3. A while loop

      while (animals.length <= 15) {
          animals.push("sirens");
      }

      Two kinds of loops are the for loop and the while loop.

      Example 4. A coin flip

      // Random comparator function
      
      function random_choice(a, b) {
          random_number = Math.random();
          if (random_number < 0.5) {
              return -1;
          } else {
              return 1;
          }
      }
      chaos = animals.sort(random_choice)
      console.log(chaos)

      Actually randomness is hard, but this is sufficient for us now.

      On a Moodle page

      container = document.querySelector('.section').parentNode;
      Array.from(document.querySelectorAll('.section')).sort(random_choice).forEach(a => {
        container.appendChild(a)
      })

      On your email

      inbox = document.querySelector('#messagelist > tbody');
      
      Array.from(inbox.children).sort(random_choice).forEach(email => {
          inbox.appendChild(email)
      });

      On Instagram

      feed = document.querySelector('article').parentNode;
      
      Array.from(feed.children).sort(random_choice).forEach(post => {
        feed.appendChild(post);
      });

      🏭 Guided activity
      Discuss where you encounter sorting on the web. What are the items being sorted, and by which criteria are they sorted. Can you influence it? How would you like them sorted? Could you describe it algorithmically?

      Exploration of conditional execution

      • Read Chapter 5 “Logistics: Listicles, Algorithms, and Real Time” of Liam Cole Young. 2017. List Cultures. Knowledge and Poetics from Mesopotamia to BuzzFeed
      • Prepare for Show and Tell about your exploration.