April 17, 2002

The purposes of programming languages: An introduction

Author: JT Smith

- By Jenn Vesperman -

Everywhere you turn in the computing world, there's someone claiming that programming language X "is best." Best for all circumstances, best in all cases, just plain best. But the world doesn't work that way. Languages have purposes, and a given language might be the best currently available for a given purpose. But no language is universally best for all purposes.There are benefits and costs to every language. And with hundreds of languages, finding the best language for a project can be a nightmare. Fortunately, languages can be categorized, which makes a cost-benefit assessment easier.

Language families

Start by dividing languages into language families. Each family has distinct characteristics that every member of the family shares, and that are not shared with other families.

In general, an algorithm that is written for one member of a language family will translate into the same algorithm for another member of the same family, but will need to be expressed very differently or completely changed to work in a different family.

Procedural: The largest language family is the procedural family. Procedural languages describe procedures -- recipes for the computer to follow. Do step 1, then step 2, then if x is true do step 3 else do step 4.

Procedural languages are extremely flexible, and are very good workhorse languages. Most programmers start their computing study in procedural languages. Typical procedural languages include the C family, Perl, Python, BASIC and Java.

Object oriented: Object oriented programming is a relatively recent approach to programming. Some languages have been developed to encourage object orientation in program design, the most well known of these are Java and C++. They are still procedural languages, but they have additional features (such as inheritance) that other procedural languages do not necessarily have.

Relational and other database languages: The next most common language family are the database languages. The various forms of SQL are relational database languages. These languages are database-specific -- they exist to make queries of a database, and to post data to the database.

The unique feature of relational databases is the structure of the data: in tables, with neatly defined relationships between the tables. It is not actually the language that is relational, but the database structure it describes. Storing and retrieving data are the main purposes of database languages.

Declarative: Declarative languages do not state how to do the task, only what task to do. Most "artificial intelligence languages" are declarative. If a language describes the structure of knowledge but not how to search it, it is likely to be a declarative language.

Declarative languages are extremely efficient at describing and searching expert systems and other AI constructions. They can also be effective as parsing tools. Lisp and Prolog are examples of declarative languages.

Functional: Functional languages describe mathematical functions. Order of execution is not relevant, nor are the details of data storage or presentation. A functional language is ideal for high level coding of intensely mathematical problems. Miranda and APL are functional languages.

Compiled vs. interpreted

The second major difference between languages is whether they are compiled or interpreted.

The source code for a compiled language is run through a program called a compiler before it reaches the user. The user receives executable code, and it runs without any external program other than the operating system.

Interpreted languages are provided to the user as source code or code in an intermediate form. The user's machine must also run an interpreter, which takes the program and interprets it into machine language step by step.

Because it doesn't run through an interpreter, a compiled language is usually faster to run. It also tends to use less memory and fewer system resources, because the process of interpreting from source code to machine code was done on the programmer's machine before it reached the user.

However, if the interpreter is on the user's machine already, there is no additional hard drive footprint, and there may not be an additional memory load. If the user's machine is fast enough, the speed difference may be insignificant.

An interpreted language has a faster code-test cycle -- because with a compiled language, the process is code, then compile, then test.

Interpreted languages will run on any system that has an appropriate interpreter. A compiled language must be recompiled for every system it will run on.

The source code for a compiled language is separate from the executable. This can be an advantage for security. In an interpreted language, the source code is the executable.

When execution speed, system resources and security are at a premium, a compiled language is usually a better choice. When rapid development turnaround is important and system resources are less critical, an interpreted language is usually more appropriate.

Typical uses

Scripting: For rapid development of small projects, interpreted "scripting" languages such as Perl, Python and Ruby are ideal. Development time is short, and system resources are rarely a problem.

Large projects: For large projects that must be carefully designed, the extra time taken to compile can be used as thinking time. System resources usually matter, and code security (even in Open Source projects) should be taken into account.

Compiled languages such as C, C++ and Ada are often used in these projects.

Cross-platform: At the moment, cross-platform development is dominated by Java and C++. Java is a combination of compiled and interpreted language, and the runtime environment (a.k.a. interpreter) deals with the issues caused by different operating systems. The rigorous standardization process that C++ underwent yields solid and portable backend code. The two are often used together to form a unified application.

Databases: SQL in its various incarnations is the most popular language for databases. It is a useful implementation of relational database theory.

String manipulation: Perl's native regular expressions make it a very useful language for string manipulation.

Final words

There's one other element to choosing a language -- learning time. Sometimes, particularly for short projects, the best language is one that is good enough in other ways, and one that at least some of your team already know.

Next time someone claims a particular language is "best," try asking "for what?"


  • Linux
Click Here!