How to Read Code Benfeard Williams 6/11/2015 Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors.

Slides:



Advertisements
Similar presentations
CS 100: Roadmap to Computing Fall 2014 Lecture 0.
Advertisements

Slides modified by Erin Chambers Problem Solving and Algorithm Design.
Chapter 1 - An Introduction to Computers and Problem Solving
Programming in Visual Basic
Introduction to C Programming
How does Google search for everything? Searching For and Organizing Data Prof. Susan Rodger Computer Science Dept Duke University Oct. 31, 2014.
Chapter 2: Algorithm Discovery and Design
Program Design and Development
Chapter 2 The Algorithmic Foundations of Computer Science
Computer Science 1620 Programming & Problem Solving.
CS 201 Functions Debzani Deb.
Chapter 2: Algorithm Discovery and Design
Chapter 2: Algorithm Discovery and Design
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
INTERNET APPLICATION DEVELOPMENT For More visit:
CH Programming An introduction to programming concepts.
CIS Computer Programming Logic
1. Reference  2  Algorithm :- Outline the essence of a computational procedure, step by step instructions.  Program :- an.
EGR 2261 Unit 4 Control Structures I: Selection  Read Malik, Chapter 4.  Homework #4 and Lab #4 due next week.  Quiz next week.
Introduction to Python
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science, C++ Version, Third Edition.
CHAPTER 1: INTRODUCTION TO COMPUTER SCIENCE Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Introduction. 2COMPSCI Computer Science Fundamentals.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Marie desJardins University of Maryland, Baltimore County.
Data Structures Chapter 1- Introduction Mohamed Mustaq.A.
CSE 131 Computer Science 1 Module 1: (basics of Java)
Introduction to Computer Programming Using C Session 23 - Review.
JAVA 0. HAFTA Algorithms FOURTH EDITION Robert Sedgewick and Kevin Wayne Princeton University.
What does a computer program look like: a general overview.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Introduction to Python and programming Ruth Anderson UW CSE 140 Winter
Useful IDLE Alt-ENTER Commenting-out. Writing a Program CMSC 120: Visualizing Information 2/14/08.
Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Copyright © 2002 W. A. Tucker1 Chapter 9 Lecture Notes Bill Tucker Austin Community College COSC 1315.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
The Hashemite University Computer Engineering Department
Invitation to Computer Science 5 th Edition Chapter 2 The Algorithmic Foundations of Computer Science.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
7 - Programming 7J, K, L, M, N, O – Handling Data.
Basic concepts of C++ Presented by Prof. Satyajit De
CompSci 101 Introduction to Computer Science
GC211Data Structure Lecture2 Sara Alhajjam.
CompSci 101 Introduction to Computer Science
Arrays, For loop While loop Do while loop
CompSci 101 Introduction to Computer Science
Prof. Susan Rodger Computer Science Dept Duke University Oct. 31, 2014
CS 100: Roadmap to Computing
Algorithm Discovery and Design
Computer Science Core Concepts
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
The structure of programming
Benfeard Williams June 16th, 2016
General Computer Science for Engineers CISC 106 Lecture 03
Introduction to C Programming
Presentation transcript:

How to Read Code Benfeard Williams 6/11/2015 Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there is any confusion, please the lecture presenter.

Concepts You Will Learn Programming  Practice, skill, art, science, engineering, creativity Problem-solving  How to solve problems using programming and a computer Impact of computer science  Scale and automation Foundation for future work

Interpreted vs Compiled Code Interpreted  Read and executed by another program on the target machine  Easy to implement Compiled  Expressed specifically for the target machine  Faster performance

Computers Do What You Tell Them They are fast but not smart You need to plan exactly what the computer needs to do in order to solve a problem

Declarative Knowledge Statements of fact “A good health care plan improves the quality of medical care while saving money” “y is the square root of x if and only if y*y = x”

