Unit 3 - Algorithms and Programming

programming

The main purpose of this lesson is start our programming journey that focuses on problem-solving over learning syntax. Stripping down the available commands to only a few forces us to think about the most efficient way to solve the problem and come up with creative ways of doing it.A reason to learn this way is because at its core, a computer can really only do a few simple things: load a number from memory, store a number in memory, add two numbers together, etc. Everything the computer can do is the result of combining these simple instructions to do more and more sophisticated things. We will add more complexity as we go. When programming at any level of expertise you are always limited by the constraints of the programming language you choose to use. Whether the language gives you thousands of commands and libraries with which to control various things or only a few, you always have to use those as building blocks to get the computer to do what you want. It usually involves being creative and making interesting choices about how to go about doing something.

On to programming!

The challenge - and fun - of programming at its core, is understanding how to use and combine those machine instructions to make the computer do what you want, or to solve a problem.

We saw this in Unit 1 with the Internet, as we built up complex routing and naming protocols, all from solving the initial problem of how to coordinate communication between two people on a shared wire. We saw this in Unit 2 with complex data types, all built up from simple binary codes. We will do the same thing with programming! To learn about programming we are going to solve problems with only a few primitive commands. You will learn how you can build up very complex computer programs from only a few simple elements.

App Lab is the programming environment we will use in the Computer Science Principles course. App Lab uses both a block based and JavaScript language.You can access it from the Code.org link. We will check out the video together to see how to use App Lab.

You will complete activities 2 - 4.

What does efficiency mean? Why is it important?

    • We will compare your answers for the 3x3 grid.

Why constrain to 4 commands?

    • Learning to program isn’t just a matter of memorizing commands. The art of programming - the creative part - is always about understanding how to use the features of a programming language to solve a problem.
    • Whether you know 4 commands of a language or hundreds, you will always be constrained by the programming language. The reason you need to learn how to program is because there isn’t a command to do every little thing; you have to understand the set of things that a programming language can do, and then use your creativity and problem-solving skills to get the computer to do what you want.

Lesson 5: Creating Functions

Programming languages define the meaning of a set of general & useful commands. Nearly all programming languages provide a way to define and call new commands which programmers use for problems they are trying to solve.

Defining functions is an example of how computer scientists use abstraction to solve problems. A programmer will design a solution to a small, specific problem or task and then give it a name. When that problem comes up again, the programmer can use the new function by name, without having to solve the problem again.

In the previous lesson we created simple turtle drawings using only four commands. At some point you probably wished that more commands were available to you. What commands would have been helpful? Why?

We will watch the video about defining and calling functions together.

Notes on Program Style

The example programs have been written in the preferred style for this curriculum. These choices do not affect the functionality of a program but may affect how clearly a program can be read. As a consistent style is used programs will be easier to read and write.

    • Camelcase: Function names are written in camelcase. This means that multi-word function names are made a single word which begins in lowercase and uses uppercase letters to indicate the start of a new word. For example: thisFunctionNameIsCamelcase()
    • Function Definitions at Bottom: Function definitions appear at the bottom of the program. This is done so that the first line of the program is the first line of code actually run. The opposite format is also very common.
    • Functions Names Can’t Start with Numbers: In most programming languages, including JavaScript, function names are not allowed to begin with numbers or most symbols. Underscore, however, is allowed.
    • Use good/accurate names

You will complete challenges 2 - 8 from Stage 5.

Reflect

    • “List the benefits of being able to define and call functions in a program. Who specifically gets to enjoy those benefits?”
    • “How is the use of a function an example of abstraction?”

Vocabulary

    • Abstraction - Pulling out specific differences to make one solution work for multiple problems.
    • Function - A piece of code that you can easily call over and over again.

Lesson 6: Functions and Top-Down Design

Worksheet - Top-Down Design

Lesson 7: APIs and Using Functions with Parameters

We will look at the vocabulary words from this chapter on the code studio.

“Do you think programmers memorize all of the commands in a programming language? If not, how is anyone ever able to use an entire programming language?“

The Assignment

Complete CSP Unit 3 Lesson/Stage Puzzles 2 - 10 on Code Studio.

Lesson 8: Creating Functions with Parameters

The basic idea is that you often want to write a function that takes some input and performs some action based on that input. For example, the turtle function moveForward is much more useful when you can specify how much to move forward (e.g., moveForward(100)), rather than just a fixed amount every time.

It’s very common to encounter situations where as a programmer you realize that you basically need a duplicate of some code you’ve already got, but you just want to change some numbers. That’s a good time to write a function with a parameter; the parameter just acts as a placeholder for some value that you plug in at the time you call the function.

Just like it’s considered good practice to give descriptive names to your functions, the same is true for the names of the parameters themselves. For example: drawSquare(sideLength) is better than drawSquare(stuff).

The Assignment

Complete CSP Unit 3 Lesson/Stage 8 Puzzles 2 - 12 on Code Studio.

Lesson 9: Looping and Random Numbers

As we have developed as programmers, we have focused on the process of breaking down large tasks into smaller pieces and assigning each piece a function.When we break down a large task, often we will find that some portion of the task needs to be repeated many times. As programmers, we would simply call the same function many times. This might work if we need to call the same function five times, but if that function needs to be run 1,000,000 times, we’ll need a better solution.Today we’ll be exploring how a loop solves this problem by allowing us to repeat a set of commands many times.We’ll also practice looping through commands many times with random input, therefore giving us many instances of random output.

This will be both useful for testing our code and also for developing more variety in our drawings.

The Assignment

Complete CSP Unit 3 Lesson/Stage 9 Puzzles 2 - 13 on Code Studio.

Lesson 10: Practice PT - Design a Digital Scene

This will be the final project for this Code.org intro to programming unit. Use the links below to complete this project. Since we have a small class, this project will be completed individually. This project is intended to prepare students for the AP test.

Abstraction

Planning Guide - Design a Digital Scene - Send me the Product Description on Pg. 3

Practice PT Overview and Rubric - Design a Digital Scene

    • The project can be any drawing or scene (doesn't have to be under the sea), but it must be detailed
    • You project will be graded using the rubric from the link above and the Creative/Original Computer Rubric (creativity & degree of difficulty)
      • Product Description Planning Document - 5 pts
      • Program code to draw a digital scene - 30 pts
      • Individual Written Responses - 6 pts
      • Total 41 pts
    • Answer the Individual Written Responses (a. - c.) from the link above after you've completed your project and send them to me on Schoology
    • Put your final program in the CSP Unit 3 Lesson 10 Puzzle 3 and make sure to submit