AP CSP: Creating Functions & Top-Down Design

Slides:



Advertisements
Similar presentations
Chapter 2: Algorithm Discovery and Design
Advertisements

Chapter 2: Algorithm Discovery and Design
2 © 2003, Cisco Systems, Inc. All rights reserved. RST-2002 IP Addressing.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
Invitation to Computer Science, Java Version, Second Edition.
Algorithms and Flowcharts
Maths Parent Workshop October 2013 Stakesby Community Primary School.
JavaScript: API’s, Parameters and Creating Functions with Parameters
AP CSP: Pixelation – B&W/Color Images
Creativity of Algorithms & Simple JavaScript Commands
JavaScript/ App Lab Programming:
Vocabulary byte - The technical term for 8 bits of data.
Vocabulary Prototype: A preliminary sketch of an idea or model for something new. It’s the original drawing from which something real might be built or.
ICS 3UI - Introduction to Computer Science
Algorithms and Problem Solving
AP CSP: The Need for Programming Languages and Algorithms
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
HTTP AND ABSTRACTION ON THE INTERNET
AP Computer Science Principles
Unit 3: Lesson 1 - The Need for Programming Languages
Vocabulary byte - The technical term for 8 bits of data.
UNIT 2 – LESSON 3 Encoding B&W Images.
THE NEED FOR DNS DOMAIN NAME SYSTEM
AP CSP: Encode an Experience
FOP: Buttons and Events
ROUTERS AND REDUNDANCY
Routers and Redundancy
Functions and Top-Down Design
Lesson 5-2 AP Computer Science Principles
UNIT 2 – LESSON 6 ENCODE AN EXPERIENCE.
Unit 3 lesson 2&3 The Need For Algorithms- Creativity in Algorithms
Creativity in Algorithms
UNIT 3 – LESSON 5 Creating Functions.
UNIT 1 – LESSON 6 SENDING NUMBERS.
The Need for Algorithms 2 days
Looping and Random Numbers
AP CSP: Bytes, File Sizes, and Text Compression
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer.
Sending Bits on the Internet
Practice PT - Design a Digital Scene 3 days
Cognitive Processes: Thinking and Problem Solving
Yenka Portfolio Level for this topic: Student Name : My Levels
DAY 2: Create PT: Make a Plan
LESSON 12 - Loops and Simulations
Introduction to Computer Programming
Lesson 16: Functions with Return Values
Lesson 15: Processing Arrays
UNIT 3 CHAPTER 1 LESSON 4 Using Simple Commands.
Looping and Random Numbers
Programming Basics - RobotC
Unit 3: Lesson 6 & 7- Functions and Top-Down Design / APIs and Function Parameters Day 27.
Computational Thinking for KS3
Coding Concepts (Basics)
Fundamentals of Data Representation
Four Operations.
Topic 1: Problem Solving
Algorithms and Problem Solving
Rapid Research - Format Showdown
Functions and Top-Down Design
Unit 3 lesson 2-5 The Need For Algorithms- Creativity in Algorithms – Simple Commands - Functions Day 18.
COMPUTATIONAL THINKING COMPUTATIONAL THINKING IN PROGRAMMING
Unit 3: Lesson 1 - The Need for Programming Languages
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Computational Thinking
Quiz: Computational Thinking
U3L2 The Need For Algorithms
U3L4 Using Simple Commands
Understanding Computational Thinking
Presentation transcript:

AP CSP: Creating Functions & Top-Down Design

Do Now: 1.

Do Now: 2.

Review: Last class we learned to create algorithms to find the smallest card in a set using a limited set of commands. Algorithms creation is an art the requires creativity and a good understanding of the commands available to a programmer. We also started programming in App Lab last class. You had to complete some tasks using only four JavaScript commands. Sequencing these commands together in a particular order allowed us to complete our objective. Today we are going to learn how to make more commands from the basic four commands given to us.

Review Discussion: 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. Describe a command you wanted to be able to use and explain why you wanted to use it. Think of commands you wish you had to complete the last task! Programming languages will always have some commands that are already defined, but there will be many instances when the exact command we want isn’t available. Today we’re going to start exploring a powerful feature of most programming languages that will allow us to overcome this issue and create commands of our own.

