Eboard 01 (Section 1): Getting started

You are probably being recorded (and transcribed) (if the technology is working correctly).

Start of class instructions

  • Optional: Grab a mask
  • Optional: Grab a somewhat grainy with over-sweetened fruit bar
  • Grab one of the business cards that have computer names and locations.
  • Identify where the corresponding computer is.
  • Return the card to the jar.
  • Navigate to the computer.
  • When both partners arrive, introduce yourselves.

Approximate overview

  • Preliminaries
    • Notes and news
    • Upcoming work
    • Extra credit
    • Questions
  • Course goals
  • Course structure
  • ADTs and data structures
  • A quick intro to object-oriented design
  • Designing a stack ADT (an exercise)
  • Implementing our stack ADT (an exercise)
  • Designing an array ADT (another exercise)

Preliminaries

  • Consider grabbing a mask.
  • You should know the “pick a card, find a place” process.
  • If you don’t know the people near you, please introduce yourselves.

News / Etc.

  • Welcome to CSC207!
  • I’m Sam (or SamR).
  • Our class mentor is Maria Rodriguez.
  • We’ll be using two “books” for this course: The readings I write (or wrote) and CLRS4.
  • I type class notes in markdown and post to the Web site.
    • It’s like magic (I hope).
    • See!
  • You will find that I call on students randomly using a set of cards with your names on them.
    • I use this process to give you practice “thinking on your feet”, as it were.
    • I also use this process to help everyone realize that they are not the only one who is puzzled.
    • And I use the process to push you a bit.
    • Feel free to say “I’m not sure” or “I’d prefer not to answer.”
    • If you don’t want to be called on in class, please let me know.
  • We are a community. Treat each other with respect. If you (think you) know more than your partner, support, don’t overwhelm.
  • Sam is facing some personal issues. There may be some hiccups in the class.

Upcoming work

Tokens

I don’t know what your prior experience with tokens is. I give them for academic/scholarly events, cultural events, peer events, wellness events, and a few other things. Only those I record in the daily eboards are available. Please log them within three days.

If you’d like to suggest token events, please let me know in advance of class.

Academic/Scholarly

  • Thursday, 2024-08-29, 11:00 a.m., JRC 101. President Anne F. Harris - Moving Knowledge into Action: Initiatives and Actions in Year Two of the Strategic Plan.

Cultural

  • Thursday, 2024-08-29, 6:00 to 8:00 p.m., Grinnell Museum of Art and environs. Student Night at the Museum.

Multicultural

  • Friday, 2024-08-30, 4:00 to 5:00 p.m., HSSN N1170 - Global Living Room. Middle of Everywhere: Iowa.

Peer

Wellness

Misc

  • Thursday, 2024-08-29, 3:00 p.m. to 7:00 p.m., Central Park. Ag Appreciation Day.

Other good things

Thursday PSA

I historically give a “Friday PSA” (public service announcement). Students have encouraged me to continue doing so. Unfortunately, our class does not meet on Fridays, so I will pretend that we’re a state school, and give you a Thursday PSA. If you find these annoying, let your class mentor know and they’ll tell me to stop.

  • You are awesome!
  • People care about you.
  • So please take care of yourselves.
  • If you consume substances, please do so in moderation.
  • Don’t feel peer pressure to consume or …
  • If you cohabit, be responsible to your partner. Consent is essential (but not really sufficient).

Attendance

  • Since it’s the first day of class, I will take attendance.
    • It will take me at least a few weeks to learn all of your names.
    • For the first few weeks of class, please say your name before you ask or answer questions.
      • Please do so even if I’ve called on you by name. Even if I know your name, your classmates may not.
  • Today’s attendance protocol. When I say your name, answer as follows.
    • “Hi, my name is FORENAME SURNAME.”
    • Optional: “My pronouns are ….”
    • “You can call me PRIMARY NAME.”
    • “If you must address me by surname, you can call me Mr./Ms./Mx./Sr./Srta./etc. SURNAME [San].”
    • “This semester, I’m looking forward to ….”
    • Optional: A question

