History: The Turbo Pascal Programming Language
History: The Turbo Pascal Programming Language
Turbo Pascal is a robust language, rich in data types and procedures. This makes it a very good teaching tool, especially for those who are just beginning in the world of programming. It makes them appreciate why things are done a certain way in other languages History The field of Computer Science has not always been as it is today. Once the list of available computer programming languages was small. Tools did not exist as they do today, tools that can be used to write simple programs. Tools that require very little knowledge of the language they are based on. Before this, programmers needed to write the code. If the programmer did not completely understand the programming language or what they were programming, errors would occur. Sometimes those errors could prove to be very costly, both in terms of finding the error in the code, and in terms of output the code generated. It was imperative that programmers completely understand the language they were programming in. This is where Pascal and Turbo Pascal first came into play. The Turbo Pascal programming language was developed as an extension to the Pascal programming language. The Turbo Pascal compiler was written by Borland International and was intended to make the Pascal language an even better language. At the time, Pascal was a very popular language (Learn Pascal). The Pascal programming language came from the ALGOL programming language. It was named after the 17th century mathematician, Blaise Pascal (Learn Pascal). Mr. Pascal is credited with creating the first mechanical digital computer around the year 1640 (Computer History). The Pascal programming language began its development in the 1960s, developed mainly by Dr. Niklaus Wirth. The first programming outline of the language was published in 1971 (Learn Pascal). In this report, Dr. Wirth described his reasons for developing the language, highlighted by two main reasons: The development of the language Pascal is based on two principal aims. The first is to make available a language suitable to teach programming as a systematic discipline based on certain fundamental concepts clearing and naturally reflected by the language. The second is to develop implementations of this language which are both reliable and efficient on presently available computers. (Leestma 15). Dr. Wirth wanted a programming language that could teach people how to program effectively and efficiently with the computer systems of the 1970s. The Pascal language was very strongly typed, allowing its programmers to create their own custom data types. This was a key reason why Pascal was used as a teaching tool. It allowed professors to illustrate to students the importance of programming structure and paying attention to data types. Because of the strong type casting, the language was very readable to its end-users and ideal for beginning programmers (Learn Pascal). By the time the 1980s came about, Pascal was a very popular programming language. One of the main reasons for its success was because of its use in college placement tests. The Educational Testing Service, the company that creates and administers college placement exams to high school students, used Pascal as its language of choice on the exams. This caused many students to adopt Pascal as either a first language or a favorite language. Pascal remained the language of choice for the ETS until 1999 when it was replaced by C++ (Learn Pascal). In 1983 Borland released its version of the Pascal programming language named Turbo Pascal. The Turbo Pascal language was developed mainly by Anders Hejlsberg (Turbo Pascal). The main advantage the Turbo Pascal offered over the ANSI standard Pascal was speed (Learn Pascal). The prefix Turbo came about because of the added speed Turbo Pascal gave the end user upon compilation (Turbo Pascal). Turbo Pascal made very little changes to ANSI Pascal, but the modifications that were made drastically improved the compile speed. Turbo Pascal was able to read and compile source code at thousands of lines per minute, a harsh contrast to other compilers of that era (Learn Pascal).
Turbo Pascal brought new life into the realm of computer programming (Learn Pascal). It featured an Integrated Development Environment (IDE) which was a relatively new idea in the programming market at the time (Turbo Pascal). An IDE is piece of computer software that allows the programmer to perform multiple tasks on their source code from within the same console. An IDE usually consists of a text-editor for writing the source code, a compiler or an interpreter to build the machine readable code from the source code, a way to execute the code, and usually some type of debugger (Integrated Development Enviroment). The cost also was a reason for Turbo Pascal's popularity. At the time of its introduction, Turbo Pascal could be bought for just under $50 in the US (Turbo Pascal). The price, coupled with the extremely powerful and useful IDE, helped make Turbo Pascal the standard programming language in the 1980s. Computer magazines and other periodicals usually released their sample source code in Turbo Pascal (Learn Pascal). In the late 1980s Borland released Turbo Pascal version 5. This was a major step in the development of Turbo Pascal as it included Object Oriented Programming instructions (Turbo Pascal). Object Oriented Programming gave languages the ability to recognize and handle programming objects. Objects can be thought of as things in a program's source code. These things are separate but can be brought together to perform a particular operation (Object-oriented). Think of objects as Republicans and Democrats in Congress. Each party has their own views on particular agendas or ideas. They usually discuss these among themselves. However, in order to get something accomplished, the two sides must come together and pass laws. This is how objects work, coming together to perform a task and create a program. Object Oriented Programming generally makes a program easier to write, read, and maintain (Object-oriented). Turbo Pascal continued to make changes in the programming world. By version 7.0 it was able to eclipse the MSDOS DOS Protected Mode Interface (DPMI) and allowed for memory usage over the DOS limit of 640k. When Windows 3.0 was released, Borland released Turbo Pascal for Windows allowing programmers to develop applications for Windows (Learn Pascal). But Turbo Pascal's downfall had already begun. As computers became more and more user friendly and computer operating systems became more and more important, so did the languages that
they were build around. Unix-like operating systems began to become popular and in 1991 Linus Torvalds released his free Unix-like operating system called Linux. Linux became very popular among young computer scientists both because of its cost and the availability of its source code (Linux). Unix and its brother Linux were both written from the C language. Because students were learning Turbo Pascal to gain acceptance to colleges and then moving on to understanding the UNIX operating systems, the need for Turbo Pascal slowly declined. Students saw no reason to learn both languages when C would do everything that was needed. To make matters worse, Microsoft soon released the Windows API allowing programmers to access parts of the Windows code with their programs. The Windows API was released in C, and the use for Turbo Pascal took a huge hit (Learn Pascal). Later in the 1990s, Borland dropped support for Turbo Pascal and began touting its new language, Delphi. Delphi is based on many of the features of Turbo Pascal. It is a Rapid Application Development environment, which allows programmers to easily create programs in less time than to write each line of the source code. One of the key components of the Delphi language is its speed, something it retained from Turbo Pascal (Learn Pascal). Despite the fact that Turbo Pascal is no longer considered a popular language by programming professionals and programming enthusiasts, it is still a very useful language. The foundation that it was written on, making it a useful teaching language, can still hold true today. Any beginning programmer should consider looking at Turbo Pascal, or one of its derivatives such as ADA, as a useful starting point in their understanding of programming languages. Data Types Turbo Pascal, like Pascal, is based around four main data types. These include integer, real, char, and Boolean (Leestma 66). The integer and real data types refer to numeric values. Integer refer to counting numbers that do not have a decimal. They range from -32768 to 32767. Real data types are more commonly referred to as floats in other programming languages. Real numbers represent a much larger range of numbers and can include numbers with decimal points. In Pascal real data types range from 3.4x10-38 to 3.4x1038. Real data types can be entered either as decimal numbers or in scientific notation (Pascal Tutorial). If scientific notation is used, the symbol 'E' can be used to represent the separation of the mantissa or
whole number part and the exponent or power that 10 is raised to. The char type in Pascal is used to store a single character. The character must be enclosed in single quotation marks when it is assigned to a variable of type char. Only one character may be held in a variable of type char (Pascal Tutorial). The Boolean type is used to represent something as either being TRUE or FALSE. Boolean data types have usefulness if you are dealing with logical circuits or any type of logical problem (Leestma 66). In addition to these data types, Turbo Pascal also includes eight additional data types. These include shortint, longint, byte, word, single, double, extended, and comp (Leestma 66). A shortint is a smaller integer that handles values between -128 and 127. A longint is an larger integer that can handle values ranging from -2147483648 to 2147483647. A byte is an integer that holds values from 0 to 255. A word is similar to a byte except it goes from 0 to 65535. Single, doubles, extended, and comp are extensions to the real data type. Single data types range from 1.5 x 10-45 to 3.4 x 1038. Double data types refer to real numbers between 5.0 x 10-324 and 1.7 x 10308. Extended data types go even further ranging from 3.4 x 10-4932 to 1.1 x 104932. And finally, comp data types contain values between .5 x 10-45 and 1.1 x 1038 (Turbo Pascal Tutorial). Turbo Pascal also introduced the string data type as an extension to the char data type (Leestma 66). The way Turbo Pascal deals with strings is just as an array of characters. A string type can hold a maximium of 255 characters. A limit can be defined when the string is declared by using string[L], where L is the maximium number of characters that can exist in the string. If the limit is left blank, then a maximium of 255 characters is allotted for the string. Strings in Turbo Pascal use a unique method of determining their length. The 0th position of the string, which is an array of characters, holds the character code for the number of elements in the string (Leestma 509510). For example a string that is 13 characters long would store a carriage return as the 0th element in the string. This is because a carriage return is represented by the ASCII code 13. This allows the string to look up its length when outputting the string and only displaying the first n elements in the character array. The first character in a string is found in the 1st position of the character array. Likewise, each individual character in the string can be accessed like any other array. However, if changes are made to the
array after the nth character without changing the 0th element of the string, then the string will still think it is n characters long (Leestma 510-511). Another useful data type in Turbo Pascal is an array. An array differs from other data types in that it is not really a specific data type. Instead, it is an in-line list of other specific data types. Arrays are denoted by first declaring an array type, known as an array declaration. Since this is considered defining a new type, this must be done under the TYPE heading. The array declaration looks similar to: arraytype OF <data type> = ARRAY[<range>]
Where arraytype can be any valid identifier, range is specified to be any type of range and data type is a valid data type. In Turbo Pascal, range can be denoted by using the '..' keyword with the lower and upper bounds on the left and right side of it respectively (Leestma 448). Arrays can be extremely useful when using any type of list. Expressions/Assignment Statements In Turbo Pascal to make an assignment, a programmer must use the assignment statement. The assignment statement looks like :=. On the left side of the assignment statement is a variable, which is represented by any valid Turbo Pascal identifier. On the right side of the assignment statement is an expression. An expression can consist of either a constant, another variable, or a formula which can be a combination of the other two (Leestma 81). Variables in Turbo Pascal are sometimes referred to as identifiers. This is because of their true nature as an identifying element. There is a strict set of rules that an identifier must hold true to. An identifier can be of any length, however, only the first 63 characters will be recognized. An identifier can contain only letter, numbers, and underscores. All other characters are invalid when naming an identifier. It must also begin with either a letter or an underscore and cannot begin with a number (Turbo Pascal Tutorial). Expressions in Turbo Pascal can be a constant, or a variable, or a combination of the two. If you have any combination, you have what is considered a formula. Turbo Pascal supports six main arithmetic operations. They are addition, subtraction, multiplication, real division, integer division, and modulus. The addition, subtraction, and multiplication work just like regular
mathematics and are denoted by their familiar symbols of +, -, and * respectively. Real division works very much the same way as regular division does. It will produce a real or floating point number as a result of its operation and is represented by the / symbol. Integer division works in much the same way as real division, except it only returns the integer part of the division. For example, 8 divided by 5 in real division is 1.6. However, if this operation is performed with integer division the resulting answer would be 1. Integer division is symbolized by the keyword DIV. The modulus operation returns the remainder of the two numbers in integer division. In the previous example, the modulus of 8 and 5 would be 3. The modulus operation is denoted by the keyword MOD (Leestma 76). As in normal mathematical arithmetic, the order of operation is always a concern. In Turbo Pascal multiplication, real division, integer division, and modulus have top priority followed by addition and subtraction. Each operation is performed based on its priority level and ordinal position of left to right (Leestma 77). So a left most multiplication would have priority over a right most real division. Other arithmetic functions that are built into Turbo Pascal include the transcendental functions of sin, cos, tan, exponential and natural log. The square root function is represented by sqrt(x), where x is either an integer or a real number. The round function, which rounds a real number to its nearest integer value, is represented by round(x). And a truncate function is represented by trunc(x), which drops the fractional part of a real number and returns an integer number (Leestma 79). Assignments in Turbo Pascal must follow some rules. An expression must follow on the right-hand side of an assignment symbol. You cannot perform multiple assignments on the same line. It is legal for a programmer to assign an integer value to a variable that is of type real. This can be done without any typecasting and is one of the few instances that Turbo Pascal allows for mixed-mode assignment. An integer variable cannot hold a real value, however. It is also important to note that the assignment symbol will be used to replace the value of the left-hand variable. If the variable you are assigning the result of an expression to already has a value, then its value will be overwritten after the expression has been evaluated. It is also possible to assign a variable new content even if the expression
contains the said variable. Because the right-hand side is evaluated first, the value of the variable has the operation performed on it and then is replaced with the result of the overall expression. One of the more common instances of this being performed is while incrementing a counter. Normally the counter would be incremented by using counter := counter + 1; The current value of counter is increased by one and assigned to counter. The contents of a variable is left undefined, until it is explicitly assigned a value (Leestma 83-86). You cannot perform any arithmetic operations on a variable, unless it has been assigned a value. Another method of incrementing is by using step functions. Turbo Pascal includes two step functions that are aptly named inc and dec. Both functions take two arguments, a variable and a step. The inc function takes the value of the variable and increments it by the value stored in the step argument. The variable must be an integer variable. So using the inc function is just like assigning the variable the result of itself added to step. The dec function works in the same way, except instead of adding or incrementing, it decrements a variable using subtraction. If the step argument is not present, then a value of 1 is assumed and the variable is incremented or decremented by 1 (Leestma 85-86). A Boolean function can be performed on a Boolean data type. The one Boolean function that is available in Turbo Pascal is the function odd(x). This function returns a true or a false depending on what the value of the integer x is. If the value held in the variable x is odd, then the function returns true. If the value is even, the function returns false. Other Boolean operations that can be performed in Turbo Pascal, include less than, greater than, equal to, less than or equal to, greater than or equal to, and not equal to, represented by the symbols <, >, =, <=, >=, <> respectively (Leestma 124-125). These are commonly used in conditional statements to determine how one variable relates to another variable. Each operation returns either a true or false depending on how the left-handed side relates to the right-handed side. Structure In order to develop a program in Turbo Pascal, one must follow certain design parameters that refer to the structure of a Turbo Pascal program. This structure is the basis of how Turbo Pascal programs are written and read. In Turbo Pascal there are three distinct headings that must be
defined to properly identify a Turbo Pascal program. They are the Program heading, Declaration heading, and Statement heading (Leestma 103). The program heading is a relatively simple heading and is actually optional in Turbo Pascal. The program heading consists of the program name, and any other files that the program might use. The program heading should start with a heading of the form: PROGRAM name; Commonly, the name refers to the filename that you are working on, minus the file extension, but this does not have to be the case. After the PROGRAM statement it is customary to provide some form of documentation about the program (Leestma 103). This is usually done with a comments section. Comments in Turbo Pascal can be denoted by enclosing text in either { }'s or (* *)'s (Leestma 40). Comments can be placed throughout the program, but a short description is nice to have at the top of the program. Next in the program heading is the optional USES clause (Leestma 103). This is where you would list other Turbo Pascal files that the program might use, such as a graphics library (Leestma 67). The declaration heading is a much more robust heading. It consists of five sub-headings. Each sub-heading is optional, and most of the time all five are not used. They are the label section, the constant section, the type section, the variable section, and the subprogram section (Leestma 104). The label section is used to predefine labels or parts of your program that execution can jump to. In the program, execution is usually jumped to one of these labels by using a GOTO statement such as GOTO <label>. Labels are declared in the declaration heading by first declaring the label heading, simply the word LABEL followed by on the next line, a list of the labels. Valid labels include any positive integer or any valid identifier. Later in the program a line can begin with label: where label is one of the predefined labels (Leesta 899-900). The constant sub-heading is used to declare variables that are constant. Constant variables are variables that do not change inside the program (Leestma 67). The constant subheading is denoted by declaring the heading with the word CONST followed by a new line. On the
next line you can define all of your constants by using the syntax: identifier = constant; where identifier is a valid Turbo Pascal identifier that you want the constant to be identified as. The term constant refers to the value you want the identifier to hold. Under the CONST heading you can have as many constants as you desire, but each needs to be on its own line (Leestma 104). The type sub-heading is where new data types are declared. It is also possible to rename a type and call it something else. The type subheading is defined by the keyword TYPE, followed by a new-line. On each subsequent line, types are declared by the syntax name = type, where name is any valid Turbo Pascal identifier and type is any defined type in Turbo Pascal. Another use for declaring a type definition is to create an enumerated type. This is done in the TYPE subheading, and the syntax is much the same as declaring another type, except type is a list of strings or characters, separated by commas and enclosed in parenthesis (Leestma 418-420). An enumerated type is sometimes easier to read later in the program, since a variable declared as this type can only hold the values listed in the type's declaration. Another data entity that can be declared in the TYPE sub-heading, is a sub range. The syntax is again similar to that of other data entities, except type is defined as firstvalue..last-value. The first-value and lastvalue represent the beginning and end of the sub range respectively. The one restraint on the firstvalue and last-value is that each must be a member of an ordinal type (Leestma 431). An ordinal type is any type whose members have value both behind them and in front of them, except for the first and last value. Integers are an example of ordinal values, as each integer, aside from the smallest and largest, has both a number before itself and after itself. Real or decimal numbers do not have this characteristic and are not consider ordinal types (Leestma 416). The variable sub-heading is defined in the declaration heading as the section to declare variables and default values if desired. The variable sub-heading is denoted by the keyword VAR followed by a new-line. Each line defines a new variable of a new type, of the form variable : type (Leestma 104). Where variable is any valid Turbo Pascal identifier and type is any valid Turbo Pascal type or a type defined under the TYPE sub-heading. The
identifier variable can also be a list of valid Turbo Pascal identifiers separated by commas and will all be declared as the specified type (Leestma 73). Turbo Pascal supports subprograms of both procedures and functions (Leestma 174). They are usually defined after the VAR subheading in the declaration part of a program (Leestma 104). There is no keyword heading denoting the beginning of the subprogram heading in the declaration section, instead each subprogram is denoted by the keyword PROCEDURE or FUNCTION depending on its type. The statement heading is where the bulk of the program begins. The statement section is denoted by the keywords BEGIN and END. Enclosed between the BEGIN and END keywords are statements that are executed one at a time. Each statement is denoted to end with a semicolon. These statements contain the layout and overall program algorithm, needed to perform the program's task (Leestma 105). A statement can be any expression, procedure call, or control structure used to adequately perform a particular task. Control Structures Turbo Pascal has three methods of control structures. Control structures are statements that control the flow of a program and the way the program runs (Introduction to Pascal). In Turbo Pascal, these control structures can be categorized as either sequential, selective, or repetitive (Leestma 122). Each has its own characteristics and use. Sequential structure or statement structure is probably the most common structure element. As the name suggests, each statement is executed one after the other in order of occurrence. Sequential structure is denoted by the keywords BEGIN and END. Enclosed in these keywords are statements separated by semicolons, each executed one after the other (Leestma 122-123). You may notice that this is similar to the structure of the statement heading of a Turbo Pascal program. This is because Turbo Pascal itself is a sequential programming language, because it reads one line at a time. The selective structure is a control structure that allows the program to skip to different alternative tasks, based on a condition. The common method of performing this is with an if statement (Leestma 135). There are several different variants of the if statement, including IF-THEN, IF-THEN-ELSE, and IF-THEN-
ELSE IF-THEN-ELSE. Each IF, THEN, ELSE, and ELSE IF are keywords in Turbo Pascal (Leestma 136, 138, 145). The syntax for an IFTHEN-ELSE IF-THEN-ELSE statement is as follows (Leestma 145): IF conditional THEN statements ELSE IF conditional THEN statements ELSE statements The conditional element usually represents a Boolean expression which represents a true or false. If the conditional is true, then the statements underneath it are executed. If more than one statement is executed based on a conditional, then those statements need to be enclosed in a statement structure, with a BEGIN and END (Leestma 136137). There can be any number of ELSE IFTHEN sections. Once the criteria for the conditional has been met, either in the IF, ELSE IF, or ELSE section, execution of the program jumps to the end of the overall statement, after the ELSE statements (Leestma 146-147). The syntax for IF-THEN or IF-THEN-ELSE is similar to that of the above. The only keyword that is required in an IF statement is the keywords IF and THEN, for a single condition. If only one statement is being executed based on the conditional, then the statement structure is not required. The Turbo Pascal compiler will recognize that there is only one statement and execution will jump to the end as appropriate (Leestma 136-138). Another statement that can be used for selective purposes is the CASE statement. The case statement works in much the same way as a IF-THEN-ELSE IF-THEN statement. The syntax for a case statement is as follows: CASE selector OF label_list : statement ELSE statement END The selector in a case statement is usually a variable that will hold a value. If the value of the selector matches a value in the label_list, then the corresponding statement after the colon is executed. The label_list can be a list of possible values separated by commas, so if the selector matches any of those values, then the same
statement would be executed. Each possible value that needs to performs a distinct statement must be on a separate line after the CASE statement. If no value in any of the label_lists match that of the selector, then execution falls to the ELSE part, and the statement beneath it will be executed. The ELSE statement is not required, and if omitted and no value in the label_lists matches the selector, then execution drops to the next line following the END statement. The END statement is required to denote the end of the CASE statement (Leestma 328-330). The repetitive structure is sometimes referred to as the iterative structure or more commonly as a loop structure. Turbo Pascal supports three repetitive control structures -- the WHILE statement, the FOR statement, and the REPEAT-UNTIL statement (Leestma 150). One thing to look for in a loop is a continuous or infinite loop, a loop that never ends. If a program gets stuck in a continuous loop, then it will never end. The WHILE structure is a looping structure that will iterate through a statement or several statements based on a conditional. The syntax of a WHILE statement is as follows: WHILE conditional DO statements The conditional is usually represented by some type of Boolean expression. The statements are executed while the conditional is true. If more than one statement is being executed in the while loop, then those statements need to be enclosed in a statement structure. Usually one of the statements is a controlling element used to control the conditional (Leestma 150-152). If no controlling element is in the statements, then the conditional may always be true and a continuous loop may incur. Turbo Pascal version 7.0 introduced the break statement, which can be used to break out of a loop. This provides a way to prevent an infinite loop (Leestma 934). Another repetitive structure is the FOR loop. In a FOR loop, a statement or set of statements is executed within a specified range or a number of iterations. The syntax for a FOR loop is generally: FOR control := initial_value TO final_value DO statements
The control is a declared variable of any ordinal type. The intial_value and final_value are of the same data type as control. Initially the control is assigned the value of initial_value. With each loop the control variable is incremented by 1, until the value of control is equal to final_value. The statements are any valid Turbo Pascal statements, but if more than one statement is to be executed, then the statements need to enclosed is a statement structure. The control variable cannot be modified within the FOR loop. Another variant of the FOR loop, is similar to the above syntax, except instead of TO, the keyword DOWNTO is used. In this variant the control is assigned the initial value, but the control variable is decremented by 1 with each iteration of the loop (Leestma 335-339). Commonly a FOR loop is used to iterate through an array. Sometimes it is necessary to program a loop that centers around a post-test conditional. A post-test conditional is a loop where the conditional is evaluated at the bottom of the loop. WHILE and FOR loops are both examples of pretest conditionals, where the conditional is evaluated at the head of the loop. To accomplish this in Turbo Pascal, you would use a REPEATUNTIL loop. The REPEAT-UNTIL loop is very similar to the WHILE loop, in that the conditional does not change by the looping structure. Instead, the conditional must be changed within the loop. The syntax for a REPEAT-UNTIL loop is as follows: REPEAT statements UNTIL conditional As with the WHILE loop, the statements can be any valid Turbo Pascal statements and the conditional usually represents a Boolean expression. The loop continues to repeat the statements until the conditional is false. The difference is that the conditional is not evaluated until the statements have been executed at least one time. Unlike a WHILE loop, if more than one statement is required, they are each separated by semi-colons but do not have to be enclosed in a statement structure (Leestma 341-343). Subprograms Sometimes it is necessary or easier to split a program up into smaller algorithms or tasks. Turbo Pascal allows you split a program into
smaller sections, called subprograms. The reason for using a subprogram is to localize a problem. This allows the programmer to easily debug the program if an error occurs, since the error would be local to a specific subprogram. Subprograms are declared and defined within the subprogram sub-heading of the declaration heading in a Turbo Pascal program. Turbo Pascal supports two different types of subprograms, each with their own characteristics, called procedures and functions (Leestma 174). A procedure in Turbo Pascal can be looked at as just a smaller program. A procedure contains all the characteristics of a program but usually performs a specific task (Leestma 175). What defines a specific task is left up to the programmer's discretion. The syntax of a procedure looks like: PROCEDURE name (parameters); The keyword PROCEDURE is used to signify the beginning of a procedure subprogram. The name can be any valid Turbo Pascal identifier and is used to reference the procedure later in the main program. The parameters is an optional list of parameter names which can be any valid Turbo Pascal identifier and its data type, each separated by a semicolon. The line ends with a semicolon signifying the end of the declaration (Leestma 184). If parameters are specified then they must follow a specific syntax. The syntax of parameters in the parameter list is as follows: parameter data_type : parameter_type
will contain the value that the same parameter value calculated in the subprogram. If that is the case, you will need to specify that parameter as a variable, which is accomplished by using the keyword VAR as the parameter_type. VAR is the only keyword that parameter_type will accept. If the parameter_type is empty, then the parameter is implied to be a value parameter. This means the parameter only brings values to the procedure and does not take carry a value back to the calling program or subprogram (Leestma 190193). After the procedure name declaration, the procedure follows the same general outline of a program. The name declaration is similar to the program heading which is called the procedure heading. Following the procedure heading is the procedure declaration heading, which contains the exact same elements and sub-headings as the program sub-heading. After the declaration heading is the procedure statement heading, where the actual tasks and algorithms are performed for that specific procedure. Again this follows the same syntax as that of the program statement heading (Leestma 175). In the program the procedure can be referenced by simply calling the procedure's name followed by a semicolon. If a parameter list is specified in the subprogram heading, then the reference must contain a matching number of parameters and of valid types as specified in the procedure heading. When the program reads the procedure name, execution of the program jumps to that specified procedure, and after the procedure is executed, the program returns to the next statement following the procedure call (Leestma 186). The second type of subprogram available in Turbo Pascal is a function (Leestma 175). Functions differ from procedures in that they return a single value directly (Functions and Scope). Just as in programs and procedures, functions follow the same structure with a heading, a declaration section, and a statement section. The syntax for a function heading is: FUNCTION name (parameters) : return_type; The keyword FUNCTION is used to signify that the subprogram is a function and will return a value of type return_type. The parameters is a list of valid Turbo Pascal identifiers and their data type, separated by a semicolon. Parameters follow the syntax of:
The parameter just refers to any valid Turbo Pascal identifier. It can also be a list of parameters separated by commas, but they each have the same parameter_type and data_type. The data_type refers to the accepted data type of the value that the parameter or parameters can contain (Leestma 184). The parameter_type refers to a special meaning in Turbo Pascal. In some procedures you will want a specific parameter to be able to return a value back to the program or subprogram that called it (Leestma 189). Each parameter follows the same order as the parameter list when the procedure is referenced, so that the first variable parameter in the reference refers to the first parameter in the procedure heading. In the program or subprogram that references the procedure, the matching variable in the reference
variable_name : type The variable_name refers to the name of the variable in the parameter list, and signifies how the parameter will be referenced inside the function. Following the function heading is the declaration section and then the statement section (Leestma 218-219). To return a value to the program or subprogram from within the function, you assign the name of the function the value to return. This is done somewhere within the statement section of the function by done using the assignment operator (Leestma 219). The main difference between a function and a procedure is how values are returned. A procedure can return a value or more than one value, but it returns a value by variable in a parameter list (Leestma 191). A function returns a value directly. When a function is called in a program, the value of that call becomes the value that the function returns (Leestma 217-219). This allows the programmer to add some level of recursion in the program, since a function can perform its task depending on the value of another value returned by the same or another function. As a general rule, procedures should be used when none or more than one value is to be returned, and a function should be used when a single value is to be returned (Functions and Scope). Object Oriented Programming With the release of Turbo Pascal version 5.5, Borland introduced Object Oriented Programming to the Turbo Pascal language (Learn Pascal). Turbo Pascal's Object Oriented Programming, or OOP, was a slight derivation of the Apple iteration of Object Pascal (Learn Pascal). OOP was important because it furthered the level at which Turbo Pascal could operate at. By this time other languages were being released and could perform tasks better and faster than Turbo Pascal could. OOP was the next evolutionary step. The main concept behind OOP is the switch from viewing the code as a set of procedures and operations, but instead as a list of objects or things. Objects can be viewed as an advanced data type, but they do more. Objects are part of an even bigger picture known as a class. A class contains all the objects and all the methods that can act upon those objects. A method is similar to a procedure, but it only acts upon objects within the class. Another important defining component of OOP is inheritance, or the ability to
define subclasses that will inherit all of the defining objects and methods in a superclass or parent. These subclasses are sometimes referred to as a child class, with the class it is derived from being called its parent class (Shammas 2-5). In Turbo Pascal, a class or object is defined in the type sub-heading of the declaration heading. It follows a similar syntax as defining a new data-type, but it has a few modifications: class_name=OBJECT(parent_class) fields method_headings END; The name refers to the name of the class and how a variable can be instantiated later in the program. The keyword OBJECT is used to signify that you are defining a class of objects. The parent_class refers to the name of the parent class. This, along with the parenthesis, is not required if you are declaring a new class with no parent class. The fields refers to variables and data types that exist in the class and are defined in much the same way as variables are defined in the variable sub-heading of the declaration heading. The method_headings is where you place headings to procedures or functions that act upon the fields in the class called methods. Notice that these are simply headings and not actual subprograms, although the heading is very similar to the subprogram name declaration. The actual function or procedure will be defined later, but the name must be noted. The keyword END followed by a semicolon signifies the end of the class declaration (Shammas 7-9). Later in the subprogram heading, you can define the methods for the class by starting the declaration: PROCEDURE class_name.method; The class_name refers to the name of the class that contains the object you want to manipulate, and method refers to the name of the method declared in the class that you want to create. The syntax is the same if you want the subprogram to act as a function, simply replace PROCEDURE with FUNCTION. Then you would write the method just like you would any subprogram. One valuable piece of information you have is the ability to access the fields that were defined in the class declaration. You can think of the fields as global variables, as long as you are operating on them within class methods (Shammas 9).
task without repeating the same steps. Inheritance also plays an important part when dealing with classes. A child class has access to anything in the parent's class. Turbo Pascal supports single or linear inheritance or the ability to only inherit from one parent. What this means is that you can define a subclass from a parent class and not have to repeat all the fields and objects in the subclass (Shammas 5). This allows a programmer to perform a more specific task but not necessarily require that much more coding. After all of this has been done, you now have a complete instance of an object. When referencing this object in the main program, it can be looked at more as a thing and not just as a variable, value, or statement. To create an instance of this object, you would declare a variable to be of the stated class_name in the variable subheading of a program. Then in the program source, you can access the specific methods of an object by: variable.method Where variable refers to the variable that you defined as the object type, and method is the method to perform on that instance of the object, followed by any parameter list that may be required. This is called sending a message to the object. The message that is sent tells the object to perform the stated method on the specific variable instance of that class (Shammas 10-11). It is important to note that any method called will only affect the specific variable instance of the object. Each time a variable is declared to be of that object, the fields and methods of that object reset for that specific variable. The inheritance part of a class is usually only noticed in the actual method definition. As stated earlier a subclass inherits all the fields and methods of its parent class. A subclass can also define new fields or methods, or even override methods or fields from the parent class. If this is done, then those methods or fields become common only to the subclass. In a specified method of the subclass you can access inherited methods by using the following syntax: parent_class.method Where parent_class is the name of the parent class and method is the inherited method from the parent class (Shammas 14-16). This can be useful to allow the programmer to carry out a specific Abstract Data Types Abstract data types are a collection of data and data types that are defined with specific operations and relations among the collection. Abstract data types, or ADTs, are closely related to OOP, except each ADT is a type and not an object. Having ADTs allows the programmer to focus on the structure of a program logically, rather than think about the actual implementation of a program (Leestma 650). This makes it very easy to port part of a program to another program without having to rewrite everything. A common part of ADTs is the record data structure. A record allows you to create subtypes of various user-defined types. These subtypes are known as fields. This allows you to create a data-type and store more specific information in variables of this data type. For example, a record data type might contain a string field and an integer field to represent someone's name and age. The field types can actually be other record types, to give you even more specific information. Record data types are declared in the type sub-heading and follow the syntax: variable = RECORD field-list END; Here, variable represents the name of the record and field-list represents the field list. The field list is declared just as any other variable is declared. In the program to access specific fieldlist entries, use the notation: variable.field-list Where variable is the declared variable of the record type and field-list is the specific field list entry defined for that record (Leestma 596600). Further, if one of the field list entries was of another record type, you would add an additional . after the field-list to weave through the layers. Exceptions/Concurrency An exception is a way for a program to handle a specific run-time error. When programs are written, three types of errors must be considered. They are compile-time or syntax errors, run-time errors, and logical errors. Compile-time errors are easy to acknowledge, because the program will not compile if such an error exists. Logical errors are difficult to find,
10
since they are mainly human errors such as using an asterisk instead of a plus sign to add to numbers together. The code will still run, but incorrect information will be gathered. Run-time errors fall somewhere between the other two types of errors. A program will compile with a run-time error, but when executed, it will not finish (Leestma 47). Some programming languages allow you to handle these run-time errors through methods known as exceptions. Exceptions allows the programmer to redirect execution of a program to another part whenever a particular run-time error occurs. This other part might contain contact information in order to contact the programmer and attempt to fix any bugs in the program. Turbo Pascal does not support this directly. Instead, Turbo Pascal has several built-in error messages that are written to the screen whenever a run-time error occurs. These error messages usually indicate the precise type of error and the line number in the code as to where the error was detected (Leestma 157). This allows the programmer to find the error or bug and fix the problem accordingly. Concurrency is a method in computer programming languages of performing more than one task at a time. A language that can support concurrency is able to execute two separate procedures simultaneously or concurrently. Concurrency is a very advanced computer programming idea. Since Pascal was developed mainly for educational purposes, it did not support concurrency. Borland never got the chance to add concurrency to the Turbo Pascal language, as that project was replaced with the Delphi series. Evaluation The Turbo Pascal programming language never was designed to develop vast programs. Although it is better at this aspect than ANSI
Pascal and other Pascal variants, it is still mainly a teaching tool used to teach programmers the importance of key programming concepts. When Borland introduced Turbo Pascal it sold for a very small price, around $50 in 1984. This made it a very easy language to attain and learn, and also made it very popular. Turbo Pascal brought many changes to the Pascal language, including strings, screen control, and better memory management. One of the key features of Turbo Pascal is the IDE that is shipped with it. With this IDE, Turbo Pascal was able to use syntax highlighting and error highlighting, which greatly helps introductory and advanced programmers (Turbo Pascal; the best cost less). This increases productivity with the language due to its greater writability. Turbo Pascal, like Pascal, was designed to be very readable, thus its widespread usage as an educational tool (Wade). It makes use of keywords that largely coincide with their English meaning. The specific type headings, which must be explicitly declared, also help with the readability of the language. Turbo Pascal is very simple, because a task can be performed in a logical manner (Sebesta 10). There are different methods to accomplish a single task and several different techniques to write a specific algorithm, but generally these operations are performed in a limited number of ways, so as not to hinder the programmer's learning. The Turbo Pascal language has its place in the programming language hierarchy. The idea was almost to view Turbo Pascal as an educational tool. Borland and the makers of Turbo Pascal realized this. They know there are other more powerful languages to perform tasks. However, these tools become insufficient if the programmer does not understand how to utilize them. Turbo Pascal is an ideal language to teach beginning computer scientists the basis surrounding these tools.
11
REFERENCES
Computer History. Knobblycrab. 10 Nov. 2003 <http://www.knobblycrab.co.uk/computer-history.html>. Functions and Scope. University of Texas - Pan American. 10 Nov. 2003 <http://www.cs.panam.edu/cs1380/funcs.htm>. Introduction to Pascal. 22 Aug. 1997. IICM. 10 Nov. 2003 <http://www2.iicm.edu/hmcard/courseware/pascal/PAS4.HTM>. Integrated Development Enviroment. 4 Nov. 2003. Wikipedia. 10 Nov. 2003 <http://www.wikipedia.org/wiki/Integrated_Development_Environment>. Learn Pascal. MIT. 10 Nov. 2003 <http://www.mit.edu/~taoyue/tutorials/pascal/history.html>. Leestma, Sanford and Larry Nyhoff. Turbo Pascal Programming and Problem Solving Second Edition. New York: MacMillan Publishing Company, 1993. Linux. 10 Nov. 2003. Wikipedia. 10 Nov. 2003 <http://www.wikipedia.org/wiki/Linux>. Object-oriented programming. 7 Nov. 2003. Wikipedia. 10 Nov. 2003 <http://www.wikipedia.org/wiki/Object_oriented_programming>. Pascal Tutorial 1D. 2001. MIT. 10 Nov. 2003 <http://web.mit.edu/taoyue/www/tutorials/pascal/pas1d.html>. Turbo Pascal. 9 Nov. 2003. Wikipedia. 10 Nov. 2003 <http://www.wikipedia.org/wiki/Turbo_Pascal>. Turbo Pascal Tutorial. 10 Nov. 2003 <http://dragoncurve.hypermart.net/pas_tut/Pas1-3.html>. Turbo Pascal; the best costs less. July 1984. Creative Computing. 10 Nov. 2003 <http://www.atarimagazines.com/creative/v10n7/53_Turbo_Pascal_the_best_co.php>. Sebesta, Robert. Concepts of Programming Languages Sixth Edition. Boston: Addison Wesley, 2004. Shammas, Namir. Object-Oriented Programming With Turbo Pascal. New York: John Wiley & Sons, Inc, 1990. Wade, Michael. Pascal. Hiram College. Powerpoint slide. <http://cs.hiram.edu/~guercioa/cs351/PASCAL.ppt>.
12