Monday, October 6, 2014

Lists

From csp4hs - summer 2014

Lists

  1. Watch the video below entitled "Lists." The link to the slides is just above the video.
  2. As noted in the last lesson, variables are used to store the values of computations that are made in a program. Our past look at variables considered only a single variable that contained a single value. There are many occasions when a programmer may want to group a set of values into a single variable name (e.g., a list of class grades, a sequence of notes for a song, the list of high scores for a game), rather than storing each value separately (e.g., grade1, grade2, ..., grade20). If we had to store each value in a separate variable, our programs would become complex (imagine over 1000 different variables to store the notes of a song). A data structure allows us to group information together into a single variable that can be created and manipulated. Lists are a specific type of data structure in Snap! that allow a programmer to store a sequence of values that can be individually indexed through a common variable name. In Snap!, each element in a list is indexed, starting at index location 1. For example, on slide 2 of the "Lists" presentation below, index location 1 is an "Apple" and index location 5 is "Grape." The index locations of -1 and 6 are undefined in the example on slide 2.
  3. Go to Snap! and look at the Variables palette, making note of the various blocks that can process lists (see slide 3 of the presentation below). These blocks can be used to create, delete, add, insert at specific location, determine the length of a lists, and access values from a list. Using a loop, it is possible to iterate over all of the elements of a list and perform some special computation.
  4. Watch the video "Printing the contents of a list" located below. Notice that there are three key parts to this program, which you will often find in most code that processes a list: 1) Creation and initialization of a loop counter (often called "index" or "counter"), 2) a repeat loop that iterates over the length of a list, 3) some access to the list through blocks like "item of", and 4) within the loop, an update to the loop counter to move to the next element in the list (often done with the "change" block in Snap!). Study the program that says "C S P 4 H S" and make sure that you understand the list blocks that are used and how they work in conjunction with the repeat loop.
  5. Watch the video "Summing a list of numbers" located below. This program creates a new Reporter block (called sum) that receives a list of integers as input and returns the sum of all the numbers in the list. The benefit of using a list is that sum can be called with an arbitrary number of integers - it can compute the sum of 10 numbers as easily as it can computer the sum of 100 numbers. There is nothing fixed in the block definition that ties it to a specific size of the list (the use of the length block enables this benefit). In the code of the block, in addition to the loop index counter, there is also a variable called tempSum that is used to keep track of the running sum of the list numbers. Make sure you understand how this block works by tracing out a sample list input and how the values of index and tempSum change during the iteration over the list. After the sum of the list is computed in tempSum, notice that the value is reported back to the caller. A sample program that uses the sum block is also shown in this video, which simply sums the values of a small set of integers and says the value to the screen.

Customized Blocks and Lists

From csp4hs - summer 2014 session

Lesson Objectives

Thus far, we have used Snap! blocks that were already existing and provided to us as part of the core Snap! language. There are many situations that may arise when a programmer needs to define their own blocks to support customized features that their program needs. The ability to customize blocks is very important to support the concept of software reuse. We do not want to reinvent the wheel each time we need a special feature in our program - creating a customized block allows us to use the block in many different contexts, saving us time and also helping to make our programs more correct (i.e., we can put extra effort in making sure a block is correct, and then reuse the block in many other contexts). In this lesson, we will learn how to make our own blocks in Snap!
Another topic covered in this lesson is an introduction to a basic data structure known as a list. In Snap! and other programming languages, a list can be used to store a collection of common values in a single variable name. For example, if a program needed to store the grades for a class of 20 students, rather then have 20 separate variables for each student, a list allows us to create a single variable name that contains all of the grades together. We also learn in this lesson how to create and manipulate lists in Snap!, and consider several contexts where lists may be used.
All of the example programs shown in the primary presentations are also coded in other videos that you can watch below. Make sure that you do not just watch the videos - try to program the examples yourself in Snap! by following along with the video screen shot.

Lesson Tasks

