24
Programming Languages: History & Traditional Concepts CSC 2001

Programming Languages: History & Traditional Concepts CSC 2001

Embed Size (px)

Citation preview

Programming Languages:History & Traditional

Concepts

Programming Languages:History & Traditional

Concepts

CSC 2001CSC 2001

Solution developmentSolution development

Three main tasks (all very important): Understanding the problem

unambiguous, complete description verification/testing

Solution planning pseudocode algorithmic design verification/testing

Implementation expressing solution in a manner that a computer can

execute “programming,” but being a computer programmer is more

than this!! verification/testing

Three main tasks (all very important): Understanding the problem

unambiguous, complete description verification/testing

Solution planning pseudocode algorithmic design verification/testing

Implementation expressing solution in a manner that a computer can

execute “programming,” but being a computer programmer is more

than this!! verification/testing

ImplementationImplementation

Historical perspective Traditional programming concepts Procedural units Language implementation Programming language paradigms

imperative programming object-oriented programming Others

Alice Programming Lego Mindstorm Robots with

Drizzle

Historical perspective Traditional programming concepts Procedural units Language implementation Programming language paradigms

imperative programming object-oriented programming Others

Alice Programming Lego Mindstorm Robots with

Drizzle

HistoryHistory

Machines can execute instructions in machine language.4056

Problems?machine dependenthard to read, write, and fix (debug)

Machines can execute instructions in machine language.4056

Problems?machine dependenthard to read, write, and fix (debug)

Assembly languageAssembly language

In 1940’s, programmers developed a mnemonic notational system to help.4056 became something like…MOV R5, R6had to build assemblers to translate to

machine languagePros?

more readable, easier to writeCons?

still very low level and machine dependent

In 1940’s, programmers developed a mnemonic notational system to help.4056 became something like…MOV R5, R6had to build assemblers to translate to

machine languagePros?

more readable, easier to writeCons?

still very low level and machine dependent

Remaining challengesRemaining challenges

Machine independent languageAbility to express instructions in larger

increments

Why are these good goals?What additional tools need to be built to

make it work?Can you foresee any major obstacles

with this?

Machine independent languageAbility to express instructions in larger

increments

Why are these good goals?What additional tools need to be built to

make it work?Can you foresee any major obstacles

with this?

Two early successesTwo early successes

FORTRANFORmula TRANslatorfocused on scientific applications

COBOLCommon Business-Oriented

Languagedeveloped by US Navy for business

applications

FORTRANFORmula TRANslatorfocused on scientific applications

COBOLCommon Business-Oriented

Languagedeveloped by US Navy for business

applications

Supporting toolsSupporting tools

compilerstranslated from higher level languagestores result of translation for later

executioninterpreters

execute while translating

compilerstranslated from higher level languagestores result of translation for later

executioninterpreters

execute while translating

Language “generations”Language “generations”

First generationmachine language

Second generationassembly languageneeds assemblers

Third generationhigher level languagesneeds compilers or interpreters

First generationmachine language

Second generationassembly languageneeds assemblers

Third generationhigher level languagesneeds compilers or interpreters

High level language goals revisited

High level language goals revisited

Did the third generation languages achieve their goals of machine independence and larger instruction increments?

Larger instruction increments?Yes

Machine independent solutions?In theory

Did the third generation languages achieve their goals of machine independence and larger instruction increments?

Larger instruction increments?Yes

Machine independent solutions?In theory

What do I mean?What do I mean?

We traded machine dependence for compiler dependence.

If all compilers define the language exactly the same way, we have machine independence.

This is often not the case!

We traded machine dependence for compiler dependence.

If all compilers define the language exactly the same way, we have machine independence.

This is often not the case!

StandardsStandards

Languages typically have a “standard” formal definition.

Compiler developers can choose to extend the language if they want to.

Using these non-standard extensions can lock you into a particular machine and compiler because no one else recognizes those extensions.Why might a compiler developer do that?

Languages typically have a “standard” formal definition.

Compiler developers can choose to extend the language if they want to.

Using these non-standard extensions can lock you into a particular machine and compiler because no one else recognizes those extensions.Why might a compiler developer do that?

Case studyCase study

JavaDeveloped by SUN with specific goal of

machine independence.Microsoft’s Java implementation violated

standard.Microsoft was told they couldn’t call it

Java.Still, you can’t assume “Java is Java.”Lines are often more blurry with other