Imperative Knowledge How to accomplish something (recipe) 1)Start with a guess, g 2)If g*g is close enough to x, then g is a good approximation of the square root of x 3)Otherwise, create a new guess by averaging g and x/g. 4)Using this new guess, go back to step 2

Building Blocks Variables  Name of a storage location  Use ‘=‘ to assign a value to a variable Types  Various classifications of data  A variable can stores data of different types Operators for numbers  Arithmetic: + - * / % ** Functions (subroutines)  Sequence of instructions to perform a specific task

Variables Names are unique and can be abstract  What is  What is Declare a variable and assign a value  Name and type  Examples: int age = 18; age = 18

Data Types Int (integer)  4, 13, -7 Float (floating-point number)  Work just like normal numbers  ans = 2 * (7 + 4) – 1  ans = 21

Data Types Char (characters)  ‘H’, ‘8’ Str (string)  “HELLO”, “Echo 123” Arithmetic manipulation  phrase = “My name is ” + “Benfeard”  phrase = “My name is Benfeard”

Data Types Arrays  Collection of elements  [ 1, 2, 3, 4, 5] [ ‘A’, ‘B’, ‘C’, ‘D’, ‘E’ ] Manipulation  myArray = [1, 2, 3]  myArray = myArray * 2  myArray = [1, 2, 3, 1, 2, 3] Indexing elements

Functions Allows you to easily recall a procedure or subroutine def sum(a, b): return a+b Parameters  values in the call, that you pass to the function to use as input Output  Return value  Call Function  Answer = sum(7,3)  Answer = 10

Functions Example function that returns a value def greet(name): print "Hello " + name Advantages  Repeat code, call multiple times  Flexible, call with different arguments Functions  greet("Sue")

Booleans True or False Useful for comparisons  Greater than, less than  Is equal to, is not equal to Supports algebraic operations  And, or, not

If Statements and Loops If statement  If this statement is true, do something For loops  For all values in an array, do something repeatedly While loops  While a statement is true, do something repeatedly

Computers do what you tell them They are fast but not smart You need to plan exactly what the computer needs to do in order to solve a problem Outline the solution to your problem  Pseudocoding (step by step walkthrough of code)

Algorithms Describe in words how to solve a problem Like a recipe, must be detailed and precise How to make a Peanut Butter & Jelly Sandwich Ingredients: Two slices of bread Peanut Butter Jelly 1.Spread peanut butter on one slice 2.Spread jelly on the other slice 3.Combine slices together Does this provide enough information for anyone to make the sandwich?

Find Narten Anderson Applegate Bethune Brooks Carter Edwards Foggle Griffin Holhouser Jefferson Klatchy Morgan Munson Narten Oliven Parken Rivers Roberts Stevenson Thomas Wilson Woodrow Yarbrow Did you find Narten? Can you explain your step-by-step process? If this list had millions of names, what would be an efficient way to find Narten?

Creating an Algorithm Is the algorithm correct?  Try it again and again and again  Reason through it: logically and informally How efficient is the algorithm?  How many guesses would it take you to find Narten in the worst case scenario?  Should we care about efficiency?

How To Dissect Code ## Author’s comments ## def main(): filename = “romeo.txt” fileToProcess = open(filename) count = 0 for line in fileToProcess: words = line.strip().split() for word in words: if len(word) == 4: count = count + 1 print “count is”, count if __name__ == “__main__”: main() Opening a romeo.txt file Counting something Looping through lines Important information about function and usage from author Splitting lines into words? Words of length equal to 4? Increase counter Print count at the end Mysterious code…

Example In TextWrangler

Computers Read In Order We give computers the entire code but the computer cannot read ahead ## Author’s comments ## def main(): filename = “romeo.txt” count = 0 for line in fileToProcess: words = line.strip().split() for word in words: if len(word) == 4: count = count + 1 fileToProcess = open(filename) Print “count is”, count

Important Resources Howtolearntocode.web.unc.edu Stackoverflow.com BCB Modules ITS Research Computing HtLtC teachers