48
PROGRAMMING FUNDAMENTALS Neal Stublen [email protected]

Neal Stublen [email protected]. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Embed Size (px)

Citation preview

Page 1: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

PROGRAMMING FUNDAMENTALS

Neal Stublen

[email protected]

Page 2: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

AN OVERVIEW OF COMPUTER PROGRAMMING

Page 3: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Computer Systems

Hardware

Display

Keyboard

Mouse

Microphone

Memory ChipsMicroprocessor

Page 4: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Computer Systems

Hardware

System Software

Windows

LinuxAndroid

iOSMac OS

Page 5: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Computer Systems

Hardware

System Software

Application Software

Microsoft Word

Visual Studio Face TimeAngry Birds

FirefoxPhotoshop

Page 6: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

System vs. Application Software

Specialized skills target different levels of software development

Application software provides specialized services

System software makes common services available to all applications

Application software performance affects (most often) a single application

System software performance impacts every application

Page 7: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Review Question

Classify the following as system software or application software:Word processing softwarePrinter driver softwareVideo gamesInternet browser

The line may seem fuzzy at times, but often individual developers may focus on one or the other.

Page 8: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Software Operations

Input

Page 9: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Data Input

Sources of data input? Keyboard/mouse Touch screen Files on a hard drive Sound in a microphone Camera images Accelerometer/gyroscope sensor data

Page 10: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Software Operations

Input Processing

Page 11: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Processing

Processing is done by the CPU Examples of processing Position cursor on screen Reformat text Perform voice recognition Sharpen photographic data Detect shaking gesture

Page 12: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Software Operations

Input Processing Output

Page 13: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Data Output

Examples of data output? Update display on monitor Play sounds through a speaker Write files on a hard drive Start or stop a motor

Page 14: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

"Coding" Software Software instructions are written in a computer

programming language What programming languages can you identify?

C/C++JavaC#Visual BasicPythonPHPJavaScriptPerl

Page 15: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Language Progression Programming instructions are converted into

codes that can be understood by the computer Languages progress to make programming

tasks easier and clearer

int var = 0;var++;

.DATAvar  DB 0

mov eax, [var]inc eaxmov [var], eax

Page 16: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Language "Syntax"

Each language has its own syntax for formatting instructionsint value = 25;  // C++, C#value = 25  // Pythonvar value = 25;  // JavaScript

Syntax must match expected formatting or the computer program cannot be converted into machine instructions

Page 17: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Compilers/Interpreters Computer language instructions are converted

using a compiler or interpreter A compiler converts a program into low-level

instructions before the program can executeSyntax errors are found before the program runsC++, C#, Java

An interpreter converts a program into low-level instructions as the program executesSyntax errors may not be discovered for a long

timePython, PHP, Perl, JavaScript

Page 18: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Source Code and Object Code

We refer to our high-level computer program as source code

We refer to low-level machine instructions as object code

Page 19: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Programming Logic

Instructions are performed in a specific sequence to accomplish the desired purpose

Logical errors prevent a program from working correctly

Logical errors may exist when syntax errors do not

Page 20: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Syntax Errors

Two add eggs Flour in stir One sugar add cup At minutes 350 45 bake degrees for

Page 21: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Logic Errors

Stir in flower Add two eggs Bake at 350 degrees for 45 minutes Add one cup sugar

May be referred to as "sematic errors" More commonly referred to as "bugs"

Page 22: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Sample I-P-O

input someNumber

someResult = someNumber * 2

output someResult

Pseudocode instructions are English-like statements that represent the actions a program will need to take. 

Page 23: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Sample I-P-O

input someNumber

someResult = someNumber * 2

output someResult

Input some value and store it in a memory location that's referred to using the name "someNumber".

Page 24: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Sample I-P-O

input someNumber

someResult = someNumber * 2

output someResult

Retrieve the value stored in the memory location referred to by "someNumber".  Double the value and store it in a memory location referred to by " someResult".

Page 25: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Sample I-P-O

input someNumber

someResult = someNumber * 2

output someResult

