Computer Science Principles Notes
Computer Science Principles - Big Idea 1
Collaboration
Pair Programming:
Two programmers work together.
The driver writes code.
The observer (pointer/navigator) reviews each line.
Think-Pair-Share:
Students think alone, then pair to share ideas, and then share with the class.
Leave comments in code:
Communicate to your partner(s).
Communicate to yourself.
Acknowledge code segments and media used from other sources.
Differentiate contributions of partners.
Clarify code functionality.
*If comments are not supported in your programming language, add them in an editor after.Online tools for collaboration:
repl.it - multiplayer
GitHub - collaboration and repository
Shared document or folder
Get feedback from friends and family.
Check with your teacher for preferred coding platform.
Program Function and Purpose
Computing Innovations:
Applications (Games, Social Media, Business, Productivity)
Physical Devices (Computers, Smartphones/tablets, Smart "Things", Wearables, smart technology like insoles, a watch)
Systems (E-commerce, Cloud services, E-mail)
*Purpose of Computing Innovations:Social Media Applications: Allows users to connect from a distance and archive their activities.
E-commerce: Allows users to save time and money by being able to shop from home.
Digital Assistant Device: Allows users to control their devices hands-free, making them safer while driving or more convenient when trying to multitask.
Guiding Questions about Computing Innovations:
Why does the computing innovation exist?
What problem(s) does the computing innovation solve?
What does the computing innovation allow us to do that we could not do before?
Identifying Inputs to Programs:
Computer Programs accept input in a variety of different forms:
tactile (touch)
audio
visual
text (including numerical values)
How do programs receive input?
Most programs are written in an event driven environment.
Events are triggered by some action, which usually sends input to the program.
Types of events a user can trigger:
mouse clicks
screen taps/swipes (force touch)
physical button clicks
keyboard entries
audio trigger (key word or phrase)
How does a program know what to do upon an event?
An action triggers an event.
The program "jumps" to the code segment according to the event.
The code segment is executed.
Output is triggered by the code segment (or additional events are triggered).
The program code is not necessarily executed "in order"; code segments are executed as they are called, according to the events triggered.
What does input accomplish in a program?
Input usually affects the output.
What are outputs produced by a device?
visual
audio
tactile (touch/feel) vibration
text
What is a program?
A program is a collection of statements.
A statement is a single command.
A group of statements is called a code segment.
Code segments are executed according to the rules of the programming language.
A program is often referred to as software.
Example program to find the minimum value in a list:
minaList[1]
FOR EACH item IN aList
{
IF (item < min)
{
min + item
}
This code segment would need to work on multiple lists, like lists that include:
number out of order
negative numbers
large numbers
decimals
How to describe a code segment:Simply what it does so that it could be used in a larger program
How it does what it does explain how code segment functions so that someone could expand on it
Program Design and Development
How is a program developed?
It all starts with an idea developed with a specific purpose. Follow specific steps and stick to their plan.
Developers start investigating the problem/purpose and reflect.
Developers must:
determine the requirements of the program, understand the constraints, understand user concerns and interests.
How do developers investigate?
surveys
user testing
interviews
direct observations
Sometimes the development is more exploratory
After initial investigation and reflection, developers design the program by:
brainstorming
storyboarding the program
planning user experience
laying out the user interface
organizing into modules
develop a testing strategy
Developers decide on the program requirements that describe how a program should behave and include a list of user interactions.
The program specifications outline all of the requirements.
Developers create a prototype of the program (or components). An incremental process is frequently used so developers can refine small parts (modules) of the program.
Developers test the program every step of the way at the micro level (individual components) and macro level (whole program).
Developers refine and revise through testing, feedback, and reflection.
Program development is rarely a solo endeavor. Programs are usually developed by teams of people where individuals/teams work on different functional components.
Each member of the project deserves to receive credit for their work, and their names must be written in the documentation of the program indicating their contributions to the project.
While documentation is an important place to give credit, many projects use comments within the programming language to give credit. When developers find a bug (or an error in a program), they need to be able to determine who can/should fix the problem.
Many times developers use code segments, procedures, algorithms, and more that are written by others. These other individuals are not necessarily a part of the the project, but they still deserve to be credited. Any code segments, procedures, algorithms are considered intellectual property of the author. The program documentation should include the author's name and the source of any code segments being used. This portion of the documentation may resemble a bibliography or a works cited page in a research paper.
Programmers create something called program documentation in order to:
describe the overall program, list program specifications, functions/procedures/methods within the code, specific code segments, list of events and corresponding outputs, the development of the program, how other programs may interact with the program, list of contributors/authors of the program.
Documentation happens throughout the development of the program: At the beginning list specifications, During to keep track of process, and After to explain the overall process.
Documentation throughout can improve the efficiency of the overall programming process, programmers' ability to test and refine the program, and programmers' response to bugs.
Most programming languages offer a commenting feature, although some do not. Commenting Examples:
Python:
# Comments appear on lines that follow the pound symbol (#)Java:
// Comments Single line comments appear after double forward slashes (//)/* Comments */ Multiple line comments appear between forward slash - asterisk combinations** Documentation */ Multiple line Documentation comments appear between forward slash - double asterisk combinationsJavascript, C/C++, Swift - similar to Java
XML/HTML:
<!--Comments --> Comments can be single or multi line and appear after less than, exclamation point dash-dash, and terminate with dash-dash, greater thanApplescript/Pascal:
(* Comments *) Comments can be single or multi line and appear after open parenthesis asterisk and terminate asterisk close parenthesis
Identifying and Correcting Errors
Error Types:
Logic Error: caused by a mistake in the algorithm, leading to unexpected behavior.
Syntax Error: a typo or code that doesn't follow the rules of the language.
Run-time Error: occurs when the program fails during execution (a "bug").
Overflow Error: when a calculation is outside the defined range of values.
Example: Logic Error
grade INPUT("Enter a grade")
IF (grade >89) {
DISPLAY ("A") }
IF (grade > 79 ) {
DISPLAY ("B") }
IF (grade > 69 ) {
DISPLAY ("C") }
IF (grade > 59 ) {
DISPLAY ("D") }
ELSE {
DISPLAY ("F")}
An "A" grade such as 90 would display "A" as intended, but would also display "B," "C," and "D" as well.
Example: Syntax Error
grade INPUT("Enter a grade")
IF (grade > 89){
DISPLAY ("A") }
IF (grade > 79 ) {
DISPLAY ("B")}
IF (grade > 69 ){
DISPLAY ("C")}
IF (grade > 59 ) {
DISPLAY ("D") }
ELSE {
DISPLAY ("F")}
Example: Run-time Error
grade INPUT("Enter a grade")
IF (grade > 89 ) {
DISPLAY ("A") }
IF (grade > 79 ) {
DISPLAY ("B") }
IF (grade > 69 ) {
DISPLAY ("C") }
IF (grade > 59 ){
DISPLAY ("D") }
ELSE {
DISPLAY ("F")}
If the user were to enter a non-numerical character, most programming languages would result in a run-time error when trying to compare a word to the number 89.
Example: Overflow Error (Imagine you have a calculator that has 4 display digits, what is the largest value this calculator could display?)
9,999
What would be the result if you tried to calculate 100*100?
10,000 is the result.
Essential Knowledge:CRD-2.I For errors in an algorithm or program:
b. Correct the error.
CRD-2.I.5 The following are effective ways to find and correct errors:
test cases
hand tracing
visualizations
debuggers
adding extra output statement(s)
The easiest error to correct is usually the syntax error.
The more difficult errors to find and correct are logic errors.
Using test cases is the first strategy programmers use to find logic errors.
Hand tracing can be most useful with iteration (loops).
Another strategy is adding extra output statements.
Some IDEs allow programmers to use visualizations and/or debuggers.
Visualizations show graphs, images, color, etc. (things that can be visualized) that can help determine if a program is working correctly.
Debuggers use software designed to run a program, allowing it to be paused and tested in the midst of running to determine if it is working properly.
Programmers need to define inputs that will determine whether or not the program specifications are met.
Programmers start testing a program at the onset of development.