From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.3 required=5.0 tests=BAYES_00,INVALID_MSGID, MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,fa2cc518ef3b992c X-Google-Attributes: gid103376,public From: blaak@infomatch.com Subject: Re: scripting/extension language for Ada (was : Re: tagged types extensions) Date: 2000/02/05 Message-ID: <87gvdl$qsp$1@nnrp1.deja.com>#1/1 X-Deja-AN: 581862942 References: <389207CC.C16D80E8@averstar.com> <38971028.BB16D8A2@earthlink.net> <3899F757.FAE131B3@free.fr> X-Http-Proxy: 1.0 x35.deja.com:80 (Squid/1.1.22) for client 207.34.170.107 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Sat Feb 05 10:52:37 2000 GMT X-MyDeja-Info: XMYDJUIDblaak Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (X11; I; Linux 2.0.18 i486) Date: 2000-02-05T00:00:00+00:00 List-Id: Robert A Duff wrote: > Ray Blaak writes: > > Scripting languages, on the other hand, tend to be used for > > small, quickly written programs, and good ones tend to have a > > succinct powerful notation. > > I've seen way too much long-lived software written in Perl, > csh, awk, make, etc. There is always room for a better language. Is Ada right for a scripting language, though? > Anyway, "quickly written" is irrelevant. The only time it can > possibly make sense to use languages that are difficult to > maintain is when you're going to quickly throw away the code > after writing it. Nobody (at least not me) is advocating the use of scripting languages that are difficult to maintain. The usefulness of a good scripting language is that it is well designed for invoking OS services (expressing the piping of a chain of processes, for example), interactive and easy to debug, and tends to have small programs. E.g. a few K at most for a reasonably complex script -- that's it! No build steps, object files, link times. Just run it. One tends to use scripting languages to implement small little tasks (munge a few files, spit out some email, walk a few websites,...) Scripting languages should encourage programs that are easy to write, easy to understand, and easy to change. Most scripting languages are atrocious (esp. sh and friends). They don't have to be. What I like about scsh is that one has a real programming language (Scheme) focused on tasks such that the limitations of Scheme don't apply (i.e. the lack of a module or package system for programming "in the large"). Now Ada is a fine language, and my language of choice for real software systems. The problem with Ada for scripting purposes, however, is that there is too much declarative infrastructure needed to do simple tasks. Ada's strong static typing requires ones abstractions to be carefully specified. Dynamic typing in a scripting language, on the other hand, allows one to just "whip off" a solution, and yet still have strong type checking for good runtime error detection. Consider this scsh snippet: ;; Mail myself files matching some criteria (with-cwd "~/myfiles" (for-each (lambda (file) (if (run (grep "some pattern" ,file)) (run (mail -s "found it" blaak@home) (< ,file)))) (directory-files))) Boom! That's it. A few lines and the job is done. The equivalent Ada, even assuming a reasonable high-level API to OS services, is more tedious to set up. Perhaps: with AdaScript; use AdaScript; program Main is files : FileList := DirectoryFilesOf("~/myfiles"); begin for i in FirstOf(files) .. LastOf(files) loop if Run (("grep", "some pattern", FileNameAt(files, i))) = Success then Run (Args => ("mail", "-s", "found it", "blaak@home"), Stdin => FileAt(files, i)); end if; end loop; end; Not too bad, but a little noisy. Or perhaps: with AdaScript; use AdaScript; package ThisJob is -- Objects (tagged types) can only be declared in packages. Pain pain! type FileVisitor is new AdaScript.FileVisitor; procedure Visit (withVisitor : in out FileVisitor; theFile : in out File); end ThisJob; package body ThisJob is procedure Visit (withVisitor : in out FileVisitor; theFile : in out File) is begin if Run (("grep", "some pattern", FileNameOf(theFile))) = Success then Run (Args => ("mail", "-s", "found it", "blaak@home"), Stdin => theFile); end if; end; end ThisJob; with AdaScript; use AdaScript; with ThisJob; program Main is visitor : ThisJob.FileVisitor; files : FileList := DirectoryFilesOf("~/myfiles"); begin Traverse(files, withVisitor => visitor); -- dispatches on visitor end; The latter example I include to show the tediousness of setting up a mapping function in Ada. In a real system, tedious declarations are lost in the noise of the actual solution. Also, in a real system, the declarations give much valuable information to the compiler, allowing for good error checking and efficient code generation. In a real system I am a firm believer in tedious declarations. In the kinds of programs one needs scripting languages for, however, these declarations will often tend to dominate, and just make things, well, tedious. In short: Ada is too much of a general purpose language to serve as a scripting language. Use one designed for the purpose. Cheers, The Rhythm is around me, The Rhythm has control. Ray Blaak The Rhythm is inside me, blaak@infomatch.com The Rhythm has my soul. Sent via Deja.com http://www.deja.com/ Before you buy.