Please consider the following sequence of topics for this lesson on blocks and lists:
Building Your Own Blocks
  1. Watch the video below entitled "Build Your Own Blocks." The link to the slides is just above the video.
  2. Consider our original starting point in earlier lessons of this unit that focused on simply drawing a square. The code to draw a square served the purpose of illustrating basic Snap! commands (e.g., move), but this code was not very useful because it assumed a specific type of shape with a fixed length of sides. This lesson progresses through a series of generalizations where the core square code is made more reusable by adding parameters to the block that aid in specialization. For example, the fixed length of the square is removed such that the caller of the block can specify a specific length. By abstracting out the length of the side of the square, we can now reuse the block to draw squares of any size. However, drawing a square in itself is not so interesting. The next progression in this lesson is to abstract the number of sides, which will create a more general drawShape block. The caller of drawShape can specify not only the length of sides, but also the number of sides. This allows a very general block that can draw everything from a triangle to a circle.
  3. Watch the video entitled "From square to drawShape" below, which shows how blocks are created in Snap! When teaching this lesson, it is very important to draw your student's attention to the importance of procedural abstraction and how it can allow us to create more general blocks that can be reused in many contexts (e.g., drawShape has many more options for reuse than a square block of a fixed size - there are just not many places where a fixed square would need to be reused compared to a more general drawShape). The concept of procedural abstraction allows programmers to create libraries of software that can be reused in future contexts that may not have even been anticipated when the block was designed initially. When introducing this to your students, guide them through the same progression of a very fixed program (the first square) through the drawShape block, pointing out along the way how each new evolution of the block can support a larger number of contexts. Help them to understand how a block can be generalized by abstracting the essential parts of a shape (i.e., its length and number of sides).
  4. Make sure that you understand the power of procedural abstraction and how this can be implemented in Snap! with customized blocks. You should also understand the different types of blocks: Command blocks just perform an action and do not return a result (like drawShape); Reporter blocks return a value (sort of like a mathematical function); and Predicate blocks are like Reporters, except the return type is limited to a Boolean value (i.e., they only return true or false). Blocks can also receive parameters, which provide input to a block during its computation. Parameters can be of different types, as shown in the slides and videos below. Parameters can be placed in post-fix notation (e.g., the length and number of sides appearing after drawShape) or in-fix notation (e.g., the appearance of the "<=" operator between the parameters, as shown in a video below). Watch the video entitled "Max and Less-Equal," which shows how a Reporter (that is post-fix) and Predicate (that is in-fix) are created, respectively.


Monday, September 22, 2014

9/24/14 - Snap! Variables

  When writing a program, we often need to store the value of some important concept used in our program, such as the value resulting from an intermediate computation. A variable is a concept in programming languages that allows us to associate a value with a symbolic name that can be used at different places in our program. There are specific rules for naming a variable, as mentioned on slide 2. It is important to assign the name of a variable as something that the variable represents. We often name our variables starting with a lower case letter. Sometimes, the best name may be more than one word, as in currentTaxYear or birthDate. In such cases, it is a convention to use what is called Camel Case, where the additional word is capitalized. These are just suggested conventions and not really the rules of Snap!




Try solving the exercise on slide 4 ("Variables" video) on your own, without looking at the answer on the later slides. The presentation offers two solutions to the "swap" concept. Do you understand these?

The last slide of the "Variables" video introduces the concept of a data type. It is helpful at times to know what values a particular variable can represent, such as numbers, strings, or other types of values. We will talk more about data types in a future lesson in this unit as it relates to creating our own blocks and being able to pass in values to those blocks.

The video below that will show you how to create variables in Snap!, including a solution to the swap exercise presented on slide 4.

9/22/15 - Snap! Core Programming Structures

Lesson Objectives
  This lesson introduces the three core structures that can be found in programming languages: sequence, decision/conditional (if), and iteration (loops) constructs. An important concept in conditional and iteration statements is that of a Boolean expression. The lesson will introduce comparison (relational) and Boolean (logical) operators that can be composed to express statements that are evaluated to true or false. The ability to express Boolean expressions is core to the test conditions of decision and iteration statements. Programs also need to store values as they perform a computation. The ability to declare variables, and the notion of data types, are also discussed in this lesson. You are encouraged to type in all of the examples in the slides/presentations/videos yourself in Snap! and try to get them to work. Overall, this lesson will take much more time to complete than past lessons if you decide to follow along and try out all of the programs on your own. Those who have taught computer science before will likely find these lessons as fundamental, but the context of presentation within Snap! may be offer new ideas. 