Send the value stored in the memory location referred to by "someResult" to an output device.

Page 26: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Review Question

Which of the following best describes a syntax error?

A. Syntax errors are found during user data input processing.

B. Syntax errors are identified by the compiler or interpreter.

C. Syntax errors are found when the program is run.

D. Syntax errors may be identified by the hardware device driver code.

Page 27: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Review Question

Which of the following best describes a syntax error?

A. Syntax errors are found during user data input processing.

B. Syntax errors are identified by the compiler or interpreter.

C. Syntax errors are found when the program is run.

D. Syntax errors may be identified by the hardware device driver code.

Page 28: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Review Question

Which of the following best describes a logic error?

A. Logic errors are found during user data input processing.

B. Logic errors are identified by the compiler or interpreter.

C. Logic errors are found when the program is run.

D. Logic errors may be identified by the hardware device driver code.

Page 29: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Review Question

Which of the following best describes a logic error?

A. Logic errors are found during user data input processing.

B. Logic errors are identified by the compiler or interpreter.

C. Logic errors are found when the program is run.

D. Logic errors may be identified by the hardware device driver code.

Page 30: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Procedural Programming

Breaks down a programming task into a series of smaller subtasks (or procedures)

Focus on procedures needed to accomplish the task

Page 31: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Object-Oriented Programming

Breaks down a programming task into objects that model the task

Focus on objects that can be used to accomplish the task

Page 32: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Objects

Attributes - features or properties of the object (things it "has" or "is")

Behaviors - actions that can be performed on or by the object (things it "does")

Object state - values of an object's collection of attributes

Page 33: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Stages of Development

Object-oriented analysis (OOA) Object-oriented design (OOD) Coding/Implementation Testing Maintenance

Page 34: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Object-Oriented Analysis

Determine user needs

Who is a user? What problem needs

to be solved?

Page 35: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Object-Oriented Design

Develop an object model to represent the problem and its solution

Consider object attributes and behaviors Determine relationships between objects How do they communicate and respond

to one another? has a, is a, creates a Each type of object will be represented

by a class

Page 36: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Object Examples

What objects can you identify on your phone?

What attributes and behaviors would be defined for those objects?

Page 37: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Coding/Implementation Develop the logic of the program

Mental planningSimple to complex drawingsCollaboration with others

Produce algorithms - a sequence of steps to solve a problem

Write source code in an appropriate language

Translate source code into object code that can be understood by the computer

Page 38: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Language Selection The choice of a programming language

may be dictated by the problem being solved.

Support multiple platforms? Run within a web browser? Performance is critical? Google App Engine? Extension for WordPress? Windows desktop application?

Page 39: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Testing

All software needs to be testedConfirms the program works as expected

Self-testing Testing team Automated testing

Page 40: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Maintenance

All software needs updates Why would you need to update an

application?Mistakes need correctionUser needs changeFeatures can be improved

Page 41: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

TOOLS FOR PLANNING

Page 42: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Pseudocode

English-like representation of the logical steps needed to solve a problem

Guidelines: http://bit.ly/pf-pcode

start

  input radius  area = radius * radius * pi  output areaend

start  change oil  inflate tires  check fluidsend

Page 43: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Flowcharts Visual representation of program logic Terminal blocks I/O blocks Processing blocks Decision blocks

Gliffy - http://www.gliffy.com Draw.io - http://www.draw.io Lucidchart - http://www.lucidchart.com Visual Logic – http://www.visuallogic.org

Page 44: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Example

Approaching a stop light...

Page 45: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Programming Environments Text editor Integrated development environment

(IDE)EditorCompilerDebugging Tools

Notepad++ Visual Studio

Page 46: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

User Environments

Command line Graphical user interface (GUI)

Page 47: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Exercise

Case Projects, p. 29, #1

Page 48: Neal Stublen nstublen@jccc.edu. Computer Systems Hardware Display Keyboard Mouse Microphone Memory Chips Microprocessor

Summary

Overview of computer systems System vs. application software Software operations (I-P-O) Programming terminology Programming methodology Planning tools Application environments