Comparison of Pascal and Delphi

Last updated

Devised by Niklaus Wirth in the late 1960s and early 1970s, Pascal is a programming language. Originally produced by Borland Software Corporation, Embarcadero Delphi is composed of an IDE, set of standard libraries, and a Pascal-based language commonly called either Object Pascal, Delphi Pascal, or simply 'Delphi' (Embarcadero's current documentation refers to it as 'the Delphi language (Object Pascal)' [1] ). Since first released, it has become the most popular commercial Pascal implementation.

Contents

While developing Pascal, Wirth employed a bootstrapping procedure in which each newer version of the Pascal compiler was written and compiled with its predecessor. Thus, the 'P2' compiler was written in the dialect compilable by 'P1', 'P3' in turn was written in 'P2' and so on, all the way till 'P5'. The 'P5' compiler implemented Pascal in its final state as defined by Wirth, and subsequently became standardised as 'ISO 7185 Pascal'.

The Borland dialect, like the popular UCSD Pascal before it, took the 'P4' version of the language as its basis, rather than Wirth's final revision. After much evolution independent of Standard Pascal, the Borland variant became the basis for Delphi. This page goes over the differences between Delphi and Standard Pascal. It does not go into Delphi-specific extensions to the language, which are numerous and still increasing.

Exclusive features

Following features are mutually exclusive. The Standard Pascal implementation is not accepted by Delphi and vice versa, the Delphi code is not acceptable in Standard Pascal.

Modulo with negative dividend

Standard Pascal has an Euclidean-like definition of the mod operator whereas Delphi uses a truncated definition.

Nested comments

Standard Pascal requires that the comment delimiters { and the bigramm (*, as well as } and *) are synonymous to each other. [2] In Delphi, however, a block comment started by {must be closed with a }. [3] The bigramm *) will only close any comment that started with (*. [3] This scheme allows for nested comments at the expense of compiler complexity.

Procedural data types

The way procedures and functions can be passed as parameters differs: Delphi requires explicit procedural types to be declared where Standard Pascal does not. [4]

comparison procedural data types
Standard PascalDelphi
programproceduralDataType(output);{ `printYIntersect` has one procedural parameter: }procedureprintYIntersect(functionf(x:real):real);beginwriteLn(f(0.0));end;{ Standard Pascal does not have procedural “pointers.” }functionf(x:real):real;beginf:=cos(x);end;{ ─── MAIN ───────────────────────────────────────────── }beginprintYIntersect(f);end.
typeTFunc=function(x:real):real;procedureprintYIntersect(f:TFunc);beginwriteLn(f(0.0));end;functionf(x:real):real;beginf:=cos(x);end;// ─── MAIN ─────────────────────────────────────────────beginprintYIntersect(@f);end.

Conversion of newline characters

Various computer systems show a wide variety how to indicate a newline. This affects the internal representation of text files which are composed of a series of “lines”. In order to relieve the programmer from any associated headaches, Standard Pascal mandates that reading an “end-of-line character” returns a single space character. To distinguish such an “end-of-line” space character from a space character that is actually genuine payload of the line, EOLn becomes true.

Delphi does not show this behavior. Reading a newline will return whatever character sequence represents a newline on the current host system, for example two char values chr(13) (carriage return) plus chr(10) (line feed). [3]

Additional or missing features

Following features are present or missing in either language.

Global goto

Standard Pascal permits a goto to any label defined in scope. In Delphi a goto must be within the current routine, i. e. may not leave the begin  end-frame. [3]

programjumpAround;label999;procedurefoo;begin{ This is not permitted in Delphi: }goto999;end;beginfoo;999:;end.

Buffer variables

Delphi does not support buffer variables and associated standard routines get and put. [3]

programcopy(input,output);beginwhilenotEOF(input)dobegin{ Copy file buffers. Not supported by Delphi }output:=input;{ Input↑ contains a space if a new-line occurred. }ifEOLn(input)thenbeginwriteLn(output);endelsebeginput(output);end;{ Advance reading cursor. }get(input);end;end.

Discriminated variant record allocation

In Standard Pascal allocating memory for a variant record may indicate a specific variant. This allows implementations to allocate the least amount of really necessary memory. Delphi does not support this. [3]

programvariantRecord;typesex=(female,male);clothingMeasures=recordgirth:real;casegender:sexoffemale:(underbust:real);male:();end;varsize:clothingMeasures;begin{ NB: No space allocated for `underbust`. }new(size,male);end.

Temporary files

In Delphi any file must be backed by a file in the file system. That means any file needs to be associated with a file name with Delphi’s assign procedure. In contrast, Standard Pascal is usable without file names. The following will produce a run-time error with Delphi. [3]

programtemporaryFile(output);varFD:text;beginrewrite(FD);writeLn(FD,'Hello world!');end.

Packing

Delphi does not implement the standard procedures pack and unpack. [3] Regardless, transferring data between packed and unpacked data types is an easy feat, although the implementation might not be as efficient as a compiler vendor supplied implementation would be.

Missing default write width

Delphi does not associate the data type Boolean with a default width if specified as write/writeLn parameters. [3] Delphi demonstrates the behavior as usual for character-strings.

Overloading

Delphi permits overloading routines. In Standard Pascal identifiers must be unique in every block.

functionf(x:integer):real;beginresult:=sin(x);end;functionf(x:real):real;beginresult:=cos(x);end;// ─── MAIN ─────────────────────────────────────────────begin// Note the different data types.writeLn(f(3));writeLn(f(3.0));end.

Default parameter values

Delphi permits default parameters.

Peculiar implementation characteristics

Standard write width

In Pascal, if the destination file is a text file, the parameters to write/writeLn have an implemention-defined default total width. In Delphi, for integer values this is simply 1. That means always the least amount of space is occupied. [3] Other compilers have shown default widths of, for example, 20 allowing for a fine tabular look at no cost of extra code.

comparison default write width
source code fragment
writeLn(1);writeLn(23456789);
produces in
Standard Pascal (GPC)Delphi
          1    23456789 
1 23456789 

Related Research Articles

<span class="mw-page-title-main">Oberon (programming language)</span> General-purpose programming language

Oberon is a general-purpose programming language first published in 1987 by Niklaus Wirth and the latest member of the Wirthian family of ALGOL-like languages. Oberon was the result of a concentrated effort to increase the power of Modula-2, the direct successor of Pascal, and simultaneously to reduce its complexity. Its principal new feature is the concept of type extension of record types. It permits constructing new data types on the basis of existing ones and to relate them, deviating from the dogma of strictly static typing of data. Type extension is Wirth's way of inheritance reflecting the viewpoint of the parent site. Oberon was developed as part of the implementation of an operating system, also named Oberon at ETH Zurich in Switzerland. The name was inspired both by the Voyager space probe's pictures of the moon of the planet Uranus, named Oberon, and because Oberon is famous as the king of the elfs.

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

In computer programming, a p-code machine is a virtual machine designed to execute p-code. This term is applied both generically to all such machines, and to specific implementations, the most famous being the p-Machine of the Pascal-P system, particularly the UCSD Pascal implementation, among whose developers, the p in p-code was construed to mean pseudo more often than portable, thus pseudo-code meaning instructions for a pseudo-machine.

Turbo Pascal is a software development system that includes a compiler and an integrated development environment (IDE) for the programming language Pascal running on the operating systems CP/M, CP/M-86, and DOS. It was originally developed by Anders Hejlsberg at Borland, and was notable for its very fast compiling. Turbo Pascal, and the later but similar Turbo C, made Borland a leader in PC-based development tools.

Generic programming is a style of computer programming in which algorithms are written in terms of data types to-be-specified-later that are then instantiated when needed for specific types provided as parameters. This approach, pioneered by the ML programming language in 1973, permits writing common functions or types that differ only in the set of types on which they operate when used, thus reducing duplicate code.

ALGOL W is a programming language. It is based on a proposal for ALGOL X by Niklaus Wirth and Tony Hoare as a successor to ALGOL 60. ALGOL W is a relatively simple upgrade of the original ALGOL 60, adding string, bitstring, complex number and reference to record data types and call-by-result passing of parameters, introducing the while statement, replacing switch with the case statement, and generally tightening up the language.

<span class="mw-page-title-main">Oberon-2</span> Programming language

Oberon-2 is an extension of the original Oberon programming language that adds limited reflective programming (reflection) and object-oriented programming facilities, open arrays as pointer base types, read-only field export, and reintroduces the FOR loop from Modula-2.

PL/0 is a programming language, intended as an educational programming language, that is similar to but much simpler than Pascal, a general-purpose programming language. It serves as an example of how to construct a compiler. It was originally introduced in the book, Algorithms + Data Structures = Programs, by Niklaus Wirth in 1976. It features quite limited language constructs: there are no real numbers, very few basic arithmetic operations and no control-flow constructs other than "if" and "while" blocks. While these limitations make writing real applications in this language impractical, it helps the compiler remain compact and simple.

Object Pascal is an extension to the programming language Pascal that provides object-oriented programming (OOP) features such as classes and methods.

ALGOL 60 is a member of the ALGOL family of computer programming languages. It followed on from ALGOL 58 which had introduced code blocks and the begin and end pairs for delimiting them, representing a key advance in the rise of structured programming. ALGOL 60 was one of the first languages implementing function definitions. ALGOL 60 function definitions could be nested within one another, with lexical scope. It gave rise to many other languages, including CPL, PL/I, Simula, BCPL, B, Pascal, and C. Practically every computer of the era had a systems programming language based on ALGOL 60 concepts.

<span class="mw-page-title-main">ALGOL 68</span> Programming language

ALGOL 68 is an imperative programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics.

The computer programming languages C and Pascal have similar times of origin, influences, and purposes. Both were used to design their own compilers early in their lifetimes. The original Pascal definition appeared in 1969 and a first compiler in 1970. The first version of C appeared in 1972.

IP Pascal is an implementation of the Pascal programming language using the IP portability platform, a multiple machine, operating system and language implementation system. It implements the language "Pascaline", and has passed the Pascal Validation Suite.

<span class="mw-page-title-main">GNU Pascal</span> Compiler for the Pascal programming language

GNU Pascal (GPC) is a Pascal compiler composed of a frontend to GNU Compiler Collection (GCC), similar to the way Fortran and other languages were added to GCC. GNU Pascal is ISO 7185 compatible, and it implements most of the ISO 10206 Extended Pascal standard.

<span class="mw-page-title-main">Oxygene (programming language)</span> Object Pascal-based programming language

Oxygene is a programming language developed by RemObjects Software for Microsoft's Common Language Infrastructure, the Java Platform and Cocoa. Oxygene is based on Delphi's Object Pascal, but also has influences from C#, Eiffel, Java, F# and other languages.

S-algol is a computer programming language derivative of ALGOL 60 developed at the University of St Andrews in 1979 by Ron Morrison and Tony Davie. The language is a modification of ALGOL to contain orthogonal data types that Morrison created for his PhD thesis. Morrison would go on to become professor at the university and head of the department of computer science. The S-algol language was used for teaching at the university at an undergraduate level until 1999. It was also the language taught for several years in the 1980s at a local school in St. Andrews, Madras College. The computer science text Recursive Descent Compiling describes a recursive descent compiler for S-algol, implemented in S-algol.

Concurrent Pascal is a programming language designed by Per Brinch Hansen for writing concurrent computing programs such as operating systems and real-time computing monitoring systems on shared memory computers.

Modula-2 is a structured, procedural programming language developed between 1977 and 1985/8 by Niklaus Wirth at ETH Zurich. It was created as the language for the operating system and application software of the Lilith personal workstation. It was later used for programming outside the context of the Lilith.

SuperPascal is an imperative, concurrent computing programming language developed by Per Brinch Hansen. It was designed as a publication language: a thinking tool to enable the clear and concise expression of concepts in parallel programming. This is in contrast with implementation languages which are often complicated with machine details and historical conventions. It was created to address the need at the time for a parallel publication language. Arguably, few languages today are expressive and concise enough to be used as thinking tools.

In software engineering, the module pattern is a design pattern used to implement the concept of software modules, defined by modular programming, in a programming language with incomplete direct support for the concept.

References

  1. "Delphi Reference - RAD Studio XE2".
  2. van der Heijden, Jan-Jaap; Gerwinski, Peter; Heckenbach, Frank; deBoer, Berend; Freche, Dominik; Lange, Eike; Lewis, Peter; et al. "The GNU Pascal Manual". A QuickStart Guide from Borland Pascal to GNU Pascal. Retrieved April 24, 2023.
  3. 1 2 3 4 5 6 7 8 9 10 Moore, Scott (December 2, 2022). "Standard Pascal FAQ". Q. What are the differences between Borland Delphi and the ISO 7185 standard?. Retrieved April 24, 2023.
  4. Reagan, John (April 3, 1995). "Pascal Standards FAQ". Comparison of Borland Pascal to the Pascal standards. Archived from the original on September 28, 2021.

Further reading