Excited about

  • This class. [+4]
  • Other classes. [+1]
  • Helping students learn. [+1]
  • Cooking.
  • Hanging out with friends.
  • Making stuff (all kinds of stuff)
  • Sewing.
  • Getting intimidated by Sam.
  • Checking out the hustle and bustle of downtown Grinnell.
  • Meeting new people (and then hanging out with them) (see above) [+1]
  • Reading books (“anything”)
  • AC
  • Living in a single
  • Getting more involved on campus.
  • Exploring nature
  • Passing classes / not failing
  • Living in hammocks
  • Volunteer at animal shelter
  • Living off campus

Questions

Why don’t the students have questions?

They are too nervous to ask questions. Sam is too intimidating.

What IDE will we be using?

Visual Studio Code from Microsoft

What compiler will we be using?

In MathLAN, we use OpenJDK 17 or so.

You can use newer versions if you’d like.

Can we run it on our personal computers?

If you trust Microsoft products.

VSCode is a PITA to configure, so it may take some work. Sam can help you with Linux and macOS, but refuses to try to figure out Windows.

Why is Sam intimidating?

Have you gotten your reading response graded yet? “Wow, this is crap.”

Large white-presenting male syndrome

Sarcastic

Makes JJ act as model for the class

What’s your least favorite color?

The dark green that I can’t distinguish from black.

How do you set up JUnit 5?

Stay tuned. We’ll talk about it when we do unit testing. (Or use Maven, and it should get installed automatically.)

Why is teams transcription working well? Isn’t it a Microsoft product?

I have no idea.

How do I get as good with the terminal as you are?

Practice. Not the 10,000 hour crap, but practice.

How do I get an A in the class?

Take notes. Do the work. Ask questions when you get stuck. Take advantage of redos. Go to mentor sessions. Don’t cheat.

What’s your favorite part of teaching at Grinnell?

Awesome students (especially those who I maintain connections with over the years).

What’s Maven?

A build tool (like Make, except specific to Java and somewhat on steroids)

Questions from the reading responses

Was there a reading?

Yes. It was on the schedule. I thought it was also in the email. Did you not get the email?

Could you explain the relationship between traits, mixins, and Java’s forms of polymorphism?

Perhaps after we’ve discussed Java’s forms of polymorphism.

Maybe explain the concept of Polymorphism and Inheritance, because I remember learning it from CSC 161, but have forgotten some things that I don’t remember specifically.

We’ll do those in depth in a week or two.

How should we know what strategy to choose for SAM to be efficient? It feels like we can choose anything but I don’t understand the differences until I start writing the methods.

Our goal in ADT design is not efficiency; it’s to think through how we want to use the data. What do we want to be able to do? It’s only once we look at implementations that we start thinking about costs.

How does the Layout of LIA (AAA) affect the outcome? Is there anything specific to look out for when choosing the layout for ADT?

Different layouts will lead to different costs. We should see that when we explore different implementations of stacks.

You may remember this from getting, say, the 100th element of a vector (quick) vs the 100th element of a stack (slow).

I felt sloppy answering these questions. I mostly used what I knew from C, and I had trouble envisioning how this would work in an OO environment. If you could go into more detail about these data structures are implemented in Java that would be splendid.

We haven’t done any Java or OOP yet. I wouldn’t think that you’d approach them that way. We’ll look at them as C structures or functions for the time being. We’ll return to stacks and such in an OO model in a few weeks.

How would the basic data structures we learned in 161 (stacks and queues) be implemented within Java/OOP without using pseudo-code?

We’ll cover those in a few weeks, once we’ve learned about objects (and perhaps even generics).

For the arrangement question, what were you thinking about as “other data”?

For context, that question reads “Describe a way you might arrange a stack in memory. (You might represent the stack as a linked structure or an array; what other data would you store in each case?)”

If I were storing the stack as an array in C, in addition to the array, I would also store the size of the array (I might call that the “capacity” of the stack) and the number of elements in the stack.

