hamilton c shell announcement - douglas a. hamilton - ibm personal systems developer - summer 1989

Upload: msnicki

Post on 10-Apr-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/8/2019 Hamilton C Shell Announcement - Douglas A. Hamilton - IBM Personal Systems Developer - Summer 1989

    1/3

    Summer 1989

    Software Tools

    Hamilton C ShellAnnouncementby Douglas A. HamiltonHamilton C shell is a brand new application forOS/2: not one line ofcode was ported from ordeveloped on anything but OS/2. In response tothe question often asked, UWhat can you do oilOS/2 that you cannot do on DOS? ,u the Hamil-ton C shell is one answer. This is an applicationthat simply could not be built on DOS.

    H amilton C shell is an interactive programming language for OS / 2. It is alanguage for talking about files and processesor threads and the connections betweenthem. The entire Berkeley C shell languagepopular on engineering workstations hasbeen faithfully recreated and carefullyupdated with modern compiler technology toproduce a very fast, powerful tool.Running in a Presentation Manager windowor full-screen, Hamilton C shell is a quantumleap from the standard OS/2 command processor in performance, functionality, and easeof use. People who spend most of their dayin front of OS/2 may well save an hour byusing Hamilton C shell; the payback for purchasing this product can be measured indays.

    FEATURESShown in Figure 1, Hamilton C shell featuresa full range of programming constructs foriteration, condition testing, and expressionevaluation. Statements can be nested-ufor"loops inside "switch" statements inside "if"statements, etc.-to any desired depth. Anindividual statement can have up to 64 KB ofcommand line arguments. Expressions caninvolve integers, strings, or floating point

    values and always result in sensible types,considering both the types an d the values ofthe operands.

    In addition to piping and 1/0 redirection,command substitution is provided, whichallows the output of one command to be usedas command-line arguments to another.Shell scripts, aliases, and procedures allowuser-defined language extensions. Filenamewildcarding is provided by a powerful recursive pattern-match algorithm; a wildcard canspecify matches against several directory levels in a path and a sensible match is guaranteed no matter how complex the pattern. Thehistory mechanism allows for recalling andediting past commands.

    Figure 1. Hamilton C Shell

    Douglas A. Hamilton

    Copyright 1989 by In te rna t iona l Business Machines Corporation.Reprinted with permission from IBM Personal Systems Developer, Summer, 1989. 119

  • 8/8/2019 Hamilton C Shell Announcement - Douglas A. Hamilton - IBM Personal Systems Developer - Summer 1989

    2/3

    Hamilton Cshell is acompletely newimplementationof the C shelllanguage forOS/2 comprisedofover 40,000lines ofC.

    120

    IBM Perso nal Systems Developer

    Finally, a large set of utilities is provided toround out the vocabulary of the language.There are tools for manipulating files or directories as objects, displaying disk usage,browsing forward and backward through afile or through the data coming through apipe , etc.Is it a better batch language? Yes, bu t it ismuch more than that. Hamilton C shell canbe used to build script files to do manythings. Scripts are also easier to get work ingand their perfo rmance is dramatically better.More importantly, the regularity of the language, the lifting of restrictions on commandline length, the ability to edit and rerun acommand, the powerful built-in constructs,etc., make it possible to do many more thingsinteractively. It is much easier to get thingsright the first time. A problem has to be farmore complex before the edit-debug-editcycle we associate with getting a batch file towork is needed.A good shell provides interaction bu t tacklesa different problem than icons and windows.Instead of the point-and-shoot immediacy of"do this single thing now," a shell offers language and the ability to describe more customized or repetitive actions (for example,identify a set of files, perform some actionagainst them, and filter the results in someinteresting way).

    BACKGROUNDThe earliest command processors did littlemore than let the user type the name of theprogram to be run. In the late 1960s, thingsbegan to change, reflecting new developments in operating system and languagedesign. The introduct ion of UNIX broughtwith it notions of filename wild carding, I I0redirection, piping, and background execution. The notation we use today for these constructs comes from the earliest UNIX shell.The author of the first shell, Steven Bourne,claims to have borrowed the term "shell"from the earl ier MULTICS system; certainly,it captured the idea of a user interface laye rwrapped around the kernel of the operatingsystem.Overall, the Bourne shell reflected the times:structured programming was a new conceptand in scholarly journals of the time it wasfashionable to reverse the letters of a keyword opening a control structure to indicate

    the end of it. In the Bourne shell, an "if" statement ended with "fi," "case" with "esac," etcAlso, there were relatively few "creature comforts." For example, if you mistyped a command, you typed it over-there was nothingelse you could do.By the end of the 1970s, considerably moreexperience had been collected with high levelanguages in general and with the shell in paticular. Seeing the need for a shell with a regular, modern style and grammar, and ahistory mechanism for recalling an d editingpast commands, Bill Joy ( then at Universityof California at Berkeley) undertook thedesign of the Berkeley C shell. He called itthe C shell to point ou t its similarity in control structures and arithmetic expression operators to the popular C language; realistically,though, its structure will be familiar to usersof any modern block-structured languageincluding Pascal or PL/I.

    DESIGNING FOR OS/2Hamilton C shell is a completely new implementation of the C shell language for OS/2comprised of over 40,000 lines of C. This issignificantly larger than the roughly 10,000lines in the original Berkeley C shell. We estimate that about half of the growth was dueto our choice of more modern and morepowerful, albeit more complex, compilertechnology.The rest of the growth was due to the specialengineering considerations of OS/2. Therewere a few cases where functions that UNIXprogrammers take for granted just did notexist and had to be recreated at the application level. For example, UNIX systems arecommonly supplied with a process statusfacility that reads tables inside the kernel toproduce a list of active processes. Lacking asimilar interface in OS/2, Hamilton C shellmaintains a list of child activities that i t creates; doing this requires the creation of dedicated "clean-up" threads whose sole purposeis to sleep in the background waiting forchild activities to finish.Generally speaking, we did not find OS/2 tobe a particularly difficult system to program.What we did find is that OS/2 providesunique facilities tha t are too good to pass upeven though putting them to best advantagedoes take more code. Multi-threading, whichoffers an extremely low-cost, high perfor-

  • 8/8/2019 Hamilton C Shell Announcement - Douglas A. Hamilton - IBM Personal Systems Developer - Summer 1989

    3/3

    mance mechanism for spawning concurrentactivities, was probably the most exciting. Incontrast to a process, which has its ow naddress space and resources (current directories, file descriptors, etc.), a thread owns onlya stack and a register set; a large number ofthreads, each separately scheduled, can sharethe memory space and resources of a singleprocess. Because of their extremely low overhead, threads can be spawned very quickly.Since they share the same memory space,they also can share information with greaterfacility.In the Berkeley C shell, i f the user requestedan activity be performed in the backgroundor concurrent with other activities, separateprocesses were needed. I f a background activity performed a calculation, it was awkwardto retrieve the result in the foreground. InHamilton C shell, threads are generally usedinstead, although obviously i f an externalapplication is invoked, that must be donewith a separate process or screen group. Theresult is far better performance. If a background thread assigns a value to a variable orcreates a new procedure definition, theresults are available instantaneously to anyother thread.Of course, threads are not free: anywhere athread needs to "own" a resource normallyshared with other threads, the designer is leftto his ow n devices to build an appropriatemechanism. For example, critical sectionsthat examine or modify shared objects mustbe protected with semaphores. In a shell, itwould hardly be acceptable if a script run-ning quietly in the background could sud-denly, without warning, change theforeground current directory! Building ahigh-performance mechanism to recreate acurrent directory notion for each threadturned out to be a fairly challenging project.

    Summer 1989

    On the whole, OS/2's superior kernel services were a big win; we expect that on similar hardware platforms, Hamilton C shellshould easily outperform any UNIX shell.

    SUMMARYHamilton C shell has been shipping sinceDecember 12, 1988. I t is available for immediate delivery for $350 and comes with anunconditional satisfaction guarantee. Anyone with a need to quickly increase their productivity on OS/2 will likely find this to be avery worthwhile acquisition.

    Douglas A. Hamilton, Hamilton Laboratories,13 Old Farm Road, Wayland, MA 01778-3117.(508) 358-5715. Mr. Hamilton is the author of theHamilton C shell. Prior to founding HamiltonLaboratories in September, 1987, he was the software development manager for Prime Computer'sRISC-based engineering workstations, jointlydeveloped with MIPS Computer Systems and Silicon Graphics. He holds bachelor's and master'sdegrees in Electrical Engineering from S t ~ n f o r ~ University and an MBA from Boston UniverSIty.His background includes eight years at IBM andsix years at Prime Computer in various engineering design and management positions.

    HamiltonC shell has beenshipping sinceDecember 12,1988. It isavailable forimmediatedelivery for$350.

    121