GWU

CS 1111

Introduction to Software Development

GWU Computer Science


Lecture Notes 01: Computational Thinking, Programming, and Design


Objectives

By the end of this module, you will be able to:




Before Starting

If you do not have your Codio course ready, use any text editor or simple IDE. Some possibilities are:




The Abstraction Ladder and The Black Box

If it sounds like a Sci-Fi novel, you are not wrong. This is concept allowed humanity to learn more and organize their thoughts.

The essence of abstractions is preserving information that is relevant in a given context, and forgetting information that is irrelevant in that context.

John V. Guttag MIT

Computer Science is the science of abstraction.

Gabe Parmer GWU

Abstraction is what allow us to have conversations without specifying absurd levels of detail. Think about how you order a Pizza:

Example 1: Think about how you order a Pizza:

  1. Call the pizza place
  2. Ask for a menu Item (pepperonni pizza)
  3. Give address and pay information
  4. Hang up

This is a very high-level of abstraction in which the context is clear to both parties and you both already know what every key word means. It is high-level because the details are not needed, only the context.

Example 2: If you were teaching an alien (that has never even heard of what a pizza is) to make a pepperonni pizza from scratch, you can't simply say "make me a pepperonni pizza". You'd have to go into great detail about it. Asuming the alien speaks english and all the ingredients are there and they are labeled and identifiable:

  1. Place 4 cups of bread flour, 1 teaspoon of sugar, 1 envelope of yeast, and 2 teaspoons of salt in the bowl of a stand mixer.
  2. Mix, adding 1.5 cups of water and 2 tablespoons of olive oil and beat until the dough forms into a ball.
  3. ETC (you get where this is going)

This is a very low-level of abstraction in which the context is not used (much) and great detail is needed to make progress.

Activity 1 :[2 minutes] You will be assigned to a random Breakout room. Come up with an activity where it is possible to instruct someone how to succeed using only high-level concepts; Also come up with one activity in which you are usually forced to give very low-level instructions.

Abstraction in this class

In this class, we will use abstraction to analize a problem and design a solution for it.

Analysis: We will break the problem into parts and identify the high-level steps to follow in order to complete each task. After we understand the problem, we must design a solution.

Design: We will follow a careful approach to solving problems:

  1. High-Level Sketch: first write (or draw) the solution using english (or diagrams)
  2. Sanity-Check: try your solution for some test cases and see if the expected solution is obtained
  3. Pseudo-Code: Identify which programming elements can be used for each part of the Sketched solution and rewrite the Sketch with the general use of these elements (no details)
  4. Code: Write (Edit) each module of the solution using appropriate programming language
  5. Correct: fix any spelling errors in your code
  6. Test: Teast each module by running it with input for which you expect known output
  7. Debug: If you have any unexpected output go back and fix the logic of your program


Steps 1-3 we call "Planning".


Steps 4-7 we call the ECT process (Edit, Compile, Test):


Algorithms vs Programs

Algorithm: The High-Level steps to solve a problem. This corresponds to the Planning part above.

Program: The algorithm implemented as a set of steps written with correct syntax, and using a set of existing programming features. This corresponds to the ECT part above.


Planning a Solution

This part is mostly creativity, insight, and experience. This is where puzzle solving skills and mathematics, and imagination let you come up with solutions.

Activity 2:[2 minutes] You will be assigned to a random Breakout room. Please discuss a possible high-level solution (in english) for the following problem:

If you are given any 3 objects (a, b, and c), how can you find the one with the minimum weight?

Note: I'll ask one of you to volunteer a description of theirgroup's solution. You can:
  • Raise your hand in BBUltra and i'll ask let you speak when I call on you, or
  • You can write your solution on the chat

What is the point?:
For some problems, it is enough to discuss them in english to solve them and do a sanity check. In this case, sanity checks would mean verifying that your method works for other instances of the same problem.
For example, if the weights are represented by numbers, then:

Have you thought of everything?:
For some problems, you should consider odd cases or problematic ones that might need a decision.
For example, if the weights are represented by numbers, then:
Terminology: Checking (exploring) these sanity-check cases is called exploring the solution space.


What about the Simplified Code?:
Once you have a proposed solution in english, you can either simplify the language to its minimum representation ot draw a sketch.
Here is a simple sketch of an incorrect possible solution for the minimum number problem:

Why is it wrong!
Having a sketch allows you to see your english solution in a compressed form and it might reveal some problems!

Pseudo-Code: We'll show you a way of writing this in simplified code form.

Sanity Checks: You can try the above options with either method to verify it works.



Basic ECT process:

Activity 3 :[2 minutes] Go to Codio 1.03 and modify the provided code so that when you press the blue button, the Compilation fails and reports an error.
Remove the semicolon at the end of the print instruction and press RUN:

Now correct the error and press the button again.

We can also Compile using the Terminal.

Activity 4 :[2 minutes] Go to Codio 1.05 and follow along while I perform the compile and execute actions. We will intentionally cause errors and study what happens.

Very soon we will be doing more complex things than printing "Hello, World!". At that point, we will work on one of the most important skills in programming (and logic): Debugging.




Abstraction when programming: The Black-Box approach

The point of planning is to find the general structure of the solution, in terms of a series of steps from operation-to-operatoin or module-to-module.

If you get here, you are taking for granted that each module simply does its job. That is treating a module as a black box.
Using a module as a black box is like saying: "I don't care how it works, I only need to know what I need to give it and what it gives me in return."

We'll make a rough analogy with ordering a pizza:

At the high-level, we only need the inputs (pizza order and money) and outputs (actual pizza and receipt).


We're using the pizzeria as a black box. We don't need to know about or participate in what the actual work is:




Syntax and Semantics

We will look into this next class. Just so you have these terms in mind for next class:

Syntax: The set of rules that define well formed sentences in a given language. In other words: Is the spelling correct, given the language (Java)?.
Example: the sentence "He!lp the d,og ate the pizza" has incorrect syntax (even if, as a human, you might be able to pick up on the meaning.

Semantics: This looks at the meaning of the sentences rather than at how they are written. In other words, Does the code actually do what we want it to do?.
Example: the sentence "Help, the pizza ate the dog!" has correct syntax but it does not reflect what the interlocutor attempted to say:




Meeting your Classmates

We have placed you all in groups of 3 or 4. In order to give you an oportunity to get to know each other a bit more, and to also get some bonus points, we've deviced an activity.
The idea is this:

  1. You will go back to your groups and number each other 1, 2, 3, ... This will be your member number
  2. You will set up some time to meet every one of your groupmates for at least 20 minutes before next Thursday (each one of you needs to meet the others one-on-one). We recommed exchanging emails, phones, etc.
  3. During your scheduled meeting, you will interview eachother by asking questions from a special form we've prepared for you.
  4. Each of you will use the same form for each of your interviewees.
  5. You will use the form that has the same number as the member number chosen above.
  6. The forms are linked below (Please fill only one per interviewee and use your gwmail.gwu.edu email when filling the form):
    1. Classmate Interview Form 1
    2. Classmate Interview Form 2
    3. Classmate Interview Form 3
    4. Classmate Interview Form 4