struct StackOfStrings {
   char **elements;
   int capacity;
   int size;
};

Although a linked implementation of stacks might only require one pointer, a linked implementation of queues often requires two (one for the front of the queue and one for the back of the queue).

I’ve read that there are 4 principles: Abstraction, Polymorphism, Encapsulation, Inheritance. The way the reading laid it out is a bit different: Encapsulation, Inheritance, Polymorphism, Composition. Especially in the Encapsulation part, it seems a bit difficult to differentiate between that and Abstraction. Can you go deeper into these 2?

Great question! Let’s wait until we’ve played with them a bit more.

If there is time maybe an example of a minimalist design ADT?

Yup, we’ll do that for stacks today.

If possible just re-explain how ADT and data structures work together

The ADT is the what. That is, what you want to do with your data. The data structure is the how. That is, how we achieve those goals.

In reality, the border can be a bit fuzzy.

Alternately, the ADT is the .h file and the data structure is the .c file. At least that holds if we’re thinking about collections of values.

How many tokens do we start with?

Three.

Is there a limit to how many tokens we can earn?

Time. Sanity.

Course goals

Get started learning how to be a computer scientist / software developer.

  • Larger projects.
  • Working with “professional” tools. IDE, Build tools, weird language features, version control systems (Git).
  • Working in teams.
  • More need to look/think on your own.
  • Learning many more of the “core ideas” of algorithms and data stuctures
  • A bit more math!

Course structure

  • Many days will be working in randomly assigned pairs on a set of problems.
  • Some days will be collaborative design. (TPS)
  • Weekly homework assignments (mini-projects)
    • Ideally, you will be inspired to extend some of these.
  • Way too many learning objectives and learning assessments.
    • Most are “Provide me with evidence that you’ve learned this.”
    • In spite of this sounding comparatively easy, evidence suggests that most students need at least one redo.

ADTs and data structures

Don’t forget to ask me when I use a TLA that you don’t understand.

ADTs: Abstract data types. In effect, a set of operations that you want to do on a collection of data. (E.g., push, pop, peek).

Data structures: How we organize those data in memory to achieve the operations.

ADTs are more abstract, data structures are more concrete.

Designing a stack ADT (an exercise)

We will use the Think-Pair-Share (TPS) process. You’ve already thought to yourself (or should have, since it was an assignment). Now it’s time to pair with another person and discuss your answers. Then we will share with each other.

ADT: Use the SAM approach for ADTs.

  • S: Strategy (organizing principle)
  • A: Applications
  • M: Methods

Note: This used to be the PUM approach. I thought SAM was easier to remember. (Philosophy Uses Methods)

Strategy

  • Stacks are collections of data in which you can add and remove data. You add and remove data only at the “top” of the stack.
  • Stacks follow a last-in, first-out policy; the thing you remove is the most-recently-added of the things still on the stack.

Applications

  • Back button on browser.
    • Forward button seems to depend on various things.
    • Often, a forward button requires a second
    • [There were hand gestures. Imagine them.]
  • Atoms in a water heater
  • The sequence of operations we use to set up a factory or other thing.
  • Edit operations in an editor
    • To do redo, you have two stacks

Methods

We will assume that it’s a stack of strings. We will also assume that we’re implementing it in C.

Please make sure you consider parameters, return types, preconditions, potential questions the client of your stack might have, etc.

I’ll divide your answers into “core methods” (the ones we probably can’t do without) and “optional methods” (the ones we could implement with the core methods if we wanted to).

