Post on 26-Dec-2015
THE PROCESS OF WRITING SOFTWARE
Python: System Engineering
http://www.flickr.com/photos/iamthestig2/3925864142/sizes/l/in/photostream/
1
Computing Systems
A computing system is composed of hardware: the physical components of the system software: the instructions that control the hardware
Hardware components include: Motherboard
Central processing unit (CPU) Memory (RAM / Drives)
IO Devices Video Card Sound Card Network Card
2
Hardware: CPU
Central Processing Unit An electronic chip that performs instructions
The “brains” of a computing system
A CPU can only perform very simple tasks: Can add/subtract/multiply/divide two numbers Can compare two numbers to see if one is smaller/larger Can copy/move data from one place to another
CPU’s appear more powerful than this since these tasks are done very quickly
3
Software and Programming
Tell the CPU to add two numbers Load the number from memory location 2001 into CPU
register R1 Load the number from memory location 2002 into CPU
register R2 Add the numbers in registers R1 and R2 Copy the result into memory location 2003
Programming in such a low-level fashion would not be good. Would like to write something like c = a + b
Programming languages make it easier for a programmer to talk to the CPU
4
Overview of Computation
Natural-language : a language used by people If it is written, it is defined by a system of symbols and
notations that communicate the content of the language
Examples: English, Spanish, French, Arabic, Tamil, etc…
Programming language : a language used by computers A system of symbols and notations that communicate
computational content to the CPU.
5
Low/High level languages
Low-level language Any language that is “close” to machine instructions Not meant for human readability Specific to the CPU
High-level language Any language that is closer to “natural” language Easier to read and understand Portable
6
Languages
Object code, bytecode
Assembly
Fortran, C
Algol, Pascal, Ada
Python, Java, Ruby
microcode
High Level
Low Level
Natural LanguageEnglish, Chinese, Japanese, …
Semantic Gap
Machine Language Example (Pentium III Linux Box)
01111111 0100010101001100 0100011000000001 0000000100000000 00000000…
Low Level Example
Can you understand this code?
8
Assembly Example (Pentium III Linux Box).file “hello.c”.version “01.01”.section .rodata
.LCO:.string “Hello World\n”
.text.align 4
.globl main.type main,@function
main:pushl %ebpmovl %esp,%ebppushl $.LCOcall printfaddl $4,%espxorl %eax,%eaxjmp .L1.p2align 4,,7
.L1:leaveret
Intermediate Level Example
Can you understand this code?
9
C Language Example (machine independent)
#include <stdio.h>
void main() {printf(“Hello World\n”);
}
High Level Example
Can you understand this code?
10
Compiled vs. Interpreted12
CompilerSource Program
Executable Code
(THE CPU)Input Output
Interpreter
Source Program Output
Input CPU
Compilation: The language is brought down to the level of the machine using a translator. The translator is often called a compiler.
Interpretation: The machine is brought up to the level of the language by the use of a virtual machine. This machine is often known as an interpreter.
Waterfall model
The waterfall model involves the following processes Analysis: Figure out exactly what the problem is. Understand
as much of the problem as possible Requirements: Describe exactly what your program will do
(not necessarily how). Design: Describe the variables, functions and classes of the
solution. Describe the algorithms that will be used in your software.
Implement: Translate the design into a programming language and enter it into the computer. This course will use Python.
Test/Debug: Execute your implementation and devise tests that are designed to expose errors (bugs).
Maintenance: Continue to improve/develop/fix the program in response to user needs.
13
Example: Temperature Conversion
Narrative: Susan is spending a year of study in China to learn advanced computer science programming. She speaks Chinese fluently and listens to the radio
every morning to figure out what the temperature will be so that she can dress appropriately.
The temperatures are reported in units of Celsius but she thinks only in terms of Fahrenheit.
The analysis is pretty easy in this case: She wants to write a program to convert Celsius to
Fahrenheit for her.
15
Example: Temperature Conversion
Requirements The program will allow her to type in a number that
represents the temperature in degrees Celsius. The program will then print out the corresponding
temperature in degrees Fahrenheit. The relationship between input and output must be
well defined. F = 9/5 * C + 32 F is degrees in Fahrenheit (the output) C is degrees Celsius (the input)
16
Example: Temperature Conversion
Design This is usually written in fake code (psuedo-code)
This is not a programming language Describes the essentials without worrying about detail For example:
Input the temperature in degrees C (call it celsius)Calculate Fahrenheit as (9/5)*celsuis + 32Output Fahrenheit
17
Example: Temperature Conversion
Implementation Must take the design and translate it into a program.
# convert.py# A program to convert Celsius temps to Fahrenheit# by: Susan Computewell
def main(): celsius = eval(input(“What is the Celsius temperature? ”)) fahrenheit = 9 / 5 * celsius + 32 print(“The temperature is”, fahrenheit, “degrees Fahrenheit)
main()
18
Example: Temperature Conversion
Testing How would you test this program?
# convert.py# A program to convert Celsius temps to Fahrenheit# by: Susan Computewell
def main(): celsius = eval(input(“What is the Celsius temperature? ”)) fahrenheit = 9 / 5 * celsius + 32 print(“The temperature is”, fahrenheit, “degrees Fahrenheit)
main()
19