![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
May 1999 | Volume 9 Number 5 |
Scripting Languages ... by Terry Griffin
Throughout the history of computers, there's always been demand for intermediate-level programming languages. By this I mean something that's more powerful than command processor and command shell programming (COMMAND.COM, CMD.EXE, bash, ksh, csh), but without the steep learning curve and development overhead of full-fledged compiled languages (C/C++, Fortran, Pascal, COBOL). This middle ground is typically filled by all manner of interpreted languages, although it is not uncommon for some to evolve in to compiled languages.
A few command processors have been powerful enough to satisfy most of the programming needs in this middle tier for its native OS and stave off demand for more powerful interpreted languages. One of these is Compaq's (formerly Digital's) DEC Command Language (DCL) for VMS. This, however, is the exception rather than the rule. The interactive model of most command processors proves too great a burden when faced with heavy duty programming tasks.
In CP/M, on the Apple I and II, and on DOS and some of its descendants, the middle tier has been filled by some form of interpreted BASIC. An exception was OS/2, which introduced the REXX language to PCs for compatibility with other IBM operating systems.
On Unix, command shells have tried to do for Unix what DCL did for VMS, but with only partial success. Where they leave off, a variety of scripting languages have jumped in. A brief overview of some of the more popular of these languages for Unix follows. All of the languages discussed here are also available for many non-Unix platforms.
The awk language was originally developed at AT&T Bell labs by Alfred Aho, Peter Weinberger, and Brian Kernighan. It continues to be maintained by Brian Kernighan. The AT&T implementation ships with most proprietary flavors of Unix, and its official definition is now contained in POSIX standard 1003.2.
Linux and other open source flavors of Unix include a clone of AT&T's awk, GNU awk (gawk) by Paul Rubin and Jay Fenlason of the Free Software Foundation. In addition to supporting Unix, gawk is available for DOS, VMS, Atari ST, and OS/2. A Win32 port of gawk (and many other GNU tools) is included as part of Cygwin collection from Cygnus Solutions.
Awk was designed as a text processing language, and, as such, it contains strong support for regular expression matching. It also has some number crunching capability, including a basic math library. Awk has a C-like syntax and two types of variables, strings and floating point numbers. Awk is procedural, not object oriented. By itself awk is considered inadequate for many tasks, so it is often paired with sed, the Unix stream editor. This pairing of awk and sed is so common that you rarely hear one mentioned without the other.
Use of awk has fallen off in recent years since the arrival of Perl (see below), but there are still quite a lot of awk scripts floating around out there. The latest version of gawk may be acquired from the GNU project's FTP archives.
As with many modern scripting languages the Tool Command Language (Tcl) was designed to solve a particular problem. While a professor at UC Berkeley, John Ousterhout and his students found themselves repeatedly adding custom scripting capability to various software tools they had developed for integrated circuit design and other tasks. After many iterations of this, and not being entirely satisfied with the results, Mr. Ousterhout implemented a reusable C language package for adding scripting capability to any C program. Thus Tcl was born.
At first glance, Tcl (often pronounced "tickle") looks a lot like C, but the more you use it the less C-like it becomes. Tcl is not much of a text processing language, nor is it much for number crunching. There is one data type, strings, but if these strings contain numbers then they are interpreted as such in certain contexts. Tcl is procedural, not object oriented (OO), but OO extensions are available.
Because the original design of Tcl assumed that most of the hard work would be done by C code, Tcl by itself doesn't really excel at anything. In particular, it doesn't scale well, that is to say, it is generally not suitable for large projects. Recent enhancements to the language have improved its scalability, but in my view they were poorly designed and come across as kludges more than enhancements. Generally, you're better off to stick to the original intent of Tcl, which is to do the complicated stuff in C.
What saved Tcl from oblivion, in my opinion, was the Tk toolkit, inspired by Apple's Hypercard. Tk adds graphical user interface (GUI) capability to Tcl. The first time I saw Tk in action a co-worker of mine wrote a three-line script that presented a simple GUI button. Our previous GUI programming experience was limited C/X11/Motif and C/MS-Windows-API where creating just a button is anything but trivial, so we were all quite impressed.
Tcl has proved to be popular enough that John Ousterhout recently started his own company in an attempt to make a living from it. The company is Scriptics, now official Tcl/Tk distributors for Unix, Win32, and Macintosh. Native ports are also available for DOS, Win16, OS/2, and VMS, although many of these ports are running several version numbers behind the Scriptics version.
The Practical Extraction and Reporting Language (Perl) started out as a successor to awk. Larry Wall was trying to use awk to solve a particular problem which turned out to be too big for awk to swallow, so he switched to a different language, C. But instead of using C to solve his problem directly he used it to implement a new general purpose text processing language, Perl, which in turn he used to solve his problem.
Perl's forte is still text processing, but it has evolved in to a general purpose language. Perl can be either procedural or object oriented, depending on your personal preference. There is only one data type, strings, but with OO you can create as many other types as you need. Like Tcl, it may be embedded in C programs. For those of you with old awk and sed scripts around, Perl comes with awk-to-perl and sed-to-perl translation utilities.
One popular use of Perl is as "glue" language. This is the software equivalent of duct tape. With a glue language, you can patch together other bits of software that otherwise would have no way of working together. As the Internet's most popular glue language, and in particular for its use in web server CGI scripts, Perl has been dubbed the duct tape of the Internet.
One of the things that makes Perl a good general purpose language is its rich library, which includes routines that implement the entire POSIX.1 API (application program interface) standard for interacting with the operating system.
Those who like Perl and those who dislike it do so for pretty much the same reason. Perl is quite deliberately a messy language. You can get very sloppy with Perl, and there's a good chance that it will still do what you want. Perl scripts can be made to look like C, or not anything like C. It's a matter of your personal style. It enforces the minimum set of rules necessary to get by. In Perl there are few wrong ways to do something and multitudes of right ways, leading to the Perl motto "There's more than one way to do it!"
The messiness of Perl hit home recently when I had the need to enhance one of my own Perl scripts. Upon examining the script, it took me quite a while just to figure out how it worked. Lesson: Perl code is not self documenting.
Perl's free form attitude is in contrast to languages like Java, Ada, and Pascal, which seek some notion of computer science purity. The Perl philosophy traces to Larry Wall's profession as a linguist, from which he's gained an appreciation for the messy qualities of spoken languages that give them the flexibility for solving a wide variety of communication problems.
Perl has no GUI capability, but the Perl/Tk project has merged (you guessed it) the Tk toolkit from Tcl/Tk with Perl to create a viable alternative to Tcl/Tk for quick and dirty GUI development.
Stock Perl is available for all flavors of Unix, plus VMS, OS/2, and Win32. There are also ports to many other operating systems. More information can be found at http://www.perl.com/. For information on Perl/Tk, start with the FAQ.
Guido van Rossum's Python language was, from the beginning, designed as a glue and general-purpose language. Guido did not have particular problem to solve. He just had some "ideas left over" from some previous projects that he wanted to try out. So, over a two week period one Christmas break, Python came into existence. (I wish I had some ideas left over.)
Python is meant to address many of the same tasks as Perl, but it does so without being quite so messy. This makes it popular amongst those who are uncomfortable with Perl's free form attitude. Also unlike Perl, standard Python comes with several GUI extensions, including Tk.
Python has very strong object-oriented flavor. It looks nothing like C, and has the unusual characteristic that indentation is part of the language syntax. Like Tcl and Perl, Python may be embedded in C programs. Like compiled languages, there are a large number of built-in data types, including strings, integers, floating point numbers, plus an analog to the C "void" type, and a type type. That is, you can create a variable that is itself a type definition, and this variable can, for example, be compared to other variables that contain type definitions. Like I said, it's very object oriented.
I can't say much more about Python because, unlike Tcl and Perl, I've not uses it that much. Besides, I'm just about out of space. It's all free software so just try Python and the others yourself and make your own judgments. Python is available for all flavors of Unix, plus DOS, Win16, Win32, WinCE, Macintosh, OS/2, Amiga, BeOS, QNX, VMS, and Psion. Get the latest software and information at http://www.python.org/.
You can also get a listing of articles by Terry Griffin
If you need instructions for our search engine, go to our main search page.
This article was originally published in the May 1999 issue of Computer Bits magazine, and is copyright © 1999 by Bitwise Productions, Inc., Forest Grove, OR, (503) 359-9107. All rights reserved. Archival material is provided as-is. Links are not necessarily maintained. Recent events compel us, sadly, to emphasize that your rights to this article are limited to viewing it and printing it for personal use only. You must receive explicit permission from Computer Bits and the author(s) before reprinting or redistributing this article in any medium. |