Wednesday 31 December 2014

1.0 - Programming Languages Concepts Notes


Programming Languages Concepts

Sometimes to succeed in something, we need to go back to the basics, to re-develop a solid foundation on which everything else can sit on.

1.1 Reasons for studying the concepts of programming languages

The following is a compelling list of potential benefits for studying concepts of programming.

  • Increased capacity to express ideas - Having a better understanding of the concepts of programming languages, will enable a programmer to communicate their thoughts, verbally or in writing.
     
  • Improved background for choosing appropriate languages. When given a choice of programming languages for a new project, many programmers  will continue to use the language with which they are most familiar with, even if its poorly suited to the project. If these programmers  were familiar with a wider range of languages and language contracts, they would be better able to choose the language that includes the features that best address the characteristics of the problem at hand.
  • Increase ability to learn a new languages. Computer programming is still a relatively young discipline and design methodologies, software development tools and programming languages are still in a state of continues evolution. This makes software development an exciting profession, but also means that continues learning is essential. Through understanding of the fundamental concepts of languages, can ease the burden.
    |
  • Better understanding of the significance of implementation.  Helps us understand why programming languages are designed the way they are. Gives us an ability to use a language more intelligently, as it was designed to be.  Helps us understand the choices among programming language constructs and the consequences of making those choices.

1.2 Language Evaluation Criteria

How to evaluate programming language via its readability, writ-ability and reliability.

Readability 

Since maintenance has been recognized as major concept of the software life cycle.
The ease of maintenance is determined in a large part by the readability of code. Readability is an important language evaluation criteria.


The bullet points below describe characteristics that contribute to the readability of a programming language
  • Overall simplicity,  is there a small amount of basic constructs, a small amount of ways to accomplish the same particular operation. Readability problems occur whenever the programs author has learned a different subset from that subset with which the reader is familiar.
  • Orthogonality, Meaning that a relativity small set of primitive constructs can be combined in a relatively small number of ways to build the control and data-structures of the language. further more every possible combination of primitives is legal and meaningful. Enables a large amount of data structures can be defined.
  • Control Statements, A program that can be read top to bottom is much easier than a program that requires the reader to jump from one statement to some nonadjacent statement in order to follow the execution order.  ie. the use of a while loop statement in C, compared to the FORTRAN goto statement.
     
  • Data types and structures, The presence of adequate facilities for defining data types and data structures in a language is another significant aid to readability. For example suppose a numeric type in the language is used for an indicator flag because there is no Boolean type in the language. In such a language, we might have an assignment like 'timeout = 1' whose meaning is unclear vs 'timeout = true' which is clear.

  • Syntax design, ie. not restricting a identifier to six characters. using 'end if' instead of just '}'

Writ-ability

The bullet points below describe the most important characteristics influencing the write-ability of a programming language
  • Simplicity and Orthogonality, If a language has a large number of different constructs, some programmers might not be familiar with all of them. this situation can lead to a misuse of some features and a disuse of others that may be either more elegant or more efficient.

  • Support and Abstraction, is the ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored.

  • Expressivity, Convenient ways of expressing an operation. like i++ (increment a number)

Reliability

 The program is said to be reliable if it performs to its specifications under all conditions.

 The bullet points below describe several language features that have a significant effect on reliability of programs in a given language.
  • Type Checking, simply testing for type errors in a given program, preferable at compile time, as at run-time it can be expensive.

  • Exception Handling, the ability of a program to intercept run-time errors. ie javascipt is bad at this.
  • Aliasing, is having two or more distinct names that can be used to access the same memory cell.  (dangerous feature)
  • Readability & Writ-ability,  the easier a program is to write, the more likely it is correct, also making it more reliable. Programs that are difficult to read are also difficult to write/modify.
  • Cost,  the ultimate cost of training programmers to use language. 
    Effort in writing application.
    Cost of executing code, required add on frameworks, environments.
    cost of maintainability over a lifetime.

 ----------------------


The two primary components of a computer are its internal memory and its processor.

The internal memory is to store programs and data

The processor is a collection of circuits that provides a realization of a set of primitive operations or machine instructions, such as those for arithmetic and logic operations.

The machine language of the computer is a set of instructions.

In absence of other supporting software the machine language is the only language that most computer hardware "understand"

The most practical design choice is to implement hardware with a very low-level language

A language implementation system cannot be the only software on a computer.

An operating system is required supplies higher level primitives then those of a machine language. These primitives provide system resource management, input and output operations, a file management system, text and or program editors and a variety of other commonly needed functions.
 
The operating system and language implementations are laid over the machine language interface of a computer.



Programming languages can be implemented by any of three general methods.

Compilation (compiler implementation)
  • At one extreme, programs can be translated into machine language, which can be executed directly on the computer.
  • Has an advantage of  very fast program execution, once translation process is complete.
  • Most production implementations of languages such as C are by compilers.

Pure-interpretation
  • Opposite end (from compilation) of implementation methods.
  • Programs  are interpreted by another program called an interpreter, with no translation what so ever.
  • The interpreter acts as a simulation of a machine whose fetch-execute cycle deals with high level language program statements rather than machine instructions.
  • This software simulation obviously provides a virtual machine for the language.
  • Advantage is allowing easy implementation of many source level debugging operations, because all run time errors messages can refer to source level units.
  • Disadvantage - runs 10 - 100 times slow than in compiled systems
  • Java script and PHP 
  • Regardless of how many times a statement is executed, it must be decoded every time.


Hybrid Implementation Systems

  • Compromise between compilers and pure interpreters.
  • They translate a high level language program to an intermediate language design to allow easy interpretations.
  • Makes it faster, because source statements are only decoded once
  • A Just In Time (JIT) implementation system initially translates programs to an intermediate language. Then during execution, it compiles intermediate language methods into machine code when they are called. The machine code version is kept for subsequent calls.
  • Used with .NET languages , JAVA
  • Sometimes an implementer may provide both compiled and interpreted implementation for a language. in these cases, the interpreter is used to develop and debug program. Then after a (relatively) bug free state is reached, the programs are compile to increase their execution speed.


Pre-processors
  • A pre-processor is a program that processes a program immediately before the program is compiled. Preprocessor instructions are embedded in programs. Preprocesser instructions are commonly used to specify that the code from another file is to be included. for example.using mylib.cs

    causing the preprocessor to copy the contents of my lib to the top