Jinbo Lin
CSC 415: Programming Languages
Dr. Lyle
October 23, 2014
I. The History of Pascal
Pascal is a programming language that grew out from ALGOL. After the failing of ALGOL, several computer scientist still worked on extending ALGOL. Dr. Niklaus Wirth, a member of original group of designing ALGOL, tried to develop a language suitable for teaching programming as a systematic discipline. In 1971, he published Pascal. Later, Dr. Ken Bowles in University of California at San Diego (UCSD) adapt the Pascal compiler to the most popular microcomputer of the day - Apple II, hence, Pascal was widely accepted by Universities.
By the early 1980's, the U.S. Educational Testing Service decided to add a computer science exam to its AP exam in high school, and it chose the Pascal. Therefore, both secondary-school students and college students began to learn Pascal. Pascal became the most popular language as teaching language for more than ten years, however, since Pascal is a teaching language, when a new language became more suitable for teaching than Pascal, Pascal would be forgotten. As the technology growing, C++ replace Pascal became the official language of AP exam in 1999, then Java replaced C++ right after that, Pascal was no longer popular (History of Pascal).
II. Overview of Pascal
Names, Binding, and Scopes
Like other early programming languages, Pascal is not case sensitive. Letters and digits are the only characters permitted for creating an identifier, some compilers also allow the underline character “_” in names. Different types of compiler has its own rules on the length of identifier name, some systems require a fixed length for names while most compiler do not, programmer need to check his or her own compiler. To make this problem even worse, some compiler like standard Pascal allow programmer to name a variable long enough that make sense to himself or herself, but the compiler only recognized first eight characters (Behforooz).
Pascal use static type binding, which means that programmer should explicitly declare the variable type before the body of the program. In Pascal, there is a block call “var” between the head and body of the program, which is used to explicitly declare all the variables will be used in this program. Also, all ALGOL based language are static scoping, which includes Pascal.
Data Type
The reason why Pascal was the best teaching language at the time is because of its data type. There are three categories of data types in Pascal, they are simple, structured and pointer. Simple data types includes integer, real, character, boolean and user-defined type. Structured data types are array, record, file and set.
Pascal has many ways to define those data types, and each type may vary on the range and the memory size. For example, there are ten ways to declare integer: byte, shortint, smallint, word, integer, cardinal, longint, longword, int64 and qword. Among those ten ways, the range of byte is from 0 to 255 and it require 1 byte of memory to store it; the range of smallint is from -32768 to 32767 which require 2 bytes of memory; the range of longint is from -(2^31) to (2^31)-1 which required 4 bytes of memory. The most common way, integer, will be stored as either smallint or longint (Free Pascal Wiki).
While other language struggling whether to use just 1 bit to store a boolean variable, the boolean data type in Pascal use at least 1 byte to store it. To make memory efficiency problem even worse, there exist wordbool data type which use 2 bytes and longbool data type which use 4 bytes, both of them use any nonzero value to stand for true value.
Most language treat string as array of character, programmer can declare a string variable in four ways in Pascal: character array, string variable, short string and null terminated string. Character array is a sequence of zero or more characters enclosed by single quotes (e.g. myString: pack array [1..20] of char). String variable is the variable of String type which defined in Turbo Pascal: a sequence of characters with an optional size specification. This is the most common way of declaring string (e.g. myString: string). Short string is a string type that with the specification of length (e.g. myString: string[20]). Null terminated string is a string type that use a null value at the end of actual string value to indicate the length (e.g. myString: pchar). Furthermore, both string variable and character array use the function “Length” to return the length of the string, Null terminated string use “StrLen” function to return the length, and the length of short string is stored automatically in the zeroth index.
Expressions and Assignment Statements
The rules about expressions and assignment statements in Pascal are similar to most common languages; operator precedency rule is the same as other language, operands are always evaluated from left to right. However, Pascal has strict type checking which makes Pascal became the most popular language for teaching purpose at the time.
Pascal has strong type checking on all objects which means that a variable cannot be converted to other type without explicit conversion. Pascal Compiler will catch every single data type mismatch, but there are two exceptions. First, Pascal allows mixed mode expression within a data type category. For example, the result of a shortint variable plus a longint variable can be assigned to an int64 variable since those three types are all belong to integer. Second, Pascal allows implicit type conversion when integers and reals are both appear in same expression, but downcast is not allowed. This means that the result of an integer plus a real can be assigned to a real variable, but it cannot be assigned to an integer variable.
Control Structure
For selection statements, Pascal has “if then”, “if then else”, and “case” statement. Multiple-selection using “if” (“else if”) in Pascal is handled as multiple nested “if then else” statements. Note that in “if then else” statement, there is no semicolon at the end of the statement in “then” block, in other words, Pascal compiler treat the entire “if then else” statement as one statement that only one semicolon required at the end of “else” block statement. Similar to most other common language, if more than one statements appeared in either “then” block or “else” block, then those statements must be enclosed by “begin” and “end”. Also, the “else” block will automatically match to the closest “if” statement in nested “if” statement.
For iteration statements, Pascal support “for do” loop, “while do” loop, and “repeat until” loop. All three kinds of iteration are similar to other language, but the “for do” loop could only loop through every single element of the given discrete range, and the range must be in integer. All three kinds of iteration support “continue” and “break” to skip this time at given condition or get out of the loop. Also, Pascal has “goto” statement provides an unconditional jump from the goto to a labeled statement in the same function. Label must be declared before “var” block and it must be an unsigned integer from 0 to 9999. The following codes can demonstrate “goto” concept and it will print out the numbers from 1 to 9 without 7.
program example;
label 1;
var
i : integer;
begin
i := 1;
1: repeat
if( i = 7) then
begin
i := i + 1;
goto 1;
end;
writeln('value of i: ', i);
i:= i +1;
until i = 10;
end.
Subprograms
Like Ada, the subprogram in Pascal has two different types, they are procedures and functions; the only difference between those two types are a function directly return a value while a procedure do not. The structure of procedures and functions are similar to a simple Pascal program, but subprograms have to be implemented or at least declared before the body of the main program. One thing that needs to be mentioned is that Pascal does not have a “return” statement, so whenever programmer try to return a value in a function, he or she need to treats the function name as a variable and assign the value to the function name.
The arguments of subprogram in Pascal support both call by reference mode and call by value mode. In Java, every argument is in call by value mode by default which means the original object will not be modified in the subprogram except array. However, even though call by value mode is default setting of subprogram in Pascal, programmer is still allowed to use call by reference mode by using the keyword “var” in front of arguments.
Support of Object-Oriented Programming
Earlier versions of Pascal were pure procedural language, however, Object Pascal was designed and released by Apple Computer as an extension to Pascal to support Object-Oriented Programming (OOP) in 1986. On this extension, two new types were added in order to support OOP: object and class.
Unlike “object” in the basic concept of OOP that object is an instance of a class, the concept of object in Pascal is actually a data type like record. Nevertheless, object contains procedures and functions as part of it, this is what makes object type reach the concept of OOP. Object has constructor and destructor, the visibility of its members can be set as either public, private, or protected; also, an object can be inherited from another object. All of those make object looks like a class in other common OOP languages.
type object-identifier = object
private
field1 : field-type;
field2 : field-type;
...
public
procedure proc1;
function f1(): function-type;
end;
var objectvar : object-identifier; (Object Oriented Pascal)
Even though object exhibit most characteristic of OOP, but it does not take part in polymorphism while class does. So class is more frequently used in object-oriented behavior program. Class is defined in the way that very similar to object except “type class-identifier = class”, however, the main difference between these two types is that the instantiation of a class is creating a pointer to the class while the instantiation of an object is create a new object itself. Technically, the class is allocated on the heap and the object is allocated on the stack.
Concurrency
Concurrent Pascal, also known as Pascal-FC, was designed by Brinch Hanson for concurrent computing. “It supports a wide range of concurrency primitives including semaphores, monitors with condition variables, synchronous message passing using channels (as in occam and CSP), remote invocation (as used in the Ada rendezvous), protected resources (as used in Ada 95 protected objects) and requeue.”(Pascal FC)
Several constructs were removed from Concurrent Pascal for security: records, goto statement and labels, procedures as parameter, packed arrays, pointer types and file types. Those constructs are removed in order to combine compile time checks and minimize the runtime checking in the threaded-code interpreter. Hence, it is possible to make sure that a program cannot damage itself or another program by addressing outside its allotted space.
Exception Handling
The “try-except” statement and “try-finally” statement carry everything about exception handling in Pascal. “Try-except” statement work the same ways as other languages, but the “try-finally” statement is a little bit different from other languages. In Pascal, when an exception is raised in “try” block, then compiler will skip the rest of statements in “try” block then execute statements in finally block which ignore the exception. “Try-except” statement and “try-finally” statement can be nested, but unlike Java, a “try” block must be followed by either an “except” block or a “finally” block exclusively.
III. Evaluation
Readability
Pascal was designed as a teaching language, so it supposed to have high readability, and the language do achieve the goal. Pascal code are very structured: variables, subprograms, user-defined types and so on has to be declared in their own block before the main program begin. Hence the reader do not need to worry about having trouble to find the place where a specific variable or function is declared, which will improve the readability a lot.
Pascal has a relatively small amount of constructs which increase the simplicity of the language; there is only one way to accomplish most operation in Pascal which makes the language lack of multiplicity hence the simplicity is increased. However, the support on operator overloading brought down the overall simplicity. We can conclude that Pascal is decent in overall simplicity which increase the readability.
Even though there are fair amount of primitive constructs, but most combination are legal which makes Pascal has high orthogonality hence brought up the readability. Plus Unlike C based language as symbolic language, English words are used more frequently than symbols in Pascal which makes reader easy to understand. But the issue on data type may decrease the readability since there exist so many ways to define a string. Overall, Pascal has high readability.
Writability
In case sensitive language like Java, one big challenge face by programmer is that programmer may remember the name of the functions in library but often misspell it due to the combination of uppercase letter and lowercase letter. However, Pascal is case insensitive language which means that programmer do not need to worry about misspell the combination but just need to remember the meaningful name. This profoundly improve the writability of the language.
However, we should evaluate the writability of this language in many ways. As we mentioned above, Pascal code use more English words rather than symbol thus the readability is increased but it also decrease the writability. In other ways, Pascal support abstract data type (array, record, object, class, etc.) which improve the writability. Pascal support operator overloading which increase the writability, too. Also, even though Pascal has a “use” block that allow programmer to use external libraries but the relatively small size of libraries decrease the writability. After all, Pascal still has decent writability.
Reliability
Pascal is a very restricted language, its restrictions were intended to encourage the development of reliable programs by enforcing a disciplined structure. Pascal is a strongly typed language, the compiler would check every data type mismatch at the compile time. Even though the arithmetic of integers and reals are allowed, but the compiler will catch that as warning. Type checking still improve the reliability of Pascal.
In one way, Pascal support exception handling well so this increase the reliability. But the Pascal also support aliasing since Pascal support call by reference mode in parameter which means that the reliability is decreased. And, Pascal has rich data type set which make it more reliable. Overall, Pascal is a reliable language.
Cost
When we discuss the cost, we should consider not only the cost of software and hardware, but also the total cost of function of many characteristics of this language. Since the two major Pascal IDE, Delphi and Lazarus, are free to download online and they can run on most major operating systems like Windows, Linux and Mac, the cost of programming in Pascal is free. So the remaining topic is the total cost of many of its characteristics of Pascal.
Pascal is developed for teaching programming as a systematic discipline and to develop reliable and efficient programs, and this language do accomplish the goal of developer. Pascal is a structured language, the code is separated in different blocks strictly to improve the readability. Pascal is also a strong typed language so that it is suitable for teaching new programmers good programming practices, and strong typing also makes Pascal becomes a reliable language. Pascal has rich data types, it support user-defined types, and it also support Object Oriented Programming by object and class data types, all of these improve the writability of Pascal. It’s seems like Pascal is a perfect language that has decent readability, writability and reliability, but every programming languages has design flaw, especially for those early languages.
Pascal is designed as a teaching language, in other words, it is design for beginner programmer to learn most concept of computer programming. Even though Pascal got expanded after so many versions, but it still cannot get rid of this framing. Pascal has decent writability is because it is easy for programmer to write the code, not because of its flexibility and power. Pascal is not flexible and it is also not as powerful as other languages. Obviously the strong typing makes Pascal lack of flexibility, and one evidence of Pascal is not powerful is that the external libraries of Pascal is relatively small, some programmer even treat Pascal as “toy language”.
Bibliography
TaoYue.com. History of Pascal. Jan. 6th, 2011. Web. Sept. 3rd, 2014.
Behforooz, Ali, and Martin O. Holoien. Problem Solving and Structured Programming with Pascal. Monterey, CA: Brooks/Cole Pub., 1986. P.232. Print.
Yue, Tao. "Variables and Data Types." - Free Pascal Wiki. Web. 11 Sept. 2014. .
"Pascal-FC." Pascal-FC. Web. 13 Oct. 2014. .
"Tutorials Point"Object Oriented Pascal. Web. 13 Oct. 2014.
Share with your friends: |