Huwebes, Hunyo 23, 2011

cos7 chapter 1 notes

Programming Languages

  • Programming languages are languages.
  • Hundreds of programming languages have been designed and implemented on hundreds of computer systems.
  • Most programming languages were implemented on only a small number of systems.
  • A few dozen programming languages have been implemented on most contemporary systems.
  • Almost any program can be written in almost any computer language.

Reasons for Studying Concepts of Programming Languages

  • Increased capacity to express ideas.
  • Improved background for choosing appropriate languages.
  • Increased ability to learn new languages.
  • Better understanding of the significance of implementation.
  • Better use of languages that are already known.
  • Overall advancement of computing.

Programming Domains

Scientific Application

FORTRAN, one of the first high level languages, was designed for scientific work, and is still the most efficient language for scientific and engineering applications.

Business Application

COBOL, one of the first high level languages, was designed for business use, and is still widely used for business applications.

Artificial intelligence

Systems Programming

Web Software

Language Evaluation Category

readability

the quality of written language that makes it easy to read and understand.

  • COBOL programs are typically very readable: e.g.,

MULTIPLY UNIT-COST BY QUANTITY GIVING TOTAL-COST

  • APL programs are typically very unreadable: e.g.,

(?R?R?.×R)/R?1??R

(This expression, from Wikipedia, gives all the prime numbers less than R.

  • The C language is quite flexible; it can be used to write readable programs, e.g.,

· int main (void) {

· printf ("Hello, world!");

· return EXIT_SUCCESS;

· }

or unreadable programs, e.g.,

main(v,c)char**c;{for(v[c++]="Hello, world!\n)";

(!!c)[*c]&&(v--||--c&&execlp(*c,*c,c[!!c]+!!c,!c));

**c=!c)write(!!*c,*c,!!**c);}

(Both programs do the same thing - display the message "Hello, world!".)

writability

the quality of written language that makes it easy to express ideas.

reliability

An attribute of any system that consistently produces the same results, preferably meeting or exceeding its specifications.

Reliability can relate to how the language handles errors: for example, if an array is indexed out of bounds (i.e., the array contains 10 items, and item 20 is referenced),

  • C will access whatever happens to be at the corresponding location in memory - sometimes just using garbage data, and sometimes crashing the program.
  • Perl will either use NULL as the value, or extend the array.
  • Java will throw an Out Of Bounds exception.

Java is more reliable, but less efficient, than C.

COST

Influences on Language Design

1.Computer architecture

http://www.comsci.us/languages/images/vonneumann.gif

2. Program Methodologies

Language Categories

imperative language

A programming language which expresses the steps to solve a problem.

functional programming

A programming paradigm which models a computational problem as a collection of mathematical functions, each with an input (domain) and an result (range).

Tucker and Noonan, Programming Languages

logic programming

A programming paradigm which models a problem by declaring what outcome the program should accomplish, rather than how it should be accomplished.

Tucker and Noonan, Programming Languages

object-oriented programming

A style of programming that defines data as objects with attributes and methods that are applied to those objects, and which can be inherited by other objects.

  • The most common programming languages, C, Java, Pascal, FORTRAN, COBOL, PHP, Perl, etc., are all imperative languages.
  • Lisp and its dialects, such as Common Lisp and Scheme, are the most common functional languages.
  • Prolog is the most common logic programming language.

Language Design Trade-offs

Implementation Methods

Compilation

token

An atomic symbol of the source program.

compiler

A translator from a high level language to a low level language.

linker

A program which combines two or more object modules into a single object module or into an executable file.

http://www.comsci.us/languages/images/compiler.gif

http://www.comsci.us/languages/images/linker.gif

Pure interpretation

interpreter

A program expressed in one language which executes programs expressed in another language.

http://www.comsci.us/languages/images/interpreter.gif

http://www.comsci.us/languages/images/hybrid2.gif

http://www.comsci.us/languages/images/emulator.gif

Java uses this model; a program is first compiled to a disk file with the javac compiler, and then can be executed by the Java Virtual Machine (JVM emulator.

preprocessor

A language processor that is used to translate and perform other types of manipulations of a program before it is compiled or assembled.

Prof. Croker's Glossary of Object-Oriented Terms

http://www.comsci.us/languages/images/preprocessor.gif

  • A preprocessor is strictly a textual processor, incorporating text from another file, replacing textual elements with new text, or deleting passages of text.
  • C and C++ depend heavily on a preprocessor; almost all C and C++ programs make use of preprocessor statements.
  • The PL/I language also has a preprocessor.

Programming Environments

Three programming environments are in use today:

  1. The command line environment, which typically involves creating a source code file using a text editor, followed by a compiler and a linker invoked from the command console. In many cases, the compiler and linker are invoked together.
  2. An Integrated Design Environment (IDE), which combines an editor, a compiler, and linker into a single application in which a program can be written, compiled, linked, and run. A debugger is usually included.
  3. A Visual Design Environment, which extends an IDE so that GUI components can be incorporated graphically with a mouse. Blocks of code are generated automatically by the visual environment as widgets are manipulated with the mouse.

Walang komento:

Mag-post ng isang Komento