Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See

Slides:



Advertisements
Similar presentations
Input and Output Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Advertisements

Directory and File Paths Copyright © Software Carpentry and The University of Edinburgh This work is licensed under the Creative Commons Attribution.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Interfaces Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Visualization Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
Slicing Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Floating Point Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Control Flow Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Sorting CMSC 201. Sorting In computer science, there is often more than one way to do something. Sorting is a good example of this!
8 Algorithms Foundations of Computer Science ã Cengage Learning.
Software project management Module 1 -Introduction to process management Teaching unit 1 – Introduction Ernesto Damiani Free University of Bozen-Bolzano.
CS /29/2004 (Recitation Objectives) and Computer Science and Objects and Algorithms.
ECE Lecture 1 1 ECE 3561 Advanced Digital Design Department of Electrical and Computer Engineering The Ohio State University.
Lab 5 Using methods Why methods ? Manage complexity Manage complexity Better program organization Better program organization Next step in understanding.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
Programming. Software is made by programmers Computers need all kinds of software, from operating systems to applications People learn how to tell the.
Introduction Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
Loops and Iteration Chapter 5 Python for Informatics: Exploring Information
Mechanics Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Chapter 11 Introduction to Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Fixtures Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Nanotech Example Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
1 CS 350 Data Structures Chaminade University of Honolulu.
Invasion Percolation: Assembly Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
More Tools Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Storage Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Computer Science and Software Engineering© 2014 Project Lead The Way, Inc. Procedural Abstraction Object-Oriented Code.
This Power Point presentation was presented at the NSTA regional conference in Seattle, December 9, 2011 Images without permission for distribution have.
First-Class Functions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Caring for Goldfish Part 2. Daily Objective Fish have basic needs. Fish change their environment. Fish behavior is influenced by conditions in the environment.
Testing Mutable Objects CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons.
CSI 1340 Introduction to Computer Science II Chapter 1 Software Engineering Principles.
Operators Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Invasion Percolation: Randomness Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
The Last Lecture CS 5010 Program Design Paradigms "Bootcamp" Lesson © Mitchell Wand, This work is licensed under a Creative Commons Attribution-NonCommercial.
Exceptions Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Loops and Iteration Chapter 5 Python for Informatics: Exploring Information
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Lecture 6 Title: Project Cost Management MIS 434.
SL/HL BioChem Project. Make a song and music video Step 1: Write the song I recommend creating a parody of an existing song, so you don’t need to compose.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion (Continued) Prof. Katherine Gibson Prof. Jeremy Dixon Based on slides from UPenn’s.
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Python Aliasing Copyright © Software Carpentry 2010
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
Program Design Invasion Percolation: Aliasing
Sets and Dictionaries Examples Copyright © Software Carpentry 2010
7 Big Ideas of Computing:
CMSC201 Computer Science I for Majors Lecture 18 – Recursion
CS 5010 Program Design Paradigms “Bootcamp” Lesson 8.7
Program Design Invasion Percolation: Resolving Ties
CS 5010 Program Design Paradigms "Bootcamp" Lesson 12.1
Program Design Invasion Percolation: Neighbors
CMSC201 Computer Science I for Majors Lecture 16 – Recursion
Software Development Process
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Version Control Basic Operation Copyright © Software Carpentry 2010
Programming.
Testing Mutable Objects
Version Control Introduction Copyright © Software Carpentry 2010
Computational Thinking
A Level Computer Science Topic 6: Introducing OOP
Quiz: Computational Thinking
U3L4 Using Simple Commands
Presentation transcript:

Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See for more information. Classes and Objects

Introduction Computer science is the study of algorithms

Classes and ObjectsIntroduction Computer science is the study of algorithms Computer programming is about creating and composing abstractions

Classes and ObjectsIntroduction Computer science is the study of algorithms Computer programming is about creating and composing abstractions hide the details

Classes and ObjectsIntroduction Computer science is the study of algorithms Computer programming is about creating and composing abstractions hide the details make one thing act like another

Classes and ObjectsIntroduction Computer science is the study of algorithms Computer programming is about creating and composing abstractions hide the details make one thing act like another Functions turn many steps into one (logical) step

Classes and ObjectsIntroduction Computer science is the study of algorithms Computer programming is about creating and composing abstractions hide the details make one thing act like another Functions turn many steps into one (logical) step Libraries group functions to make them manageable

Classes and ObjectsIntroduction Computer science is the study of algorithms Computer programming is about creating and composing abstractions hide the details make one thing act like another Functions turn many steps into one (logical) step Libraries group functions to make them manageable Classes and objects combine functions and data

Classes and ObjectsIntroduction Computer science is the study of algorithms Computer programming is about creating and composing abstractions hide the details make one thing act like another Functions turn many steps into one (logical) step Libraries group functions to make them manageable Classes and objects combine functions and data And, if used properly, do much more as well

Classes and ObjectsIntroduction Simple simulation of aquarium containing