Class Exercise - Decision Structure - grade converter from video

     Compose the solution using if/then and boolean expressions


Tuesday, September 16, 2014

Lesson Plans Comp 2 and 3 9/16/14

Today you will work on the 1st 2 sections of the Computer Science programming piece.  


1.  Understand what software engineering is and why it is important to thoughtfully plan out you program before coding it.

2.  Get acquainted with  Snap! and code a small program or two.

Introduction to Networking


Download the newest version of packet tracer and get it running on your Mac.  I have found that wine wrap has been the most stable.  Work with each other to figure it out.

Recap last weeks work -

Terms:
End Device
Intermediary Device
Networking Media
Encoding
Clients and Servers
Peer to Peer
Physical Topology
Logical Topology

Chapter 1 Objectives:






















Continue to read Chapter 1  starting with   1.2.2.1 and take notes

Lab 1.2.3.3  Converged Networks

Pay attention to Internet, Intranet and Extranet

Cont. to read 1.2.4 (Connecting to the Internet) and do the packet tracer exercise

1.3 (Converged Networks) and the Lab

1.4 The Changing Network Environment

It is OK if you decide that you would like to spend more time on the programming piece today.


You may spend some time creating a proposal for the middle school Hour of Code.

Section 2 - Snap! Overview

Snap! Overview

Lesson Objectives


  Before learning about some of the general constructs used in programming that are covered in the rest of Unit 3, this lesson provides a general overview of the Snap! environment. You will create two short programs, and learn how to store your own programs in several different ways. The lesson is composed of a short video that you are encouraged to follow as you build your own similar programs and become comfortable with the Snap! browser-based environment. There are many things that will not be covered in this lesson. In fact, the entire unit will not cover every concept in Snap!. Our goal is to provide you with a set of experiences that allow you to understand some of the core ideas in programming, such that you have the confidence to then explore more on your own.

  When learning a new foreign language, I have observed that it is easier to read in that language than to write in the same language. It seems that understanding something already provided is easier than synthesizing something new on your own. It takes practice to be able to write new expressions in a foreign language. I have found the same to be true in learning how to program. It is often the case that students can understand a program that is given to them much better than they can actually produce that same program on their own. The potential trap is to think that some proficiency in reading and understanding a program is the same as creating a new program on your own. In the same way that it takes practice to be able to write and speak in a new foreign language, you must practice and go through some hands-on activities in order to grasp the skill of programming on your own. It will be very tempting to look at a program provided to you, understand it, and think that you could produce that yourself. We encourage you instead to get involved with the coding activities that will be suggested in this unit that are designed to give you more practice in developing your programming skills, which will assist you in teaching your own future students about programming.

Lesson Tasks


Please work on the following during your exploration of this lesson:

Visit the Snap! website and look around at some of the information provided by the Snap! team. A gentle warning - there is a Snap! reference manual available. However, we suggest that you wait until the end of this unit before you try to read the manual. The Snap! manual has several advanced concepts that are discussed very early in the manual. The manual may be more accessible to those who already teach computer science, but the reference manual may be challenging to understand at first for a new CS Principles teacher who has never programmed before.

Watch the video linked below. There are no slides for this lesson. A suggestion is to first watch the video, and then come back to the subsequent steps below to review the video and try some hands-on activities.

Go to the URL that actually runs Snap! in the browser: http://snap.berkeley.edu/run. Be adventurous and explore around - you won't break anything important at this stage! Look at the different categories in the palette area, and how new blocks emerge when you click on each category. Can you guess what some of the blocks might do? Can you summarize in your own words what some of the categories represent as a theme? For example, what is the core theme of the blocks in the Motion category?

Try duplicating the "Hello World" program that is introduced at the first minute mark of the video. Pause the video in one tab of your browser, and try to duplicate what is being done in your own Snap! environment. Try to run your program by clicking on the green flag.

