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:




Abstraction and communicating with computers

We take many computational tasks for granted. For example, all of us have probably sorted a set of items on a computer before; perhaps you sorted your AirBnB results by price, perhaps you sorted a list of restaurants on Yelp by proximity to your current location, or Amazon sorted your search results for a book by how close the title was to your query. Somewhere, someone has written code that translates the human problem of "I wanted to sort this unsorted list."

As humans, we often abstract away the low-level details that we don't need to solve or understand the problem. For example, we can all probably agree that we conceptually know what it means to sort a list of names alphabetically. But, could you explain how to do that to, let's say, an alien, who's not familiar with the concept of sorting and a sorted list?

Activity 1 :[10 minutes] Imagine we wanted to sort a pack of exams by students' last names -- this makes it a lot easier to enter grades into Blackboard for the TA, since the student roster there appears alphabetically. In groups of 1-3 students, work together to provide a set of human instructions (so not code) that explains how to take a stack of unsorted paper exams (they each have one student name written on them) and convert it into a sorted stack of exams for the TA to use. Write up your answers in a format "Step 1: ..., Step 2: ..., etc."
When you are finished, each person submit a copy of these answers (you can take a photo from your phone), under the "Day 1 sorting pseudocode" link on Blackboard for participation points.

Abstraction in this class

In this class, we will use abstraction to analyze 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. Understand the problem: first make sure you know what you need to design, by writing some test inputs and their matching outputs.
  2. High-Level Sketch: write (or draw) the solution using English (or diagrams)
  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 each module of the solution using appropriate programming language
  5. Correct: fix any spelling (compilation) errors in your code
  6. Test: Test 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.




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 person attempted to say:




First Question: Why not just use English?

Solution: Use an unambiguous form of the language, even if it is a little less expressive.


In this case, we will be using the high-level programming language called Java.




What is a High-Level Language?

How does a computer execute code? What are the main components of a computer? Let's discuss!

A Low-Level language is composed of the set of instructions that can be directly executed by the computer's central processing unit (CPU). It is "machine-speak" and it is very distant from English. To the human, it looks like 0s and 1s. This is because on a computer, 0s and 1s can be represented through electrical currents (either on or off), and gates can be used to control how the current flows. No human wants to write in this language.

Solution: represent this low-level language in something easier for humans to deal with. Why? Because someone needs to eventually be able to easily understand the code to debug it. Then, have software translate the human-readable language into a low-level language that the machine can process.

These programming languages that are closer to English and that allow you to use abstract terms and instructions are called High-Level Languages. Some of these are (C, C++, Java, Python, etc).

The conversion of a program (written in a High-Level language) into an executable (written in machine code) is called Compilation. Note: we'll assume this model for this course, but there are actually some details we're leaving out right now for the sake of clarity for those of us new to programming.




Next class:

We'll discuss the basic parts of a program using the Hello World example.

Assignments for next lecture:

Bring your laptop to your lab section to work on Lab 1. Make sure you submit your Lab 1 screenshot to BlackBoard.
On the Schedule, read the "Lecture Notes 02" and be prepared to take a short quiz on Blackboard at the start of the next class (Tuesday) on that material.