languages.Best to usually stick with standard unless there

is a very good reason to deviate!

JavaDeveloped by SUN with specific goal of

machine independence.Microsoft’s Java implementation violated

standard.Microsoft was told they couldn’t call it

Java.Still, you can’t assume “Java is Java.”Lines are often more blurry with other

languages.Best to usually stick with standard unless there

is a very good reason to deviate!

Programming language concepts

Programming language concepts

A program consists of an ordered set of statements expressed (typically) in some high level programming language.

Statement typesDeclarative statementsImperative statementsComments

A program consists of an ordered set of statements expressed (typically) in some high level programming language.

Statement typesDeclarative statementsImperative statementsComments

Declarative statementsDeclarative statements

“define customized terminology that is used later in the program”associates names (variables) with

locations in main memorydeclares the “data type” of each

variabletells computer how to interpret the bits in

memoryWhy is this important?

“define customized terminology that is used later in the program”associates names (variables) with

locations in main memorydeclares the “data type” of each

variabletells computer how to interpret the bits in

memoryWhy is this important?

Data typesData types

Common primitive data typesintegers (int)real (double)character (char)Boolean

Example declarations (notations may differ!)int x, y, amount;double average;char grade;

Common primitive data typesintegers (int)real (double)character (char)Boolean

Example declarations (notations may differ!)int x, y, amount;double average;char grade;

Data structuresData structures

an organization or collection of primitive data types

provides more intuitive ways to manage data

Lists (1 dimensional) or tables (multi-dimensional) arrays Homogeneous (same type) enables working with them as a single unit

Example declarations (notations may differ!) char name[12]; (character string) float scores[120][20];

an organization or collection of primitive data types

provides more intuitive ways to manage data

Lists (1 dimensional) or tables (multi-dimensional) arrays Homogeneous (same type) enables working with them as a single unit

Example declarations (notations may differ!) char name[12]; (character string) float scores[120][20];

Custom data structuresCustom data structures

Example: managing student infoOption 1:

Have one array for each of the following:last name, first name, SSN, email address,

final average, final grade

Problems?changing sort order?

Example: managing student infoOption 1:

Have one array for each of the following:last name, first name, SSN, email address,

final average, final grade

Problems?changing sort order?

Custom data structuresCustom data structures

Example: managing student infoOption 2:

Create a custom student data structure that holds a student’s first and last names, SSN, email address, and final average and grade.

Have a single array of “students”

Example: managing student infoOption 2:

Create a custom student data structure that holds a student’s first and last names, SSN, email address, and final average and grade.

Have a single array of “students”

Custom data structureCustom data structure

We can declare that a “student” data structure looks as follows: (notations may differ!)typedef struct {

char lastName[20], firstName[20];int SSN;char email[40];float average;char grade;

} student;

What does that mean?Is Option 2 better than Option 1? Why or why

not?

We can declare that a “student” data structure looks as follows: (notations may differ!)typedef struct {

char lastName[20], firstName[20];int SSN;char email[40];float average;char grade;

} student;

What does that mean?Is Option 2 better than Option 1? Why or why

not?

Data structuresData structures

Just like with primitive data types, data structures tell the computer how to interpret the bits in the memory locations associated with the variable name!

Just like with primitive data types, data structures tell the computer how to interpret the bits in the memory locations associated with the variable name!

Variables, constants, and literals

Variables, constants, and literals

Values of variables often change during program execution.

Values of constants and literals don’t.

Literals: explicit numbers (3.1415, 17)

Constants: descriptive names for numbers (PI)

Values of variables often change during program execution.

Values of constants and literals don’t.

Literals: explicit numbers (3.1415, 17)

Constants: descriptive names for numbers (PI)

Literals v. constantsLiterals v. constants

Example:Program to compute sales price:

has array of items with priceshas to include sales tax (10 %)

.10

Can use literals everywhereProblems

Readability (what does that .1 represent?)Maintainability (need to change value of sales tax

without changing the price of things costing a dime)Use a constant called SALES_TAX (good practice)

Example:Program to compute sales price:

has array of items with priceshas to include sales tax (10 %)

.10

Can use literals everywhereProblems

Readability (what does that .1 represent?)Maintainability (need to change value of sales tax

without changing the price of things costing a dime)Use a constant called SALES_TAX (good practice)

To do…To do…

Read chapter 6Read chapter 6