Explore the various ways that you can save this program. First, export the program as an XML on your desktop. Can you see where the file was then added to the Desktop? Try to then create a New project in Snap! that is empty, and then see what happens if you then import your saved program back into Snap! This file is not intended to be read by humans, but just an internal representation of your program that Snap! can read and write. The XML format (Extensible Markup Language) is a very important standard for sharing information, and is used by Snap! as a representation for storing your program.

Click on the cloud button at the top of the Snap! screen. You may want to try to create your own account by signing up (there is a sign-up button that you can click, which will generate an email to you with account information). This is not necessary now, but will be useful later.
Create a new project in Snap! (the "New" option in the file icon at the top of the screen). Then, try to create the square drawing program on your own that is introduced in the second half of the video. In particular, experiment with the "duplicate" block option that is shown in the video as a way to save time in dragging and dropping blocks (time 5:20 in the video). Were you able to get the ability to ask the user for the size of each side? Do you see how more general that makes your program, rather than drawing a square of the same size each time? We will come back to this idea in a future lesson in this unit.

Congratulations - some of you who may have never programmed before just created your first two (albeit very simple!) programs!

Please note: If the video below appears blurry, please allow time for the full resolution to download as a stream. You may also want to try viewing all of the Snap! screencasts that are in this unit in Full Screen mode, or in a separate browser tab.

Watch the video below!!!


https://www.youtube.com/watch?v=jFs3pn7zzoc


Section 1 - programming design

CS Programming:


Interesting video on what a software engineer does and the software development process.

Lesson Objectives

There is often the tendency to want to rush into software development by going straight to programming without giving much thought to the requirements and design of their program. Although this may be tempting for smaller programs, this is not the best practice for creating quality software. In this lesson, we first consider an overview of several basic concepts (e.g., hardware, software, memory and storage, and programming languages) and then cover the various phases traditionally performed in software development. Particular emphasis is made on the need for planning, with several examples of disasters (some related to software, and some from other domains) resulting from poor planning before implementation. The rest of this unit is focused on programming, but it is important for you to understand that it is not wise to jump into coding without some forethought.


Lesson Tasks

1.  Watch this video.  It is geared towards the  instructor, but Prof. Gray talks about what programs and software languages are, how your computers processes them and the importance of planning.

https://www.youtube.com/watch?v=KEyMrFA-JnU#t=823

2. Software development has often been described as a mixture of art and engineering. This lesson focuses on the engineering of software and the need to plan and design a program before implementing it in code. The compelling reason that is given in this lesson is the potential hazards resulting from software failure, such as the Ariane 5 disaster cited in the slides. The somewhat surprising (or maybe not!) reality is that software fails often, and in various degrees of calamity. To demonstrate the ever present failures of software, a VERY STRONG suggestion is to look over the Risks to the Public that are compiled by Peter Neumann. Similar to the ACM TechNews, this compiled weekly list of software errors could be a topic for current events discussion. For example, this lesson is assigned during the voting season for Primary elections - there is a topic from June 6th related to the problems associated with fraud in online voting.

Take a look at the current entries.  Which article caught you attention?



3. Review the 5 phases of software design and compare to the version presented in the video.

http://en.wikibooks.org/wiki/Introduction_to_Software_Engineering/Process/Life_Cycle




Have you used a similar process when creating other projects?  

I do something very similar when designing a woodworking project.\:
  What are my bench requirements (size, weight load, style)
   Design the bench
   Build it
   Does it  do what I wanted it to
   Tweak 
    Does it meet my requirements?

4. Huge failures is design:

  Tacoma Bridge    and video    You may have seen this physics

  Ariane 5     and video   

5.  Related to the above idea of the types of errors associated with a program, make sure that you understand the difference between the syntax of a language and its semantics. Regarding syntax,  a compiler parses a program to make sure that the program conforms to the correct rules of a programming language. For the purpose of this course, the parsing of a program can be likened to the activity of diagramming sentences in an English class - the compiler must be able to determine that the program conforms to the grammar of the language. The semantics of the language refers to the specific meaning ascribed to the language operators and constructs. A program may be syntactically correct, but semantically wrong, which can lead to a logic error.


What type of error was the Ariane 5?


6. Of the development steps presented in the video, which step do you think takes the longest?