Homework 3: How The Tables Have Turned

Due: Tuesday February 11, 2020 at 9:00PM EST.

Setup and Handin

Setup

Handin

Remember your resources!

Useful Functions

The Assignment

Part 1: Nicknames

After placing an ad in Homework 2, Giselle has fallen in love with the marketing industry. She decides to start her own ad agency! Realizing that any proper business has a team, she hires a posse of Livia, Floria, Colton, and Monica. To establish fun vibes in the workplace, Giselle decides to give nicknames to her gang.

She formats each nickname as a String in a specific way by pairing a real name and a nickname with diamond brackets and a comma. Even though this is the Wild West, she has some strict conditions for which nicknames are allowed. Help her figure out which nickname options are valid!

Requirements for a valid nickname pair:

Task: First, write tests in the hw3-tests.arr doc for nickname-check. The function takes in a nickname pair String and returns true if the pair follows the rules, and false if it does not. Be sure to write comprehensive tests to examine the behavior of the function across various types of acceptable input. Of the 7 broken solutions (the bugs you are trying to catch), 5 of them are from errors in nickname-check. The other 2 will be caught in Part 2. Do not use the given examples below as part of your testing.

Example tests (to go into the check block):

Task: Now, fill in the function nickname-check in the file hw3-code.arr. Since you already tested this function in the other document, you do not need a where block for this function. Make sure to include a doc string and a type annotation.

Note: Being able to look in language documentation for useful operations is an important skill, which is why we aren’t telling you exactly which String operations to use. We want you to look at the String documentation to find useful operations for solving this problem. However, limit yourself to operations with input and output types that we have used this semester (Number, String, Boolean). Don’t use operations that return List, as we haven’t covered that yet.

Part 2: More sophisticated ad matching

Following in the footsteps of her former foes, Giselle wants to make targeted ads. She realizes she can sell more ads by improving how she matches ads to users. In particular, she wants to consider more information than someone’s age, what kind of work they do, and what sort of place they live in. Now, she also wants to consider (in an anachronistic way) how much someone uses a mobile phone (“never”, “sometimes”, or “frequently”) and whether they ride horses.

If we updated our show-ad function from Homework 2, we’d get a function header like:

fun show-ad(target-age :: Number, job-area :: String, 
  place-type :: String, mobile-usage :: String, 
  rides-horses :: Boolean) -> Boolean:
  ...
end

How messy! If next week she added another collection of criteria, this would become even more unwieldy. Having the criteria as their own inputs doesn’t scale. We need a way to enable growing the set of attributes without making a mess of our code.

Instead of passing the criteria for each ad as a separate input, what if we somehow bundled the infomation about the ad into one piece of data? For example, we could make a Table with one row that has the information about the ad which we’re checking against the constants that describe Giselle. For example:

table example

Now, our show-ad function can look like:

fun show-ad(ad-info :: Table) -> Boolean: 
  ...
end

Part 2A: Taking into account new parameters

Note: It is very important that you make sure to use the CS0111 Table documentation, not the official Table documentation.

Now we will implement the changes to show-ad using the new definition which takes in a Table containing five columns and one row.

Task: Copy your show-ad function from your hw2-code.arr document into your hw3-code.arr document (you can find your hw2-code.arr file in the code.pyret.org folder within your Google Drive).

Then, edit show-ad by doing the following:

Task: Change the input to a one-row table and edit the function body accordingly. The input table could be any table with one row and the five expected columns. Make sure you can get the code to run by writing some tests (you will need to explicitly create several tables with one row each to use as test cases). Feel free to fix any issues from last week’s code in the process.

Task: We need to check whether the horses match (i.e. if someone rides horses and the ad wants horse-riders). Should this be its own function or should you just check it directly in show-ad? What are the advantages/disadvantages of each? Write a comment below show-ad answering these questions.

We’re going to use helper functions for this.

Task: Fill in the horses-match function, which takes in a Boolean and returns true if Giselle’s horse status matches that of the ad. Check whether the horses match.

Task: Fill in the check-phone-usage function, which takes in a String representing the desired phone usage of an advertiser. The input String must be either “frequently”, “sometimes”, or “never”. The function should return true if Giselle’s phone usage is at least as high as what the ad wants. For example, if Giselle’s phone usage is “never”, the function should return true if the input is “never”, and false if it is “sometimes” or “frequently”. If the input is not one of the three acceptable strings, simply return false.

Make sure your show-ad function uses horses-match and check-phone-usage along with other helper functions.

Part 2B: Excluding what the ad doesn’t care about

Sometimes, the ads that we are checking don’t care about all of the possible attributes of someone. For example, we might not care about someone’s age if we just want to sell a lasso to people living in Oatman.

Specifically, how might you create an ad-table for an ad that doesn’t care about someone’s job area or target age? One idea is to leave the table cell blank. For the purposes of this assignment, we consider a String to be blank if it is an empty string (which we write as “”) and a Number to be blank if it is negative.

Task: Write comprehensive test cases for show-ad in hw3-tests.arr (2 of the 7 bugs will be for show-ad). Take into account both the changes in Part 2A (new parameters) and the possible “blank” values. You can feel free to copy your tests from hw2-tests.arr and edit accordingly.

Task: Modify your code for show-ad to handle blank values for job area and target age. The challenge here is to figure out when and how to handle these blanks. You do not need to handle blank cases for anything besides job area and target age.

Task: Could you use this same technique to handle whether someone rides horses? Why or why not? Are there other downsides to taking this approach? Write another comment under show-ad answering these questions.

Part 3: These Ads Think that They Know You

Building on this assignment’s code and last assignment’s ethical readings, we are asking you to read an article and reflect on the implications and possible ethical designs of computing and data.

Task: Read this short article on how information about every part of our lives can be used not just to target us but to invisibly manipulate others for economic and political ends. (You can use this guide to access the New York Times through a free academic pass if needed.)

Task: Answer the following question in a paragraph comment at the bottom of your code file.

Reflect on the online ads that you usually encounter, and think about the personal information that surveillance companies might have been collecting from you. To you, what factors should ethical data collection take into consideration? Consider the following:

There is no right or wrong answer here. Our goal is to get you thinking about the context of the technical content of the course. Your answer should be clear and concise, with enough specifics to show that you are thinking about the question beyond a surface level.

Task: Please add a comment at the bottom of your code file with the approximate number of hours you spent on this homework. This will be used only to average how long the homeworks are taking students this semester, and it is completely anonymous. Thank you for working to help us improve this class as we grow!

Theme Song

Turning Tables by Adele


Brown University CSCI 0111 (Spring 2020)
Do you have feedback? Fill out this form.