1 / 32

Chapter 1 The Way of the Program

Chapter 1 The Way of the Program. Dr. Paige H. Meeker. Definition. What is computer science all about?. A computer scientist is…. A little bit of: Mathematician Engineer Natural Scientist Teacher Educator But most of all – A PROBLEM SOLVER. Problem Solving / Programming.

van
Télécharger la présentation

Chapter 1 The Way of the Program

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1The Way of the Program Dr. Paige H. Meeker

  2. Definition What is computer science all about?

  3. A computer scientist is… A little bit of: • Mathematician • Engineer • Natural Scientist • Teacher • Educator But most of all – A PROBLEM SOLVER

  4. Problem Solving / Programming • Computer scientist give computers lists of instructions (aka “programs”) in order to solve problems. • This semester, we will use the Python programming language to give instructions to our own programmable robot. • But first…

  5. Programming Languages • Low level • High level

  6. High Level Languages Advantages: • Easier to program • Faster to create • Shorter and easier to read • More likely to be correct • Portable

  7. The Translation Process • Compiler • Interpreter • Some use both – Python uses both, but because of the way users interact with it, is considered more of an interpreted language

  8. Python Interpreter • How do you use it? • Shell mode • Script mode

  9. Shell Mode • Python commands typed into the shell are immediately interpreted and executed. • Instructions are typed at the Python prompt, which looks like: >>> • Once the shell session is terminated, all instructions given during that session are lost.

  10. Script Mode • A program in a file • Name ends with “ .py” (perhaps we call it “firstprogram.py” • The file (or script) can then be run inside the interpreter’s shell with the command: >>>python firstprogram.py • Once the interpreter’s shell session is terminated, all instructions given during that session are lost, but all instructions held within a file are saved for use at a later time.

  11. So… Now What? • We can give the computer (and/or the robot) a set of instructions which tell it what we wish it to do. This is called “Programming”

  12. Computer Programming • What is computer programming? • Process of writing, testing, debugging, and maintaining the source code of computer programs.

  13. Computer Programming • Why do we do it? • To create a program that performs a desired behavior. • There is some debate as to whether programming is an art, a craft, or an engineering discipline.

  14. Computer Programming • Programmers work to create code that is efficient (works without draining current resources) and evolvable (can become something bigger in the future) • Programmers are generally given a list of requirements and then work to translate those requirements into something the computer can understand.

  15. Computer Programming • Programming is often compared to following a recipe. • Programming is about giving the computer step by step instructions to go about completing the task. • The instructions generally take the form of: • a direct statement • a conditional statement • a link to a group of statements • a loop around statements meant to be repeated for some amount of time.

  16. Pizza Dough Recipe (Requirements)‏ 1. Gather Ingredients 2. Combine sugar (1tbs), salt (1tbs), olive oil (1tbs), flour (1c) in mixing bowl 3. Turn on mixer 4. Add 1/4 cup of flour 5. If dough comes off the sides go to step 6, otherwise go back to step 4 6. Knead 15 minutes 7. Let rest for at least 45 minutes in warm area • 1 dough ball

  17. N-Pizza Dough Program • Gather Ingredients • Combine sugar (N tbs), salt (N tbs), olive oil (N tbs), flour (N c) in mixing bowl • Turn on mixer • Add N/4 cup of flour • If dough comes off the sides go to step 6, otherwise go back to step 4 • Knead 15 minutes • Let rest for at least 45 minutes in warm area • N dough balls

  18. N-Pizza Dough Program • Gather Ingredients • Combine sugar (N tbs), salt (N tbs), olive oil (N tbs), flour (N c) in mixing bowl • Turn on mixer • Add N/4 cup of flour • If dough comes off the sides go to step 6, otherwise go back to step 4 • Knead 15 minutes • Let rest for at least 45 minutes in warm area Sequence of Statements • N dough balls

  19. N-Pizza Dough Program Variable • Gather Ingredients • Combine sugar (N tbs), salt (N tbs), olive oil (N tbs), flour (N c) in mixing bowl • Turn on mixer • Add N/4 cup of flour • If dough comes off the sides go to step 6, otherwise go back to step 4 • Knead 15 minutes • Let rest for at least 45 minutes in warm area • N dough balls

  20. N-Pizza Dough - Program • Gather Ingredients • Combine sugar (N tbs), salt (N tbs), olive oil (N tbs), flour (N c) in mixing bowl • Turn on mixer • Add N/4 cup of flour • If dough comes off the sides go to step 6, otherwise go back to step 4 • Knead 15 minutes • Let rest for at least 45 minutes in warm area Conditional

  21. N-Pizza Dough - Program • Gather Ingredients • Combine sugar (N tbs), salt (N tbs), olive oil (N tbs), flour (N c) in mixing bowl • Turn on mixer • Add N/4 cup of flour • If dough comes off the sides go to step 6, otherwise go back to step 4 • Knead 15 minutes • Let rest for at least 45 minutes in warm area Subroutines Mini-programs • N dough balls

  22. Programming Languages • There are hundreds of different programming languages. • A few basic types of instructions appear in all of them • Input (get input from the user) • Output (display data to the user on a monitor or printout) • Math (perform basic mathematical operations) • Conditional Execution (check for conditions and execute the appropriate sequence of statements) • Repetition (perform some sequences of statements repeatedly) • Not too bad, right?

  23. Programming Benefits • What do students learn through programming? • Mathematical and computational ideas • Coordinates, Variables, Random Numbers • Problem solving skills • Process of Design • Idea->Prototype->Experiments->Debugging->Redesign->New Ideas • Fluency with Digital Technology • To be fluent in language, you learn to read AND write – how to express yourself in the language. The same is true of programming – using the computer not just to interact but to create.

  24. Debugging • Nobody’s perfect – especially not the first time! • Debugging is the process of finding errors in the program and correcting them. • The term was first used by Grace Hopper, when she found a “bug” in the computer in the 1950’s (see photo) • Debugging is a vital programming skill 1st use of “computer bug”

  25. Types of Bugs • Syntax • Runtime • Semantic

  26. Syntax Errors • Programs must have correct syntax in order to run. • Syntax refers to the structure of a program and the rules about that structure. • Just one syntax error caused your program to quit. • Be prepared for this to happen quite frequently at first!

  27. Runtime Errors • An error that doesn’t appear until a program is run. • Aka “Exceptions”

  28. Semantic Errors • Really difficult to find • Program runs to completion, but produces an incorrect result • Must find them by looking at what the code is doing, not what you think its doing.

  29. Languages • Formal • Natural

  30. Similarities between Natural and Formal Languages • Both have rules of syntax • Both can be parsed

  31. Differences between Formal and Natural Languages • Ambiguity • Redundancy • Literalness

  32. The First Program • “Hello World” • >>>print "Hello, World!" • This is an example of a print statement, which doesn’t actually print anything on paper. It displays a value on the screen. • The quotation marks in the program mark the beginning and end of the value; they don’t appear in the result.

More Related