Classes and ObjectsIntroduction Simple simulation of aquarium containing plants

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnails

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnailsfish

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnailsfish don't move photosynthesize

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnailsfish don't movecrawl in 2D photosynthesizescavenge

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnailsfish don't movecrawl in 2Dswim in 3D photosynthesizescavengehunt

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnailsfish don't movecrawl in 2Dswim in 3D photosynthesizescavengehunt Algorithm is simple

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnailsfish don't movecrawl in 2Dswim in 3D photosynthesizescavengehunt Algorithm is simple for t in range(timesteps): move(world, everything) eat(world, everything) show(world, everything)

Classes and ObjectsIntroduction Simple simulation of aquarium containing plantssnailsfish don't movecrawl in 2Dswim in 3D photosynthesizescavengehunt Algorithm is simple Program is more complicated for t in range(timesteps): move(world, everything) eat(world, everything) show(world, everything)

Classes and ObjectsIntroduction def move(world, everything): for thing in everything: if thing[0] == 'plant': pass # plants don't move elif thing[0] == 'snail': move_snail(snail) elif thing[0] == 'fish': move_fish(fish)

Classes and ObjectsIntroduction def move(world, everything): for thing in everything: if thing[0] == 'plant': pass # plants don't move elif thing[0] == 'snail': move_snail(snail) elif thing[0] == 'fish': move_fish(fish) So far, so good

Classes and ObjectsIntroduction def eat(world, everything): for thing in everything: if thing[0] == 'plant': photosynthesize(world, plant) elif thing[0] == 'snail': scavenge(world, snail) elif thing[0] == 'fish': prey = hunt(world, everything, thing) if prey != None: devour(world, everything, thing, prey)

Classes and ObjectsIntroduction def eat(world, everything): for thing in everything: if thing[0] == 'plant': photosynthesize(world, plant) elif thing[0] == 'snail': scavenge(world, snail) elif thing[0] == 'fish': prey = hunt(world, everything, thing) if prey != None: devour(world, everything, thing, prey) Hmm…

Classes and ObjectsIntroduction def show(world, everything): show_world(world) for thing in everything: if thing[0] == 'plant': show_plant(plant) elif thing[0] == 'snail': show_snail(snail) elif thing[0] == 'fish': show_fish_fish)

Classes and ObjectsIntroduction def show(world, everything): show_world(world) for thing in everything: if thing[0] == 'plant': show_plant(plant) elif thing[0] == 'snail': show_snail(snail) elif thing[0] == 'fish': show_fish_fish) This is starting to look familiar…

Classes and ObjectsIntroduction Pessimist: code that's repeated in two or more places will eventually be wrong in at least one

Classes and ObjectsIntroduction Pessimist: code that's repeated in two or more places will eventually be wrong in at least one To add starfish, we have to modify three functions

Classes and ObjectsIntroduction Pessimist: code that's repeated in two or more places will eventually be wrong in at least one To add starfish, we have to modify three functions remember to

Classes and ObjectsIntroduction Pessimist: code that's repeated in two or more places will eventually be wrong in at least one To add starfish, we have to modify three functions remember to What about fish that eat plants? Or scavenge?

Classes and ObjectsIntroduction Pessimist: code that's repeated in two or more places will eventually be wrong in at least one To add starfish, we have to modify three functions remember to What about fish that eat plants? Or scavenge? Optimist: every pattern in a program is an opportunity to shorten that program

Classes and ObjectsIntroduction Wouldn't this be simpler?

Classes and ObjectsIntroduction for thing in everything: thing.move() prey = thing.eat(everything) if prey: thing.devour(prey) everything.remove(prey) Wouldn't this be simpler?

Classes and ObjectsIntroduction Wouldn't this be simpler? Easier to understand (after some practice) for thing in everything: thing.move() prey = thing.eat(everything) if prey: thing.devour(prey) everything.remove(prey)

Classes and ObjectsIntroduction Wouldn't this be simpler? Easier to understand (after some practice) Much easier to add new kinds of things for thing in everything: thing.move() prey = thing.eat(everything) if prey: thing.devour(prey) everything.remove(prey)

Classes and ObjectsIntroduction Nothing is free

Classes and ObjectsIntroduction Nothing is free Simple programs become slightly more complex

Classes and ObjectsIntroduction Nothing is free Simple programs become slightly more complex And too much abstraction creates as big a mental burden as too little

Classes and ObjectsIntroduction Nothing is free Simple programs become slightly more complex And too much abstraction creates as big a mental burden as too little Degree of Abstraction Mental Effort Required Putting steps together to get big picture

Classes and ObjectsIntroduction Nothing is free Simple programs become slightly more complex And too much abstraction creates as big a mental burden as too little Degree of Abstraction Mental Effort Required Putting steps together to get big picture Tracing steps to figure out what actually happens

January 2011 Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See for more information. created by Greg Wilson