Welcome to CS 201 Problem Solving with Computers Dr., Dept. of Computer Science
Welcome Lectures on Mondays & Wednesdays Labs on Tuesdays & Thursdays Course website at http://www2.cs.siu.edu/~wainer/201f11/cs201f11outline.html e-mail wainer@cs.siu.edu Textbook is Introduction to Computing and Programming in Python: A Multimedia Approach by Mark J. Guzdial and Barbara Ericson
Introduction 1) What is Computer Science about? 2) Basics of Computers and programming 3) Media Computation 4) Computer Science for Everyone thinking about process, information and communication
Recipes? Text uses the analogy of recipes. Instructions on how to accomplish a task. Inputs (the ingredients) Outputs (the results created)
Recipes? Text uses the analogy of recipes. Instructions on how to accomplish a task. Inputs (the ingredients) Outputs (the results created) computer does the recipe
Studying Recipes Computer Science studies aspects of recipes How to construct appropriate recipes (software engineering, algorithms) Ingredients to use and how to organize them (information, data structures, databases) Adapting recipes for different types/systems of cooks (systems:mobile, cloud, parallel etc., theory) Considering how well the recipes satisfy the customers/users (UI Design)
Computer Science Many different specialties covered by a variety of conferences, journals, magazines, special interests groups, societies etc. Association for Computing Machinery SIGART SIGCHI SIGWEB SIGCSE SIGARCH SIGCHI SIGGRAPH SIGBioinformatics SIGMOBILE International Society for Computers and their Applications
Why Bother Learning to Program? As a user, you use software that already exists. It may not be what you really want. Programmers have the ability to create new (or customize existing) software to better match their needs. Programming is a challenging creative activity. It helps in understanding and communicating ideas of process. (including its limits and potential) Everyone should learn to program Alan Perlis
Programming Programming can range from very small code snippets which quickly do a tedious task up to constructing very large systems for very specific cases. Millions of lines of code are now used in aircraft and even luxury cars. (10s of millions in modern operating systems.) Many systems allow users/programmers to add custom features through programming. OpenSource projects have code which is freely available to examine and modify (you don't need to start from scratch).
How a Computer Works (recipe model) output input processing unit
How a Computer Works (simplified model) output CPU ( Central Processing Unit ) Main Memory input Disk
What Computers Understand CPU ( Central Processing Unit ) Main Memory All information is represented as 1s and 0s grouped together as chunks of data stored in memory. The CPU has a simple set of instructions to read/write data from memory, make comparisons, move to internal registers, do simple arithmetic (+,-,*,/) and obtain the next instruction. These operations are done FAST and we can build up more complex things from simple parts.
It's all 1s and 0s - Encodings Everything is memory is just 1s and 0s (bits). The CPU can fetch what bits are at a particular memory address. The sequence is interpreted according to an encoding. For instance, 8 bits (a byte) can be interpreted as a decimal number address in Main Memory 7 6 5 4 3 2 1 0 0 0 1 0 1 0 0 1 2 6 2 4 2 2 64 + 16 + 4 = 84
Encodings can be Layered What does the 84 mean? It depends upon its encoding. For instance to store letters in memory each letter is given a numerical code. In the commonly used ASCII system, 84 maps to the letter T. A string of characters could be represented by a sequence of ASCII codes. 7 6 5 4 3 2 1 0 0 0 1 0 1 0 0 1 2 6 2 4 2 2 64 + 16 + 4 = 84 ASCII T
Software Determines the Encodings Each program must know how to interpret the data properly. That same 84 might be used to represent: Part of a larger number (8 bits of 32 bits ) Part of a data record (model no. for part database etc.) Part of an instruction code (CPU instruct. also in mem.) Red component for a pixel within an image Width of an image media Sample for a sound signal } Some interpretations are lower level than others. It's up to the software to make the correct interpretation.
Examples A web browser interprets data as text, and the text as page layout instructions. <p>a <b>flowchart</b> is a type of <a href="/wiki/diagram" title="diagram">diagram</a> that represents an <a href="/wiki/algorithm" title="algorithm">algorithm</a> or <a href="/wiki/process_(science)" title="process (science)">process</a>, showing the steps as boxes of various kinds, and their order by connecting these with arrows. If we wrote our own card game program, we would have to develop an encoding too.??? playerid no. cards card.0 card.1...
Software is also encoded CPU ( Central Processing Unit ) OS Main Memory app Disk Operating System and Application software are loaded and encoded into memory. The CPU reads memory to find out what instructions to do next thus executing the programs. We use special development programs and the OS to create, load and execute our own code.
Assignments Read Chapter 1 and start on Chapter 2. Lab Preview: (Tue & Thur afternoons) We'll look at the ideas of encoding characters with ASCII. Different applications can interpret/display the same data differently and we can use this to our advantage to get the format most useful to us. We start to think about telling the computer what we want it to do. Introduce flow charting and the JES (python programming) curchar = 1st character of thestring is curchar valid? N End
UG CS Major Orientation Thursday, Aug 25 4-6 Eng. Bldg, Alumni Lounge A131 Questions? Call 536-2327 CS Main Office
Remember, software is also encoded Operating System and Application software are loaded and encoded into memory. CPU ( Central Processing Unit ) OS Main Memory app Disk The CPU reads memory to find out what instructions to do next thus executing the programs. CPUs only understand simple instructions: LDA, STA etc. Luckily the power of computers continues to increase!
Moore's Law Number of transistors which can be placed on a chip doubles every 2 years! Exponential improvement relates to speed & memory size as well.
Programming Languages Rather than programming for the very low level CPU, programs (recipes) are more often written in higher level programming languages. Programming Languages main() { main() {... } source code translate 0110011 0111100 1100001 1101010 machine code
Programming Languages Rather than programming for the very low level CPU, programs (recipes) are more often written in higher level programming languages. Programming Languages main() { main() {... } source code Another CPU, another machine language translate 0110011 0111100 1100001 1101010 1101001 1000010 1110010 0111101 010 0000100 1110010 1111010 1010000 machine code
Programming Languages Rather than programming for the very low level CPU, programs (recipes) are more often written in higher level programming languages. Programming Languages C Fortran Another CPU, another machine language main() { Cobol Basic source code translate 0110011 0111100 1100001 1101010 1101001 1000010 1110010 0111101 010 0000100 1110010 1111010 1010000 machine code
Programming Languages Sometimes, rather than targeting a specific machine, code is translated to another language instead. This can make it easier to port code across different platforms. Portability becomes a problem!!! Python Can write the translator for one language using an existing language Application C translate 0110011 0111100 1100001 1101010 1101001 1000010 1110010 0111101 010 0000100 1110010 1111010 1010000 machine code {Open Source}
Programming Languages Another approach uses a layer of software to wrap the real hardware/system with a virtual one. Languages can then be target to the virtual system. Virtual Machines can wrap actual hardware Python vm Can write the translator for one language using an existing language Jython Java C translate 00001001 11001011 11010101 0000 vm vm 0110011 0111100 1100001 1101010 1101001 1000010 1110010 0111101 010 machine code
Jython is Python Python is a general purpose high-level programming language (often used as a scripting language). design philosophy emphasizes code readability large standard library ( batteries included ) dynamically typed automatic memory management supports multiple programming styles (structured, OO..) uses indentation to form code blocks (not { } etc.) free open source reference implementation
JES Overview Program Area Command Area
Sample Code variable with dynamic typing for loop coding is about naming bring in another module import string letters = string.ascii_letters for letter in letters: print letter +, + str(ord(letter)) string indent display a readable representation functions Start assign letters letter = 1st character of letters Is letter valid? Y N End Y Print letter & code letter = next character of letters