Creating Function is App Lab: We are going to transition back to App Lab and continue practicing your programming skills. You will still be limited to the four commands as before but now you are introduced to the concept of functions. A Function is simply a sequence of commands that will be performed when that function called upon. For the most part we will be dealing with programs that follow a certain style when being created Camelcase : 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 Definition at the 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 (Opposite format also common) Function 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.

Creating Functions in App Lab: Go to Unit 3 Stage 5 and work on parts 2 – 8. You will be defining new functions from the four commands given to us which will allows us to use even more commands! Follow the prompts in the and complete all the tasks in Stage 5.

Function Benefits: 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?

Function Benefits Answered: List the benefits of being able to define and call functions in a program. Who specifically gets to enjoy those benefits? programs are easier to read and write functions remove the need to repeat large chunks of code functions break the program into logical chunks The person programming and any other human reading the program enjoys these benefits. Important to note: functions do not make the program easier (or harder) for the computer to run or understand – it must still run all of the same commands as before. How is the use of a function an example of abstraction? Abstraction is the practice of temporarily forgetting details unnecessary to addressing the problem at hand. Defining and calling functions is another example of how computer scientists use abstraction to solve problems. Once you have written a function that you know works as intended, you can call the function as often as you wish, without worrying about the details or problems you had to solve to get it working.

Efficiency of Functions: Imagine that you have two programs that drew the diamond-shaped figure. One program uses functions as we did in the previous lesson. The other doesn’t use functions; it’s just a long sequence of the turtle’s primitive commands. Which program is more efficient? Make an argument for why one is more efficient than the other.

Efficiency and Functions: “Efficient” can mean several things: It could mean the total number of primitive operations performed by the turtle. It could mean number of lines of code. It could hinge on the ability to reuse code within your own code. It could be about the speed and clarity with which you can write the program. Efficiency is an interesting thing to think about, but functions also introduce the ability to leverage the power of abstraction: when we write a function, it solves a small piece of a bigger problem. Having the small problem solved allows us to ignore its details and focus on bigger problems or tasks.

Top-Down Design: With the creation of functions we are able to abstract away certain details. To create the function right() we needed to make a left 3 times. After we create that function we no longer need know how the function right() works, you just know it works. Abstraction caused by functions allows us to focus on task at hand (creating a diamond) and not worry about small problems anymore (turning right). Creating Functions for small problems and then reusing those functions allow us to focus on the real problem without having to worry about resolving our small problem over and over again. Sometimes we must look at the larger goal at hand and break that down into smaller sub-goals to complete our task. This methodology is called Top-Down design. You are going to practice Top-Down Design Now

Create a Snowflake using Top-Down Design In our last lesson we were able to create a diamond by solving smaller subtasks until we created one function able to create a diamond just by calling it. We could have actually looked at the main problem itself and break down that goal into smaller and smaller goals that I know how to program. You are going down to use Top-Down Design try and create a snowflake pattern. Break down the process of creating a snowflake into smaller subtasks. Look for repeating patterns in your snowflake and work down from there until you reach a point where you know how to code what you need. Work with a partner to figure out an approach to solve this problem using Top-Down design. Try and come up with  descriptive function names that give insight to your thinking.

Creating a Snowflake in Code Studio: When you are finished out how to breaking down your snowflake problem, transition to Unit 3 Stage 5 and create the code that will produce a snowflake. Remember to design functions that reflect your Top-Down design! Create functions for each of your sub-goals. Your final code should only run one command and that is drawSnowflake() You will then try out Top-Down Design with creating 3x3 grid Try to break down in to smaller goals with their own functions Your code should only run one command called drawGrid(); Break down the problem how you see fit. Try to look for patterns and then try to break down those patterns into something you know you can code.

Top-Down Design, Functions, and Abstraction When we layer functions - with functions that call other functions - we are creating layers of abstraction. In programming, writing functions helps us create layers of abstraction that allow us to design and create increasingly complex systems. We’ve seen layers of abstraction before in the design of Internet protocols, or in the binary encoding of information. Solving a fundamental piece of a problem that can be reliably reused in a different context frees us to think about more complex problems because we can trust the piece that has been solved and don’t have to worry about its details. Solving small problems - like how to send a single bit from one place to another - allows us to think about bigger problems, like sending numbers, or text, or images, to multiple people, over networks, in packets…etc., etc., etc.

Definitions: 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.