Core methods

  • void push(struct Stack *stack, char *elt) - adds an element to the stack
    • We pass a pointer so that we can modify the stack.
    • If we are using null to indicate that stacks are empty (see below), we probably can’t push null.
    • Implicitly: The stack has been allocated and initialized.
    • The stack can’t be full (whatever that means).
    • Note: We could also have this return a boolean or integer, with 0 meaning success and any other number meaning failure.
    • Question: Do we simply copy the char *pointer, or do we allocate new space and copy the string? (Decision: Just the pointer.)
  • char *pop(struct Stack *stack) - returns and removes the top value in the stack. Requires that the stack is nonempty.
    • Alternate: Could return a special value (null) to indicate that it is empty.
  • int is_empty(struct Stack *stack) - determines whether the stack is empty. Returns 1 if it is and 0 otherwise.
  • int is_full(struct Stack *stack) - determines whether it is safe to push. Returns 0 if it is and 1 otherwise.
  • struct Stack *new_stack(); - allocate and initialize a new stack. Returns null if it is unable to do so.
  • void delete(struct Stack *stack) - remove everthing from the stack and deallocate memory associated with the stack.

Why we need to know about what we’re copying.

char *str = (char *) malloc(10*sizeof(char));
strcpy(str, "hello");
struct Stack *stack = new_stack();
push(stack, str);
strcpy(str, "agh!");
printf("%s\n", pop(stack)); // This should print "hello"

Observations

  • If we copy only the pointer, we’ll make sure we have the same string.
  • If we copy only the pointer, we’ll use less memory.
  • If we copy only the pointer, we won’t have to worry about freeing the string after we pop.
  • If we copy only the pointer, changes to the underlying string get propagated to the stack, leading to some odd behavior.
  • If we copy only the pointer, and the pointer is from the middle of a procedure, and we pop outside the procedure, who knows what will happen.

Either decision is fine. But you should know what you’re doing. (Note: In Java, we won’t have to worry, because strings are immutable.)

Side notes

  • Remember that the strutures we are building are intended to support other code; they should not communicate with the user.

Almost-core methods

  • char *peek(struct Stack *stack) - returns but does not remove the top value in the stack. Requires that the stack is nonempty. (Could be implemented with pop and push.)
  • int size(struct Stack *stack) - probably can’t be implemented separately, but may not be necessary.
  • void clear(struct Stack *stack) - remove everything.
while (! is_empty(stack)) 
  {
    pop(stack);
  } // while

Optional methods

  • char *concatenate(struct Stack *stack) - build a string consisting of everything on the stack.
  • void for_each(struct Stack *stack, char *fun(char *str)) - do something with each string in the stack.
  • void remove(struct Stack *stack, char *str) - remove all copies of the str from the stack.

Implementing our stack ADT

We’ll use the AAA approach (which used to be the LIA approach and may get renamed again).

  • Arrangement: How do you lay out the structure in memory?
  • Algorithms: Given that arrangement, how do you implement the methods? (Broadly; we don’t need all the code.)
  • Analysis: Given those implementations, how efficient are the methods?
    • We will usually ask how many steps they do as a function of the number of values we’re working with.
    • We might also ask how much space we use.

Stack arrangements

  • Arrays
    • With newest at front
    • With newest at “back”
    • With or without extra space.
    • Requires that we store the array (char **) along with the capacity (an int) and the size (another int)
  • Linked list
    • With newest at end (keep track of the head) (and tail)
    • With newest at front (keep track of the head) *

Algorithms, Arrangement 1 (???)

Analysis, Arrangement 1 (???)

Algorithms, Arrangement 2 (???)

Analysis, Arrangement 2 (???)

Algorithms, Arrangement 3 (???)

Analysis, Arrangement 3 (???)

Another ADT: Unsized arrays

One of the skills I hope you’ll develop in the course is the ability to design new things (most often, ADTs and data structures). Hence, in addition to labs, we’ll spend a reasonable amount of class time on design problems. You had a lot of time to think about stacks. You’ll have less time for this.

I’ll ask you to take a full minute to think to yourself before you pair and then share.

Unsized arrays: Strategy

I want things that I can use like arrays, but I don’t want to have to specify their capacity in advance. They should always be big enough for how I’m using them.

I’d also prefer not to have a different syntax for arrays than for the structures I build myself.

Unsized arrays: Applications

Unsized arrays: Methods

Core methods

Almost-core methods

Optional methods

Implementing ADTs

If we’re lucky, we’ll have the time to talk through some of these.

Arrangement

Algorithms

Analysis

Probably not this one.