What are computer languages and What is the basic process...

26

Transcript of What are computer languages and What is the basic process...

Page 1: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over
Page 2: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

What is programming?

What are computer languages and

how have they evolved?

What is the basic process of

programming, including the tools

involved?

Page 3: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

A step-by-step set of instructions

to accomplish a task.

Example: Make KoolAid

- Fill jug with water

- Add KoolAid mix

- Stir

- Pour from jug into cups

Page 4: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

A step-by-step set of instructions

to accomplish a task

expressed in a Computer

Language

Page 5: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Machine Language

- Consists of binary codes for very

simplistic commands

Ex: 1001 (move), 1100 (add)

- Codes differ by CPU model

- Is the only language a CPU can

follow

- Using ML Requires detailed

knowledge of the CPU/hardware.

Page 6: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Machine Language

ENIAC being

programmed

Univ of Penn, 1940’s(photo: U.S. Army)

Page 7: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Assembly Language

- Consists of text codes for very

simplistic commands

Ex: ADD, SUB, MOVE

- Codes differ by CPU model

- 1-to-1 translation to Machine

Language

- Using Assembly requires detailed

knowledge of the CPU/hardware

Page 8: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

High Level Language

- Consists of text codes for more

complex expressions

- Codes standardized across CPU models

- 1-to-Many translation to Machine

Language

- Does not require detailed knowledge

of the CPU/hardware.

Page 9: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

ML vs ASSM vs HLL

Assembler: Machine Lang:MOV @065 to CPU:R1 10010001 01000001

MOV @066 to CPU:R2 10010010 01000010

ADD 01010000

MOV CPU:REG3 to @067 10100010 01000011

High Level Language:

x = a + b

Page 10: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Early High Level Languages

Fortran (FORMula TRANSlation)

- by IBM, 1950’s

- Number cruncher for

mathematicians, scientists and

engineers.

- Ex: A = 3.1415926 * R * R;

- Very poor at manipulating “pretty”

output and large volumes of data.

Page 11: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Early High Level Languages

COBOL (COmmon Business

Oriented Language)

- by committee, funded by DoD, 1960

- For business/management apps: does

“pretty” and handles large volumes of

data easily.

- Very English-Like. Ex:

ADD SUBTOTAL TO TAX GIVING TOTAL.

Page 12: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

High Level Languages

C

- by Dennis Ritchie (AT&T), 1972

- Combines ease-of-use of a HLL with

the “power” of Assembly

- Used to write efficient systems

software (Unix Operating System)

Page 13: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Efficiency

Accomplishing a task using the least

amount of resources.

In Programming, “resources” are:

- Time (number of instructions executed)

- Space (amount of memory required)

Page 14: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

High Level Languages

C++

- By Bjarne Stroustrup (AT&T), 1983

- Enhancement of C: major items:

- Object-Oriented Programming

- Extensibility: programmers can add

new features to the language itself.

Today: one of the most common languages.

Page 15: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Tools, Files and Errors

Page 16: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Software ToolsEditor – used to write the program in a HLL.

Compiler – translates program in a HLL into

Machine (or other low level) Language

Linker – combines Object Files into an

Executable.

Loader – copies an Executable into memory and

starts program execution.

Page 17: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Software Tools

Integrated Development Environment (IDE)

Combines the editor, compiler, linker, loader and

often other helpful tools into one programming

tool.

Example: Microsoft Visual Studio IDE

Page 18: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

FilesSource – a text file containing a program written

in a HLL

Object – part of a program translated in Machine

Language

Executable – a complete program in Machine

Language

Page 19: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

ErrorsSyntax (aka Compiler) – found in the Source,

these are violations of the rules for writing

programs in the HLL.

Link – the linker is unable to link the object files

into an executable. Typical errors indicate

something is missing or the parts (objects) do

not “fit” together as expected.

Page 20: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

ErrorsLoad – the loader is unable to copy the

executable into memory and start execution.

Typical errors include “not enough memory” or

“not a trusted program” (virus protection).

Run-Time – occurs during execution. Typical

errors include “division by 0”, “file not found”,

“memory access violation”. Execution halts

when a RTE occurs; normally called a “program

crash” and may not have an error message.

Page 21: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

ErrorsLogic (Semantic) – when there is no error from

the perspective of the computer, but rather the

program does something unexpected by the user.

Example: The program prints:

The area of a square with a length of 3m is 6m2

Page 22: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Errors

Bug

informal name for a Logic (or Run-Time) Error

Page 23: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

- Programming is writing instructions for a

computer to follow.

- Various languages have been invented over

the years to assist programmers.

- While variations exist, there is a basic

process for writing code in a HLL and

translating it into ML, including use of a

basic set of tools.

Page 24: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Term Definition

Algorithm A step-by-step set of instructions to accomplish a task

Program A step-by-step set of instructions to accomplish a task expressed in a

computer language.

Machine Language Binary computer language that differs by CPU model…the only language a

computer can follow.

Assembly Language Language made up of simple text codes for simplistic instructions. It differs by

CPU model and has a 1-to-1 translation of commands into Machine Language.

High Level Language Language made up of more complex and human-language-like codes with a 1-

to-many translation of commands into Machine Language.

FORTRAN Early language used to solve mathematical/scientific/engineering problems.

COBOL Early language used for business data processing.

C Language combining the functionality of a HLL with that of Asssembly, used to

write Systems Software.

Page 25: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Term Definition

C++ An enhancement of the C language providing support for Object-Oriented

Programming and language Extensibility.

Extensibility The ability of a programmer to extend an existing language with new

features.

Editor Software tool that allows a programmer to write a program in a HLL.

Compiler Software tool that translates a program in a HLL into Machine Language.

Linker Software tool that combines Object Files into a single Executable.

Loader Software tool that copies an Executable into memory and initiates program

execution.

Source File Text file that contains a program written in a HLL.

Object File File that contains instructions in Machine Language, but is not a complete

program.

Executable File File that contains instructions in Machine Language that is a complete

program.

Page 26: What are computer languages and What is the basic process ofcs.uky.edu/~kwjoiner/cs215/notes/IntroToProgramming.pdf · computer to follow. - Various languages have been invented over

Term Definition

Syntax Error Violation of a HLL rule in a Source File, discovered by the Compiler

Compiler Error (same as Syntax Error)

Link Error Error meaning the Linker is unable to combine Object Files into an Executable

Load Error Error meaning the Loader is unable to copy an Executable into memory and

initiate program execution.

Run-Time Error Error that occurs while a program is executing, causing the program to halt.

Logic Error Unexpected output/behavior of a program when there is no other type of

error.

Semantic Error (same as Logic Error)

Bug Informal word meaning Logic (or Run-Time) Error