Scripting: A Programming Alternative : Who needs BASIC? Use your Web browser to run astronomical programs. (2024)

Link/Page Citation

For many years Sky & Telescope has included BASIC listings withastronomical computation articles. These programs afford insights intocelestial phenomena through their ability to simulate, predict, and aidvisualization. Various reasons have been given in the past as to whyBASIC remains the language of choice for this purpose, including itsubiquity and simplicity (S&T: April 1996, page 82). I want tosuggest, however, that there is a suitable alternative.

I must admit that I have a soft spot for BASIC. Like many others, Icut my programming teeth on it, and between 1991 and 1996 I developed afreeware BASIC compiler for Amiga computers (seewww.adelaide.net.au/~dbenn/). I'm not embarking on a critique ofBASIC or any other language. Rather, my primary concern is with the easeof dissemination of astronomical program code.

Every computer user who possesses either NetscapeNavigator/Communicator or Microsoft's Internet Explorer also hasaccess to the language I'm thinking of -- and I don't meanJava. I'm referring to ECMAScript. You are more likely to haveheard of JavaScript for Netscape or JScript for Internet Explorer. The"ECMA" stands for European Computer Manufacturers Association,an organization that decided on a common subset of JavaScript andJScript and designated the standard as ECMA-262.

ECMAScript programs are embedded within the hypertext markuplanguage (HTML) used to create Web pages and are run by the browser.Just as you don't need to be online to edit and view HTML files,ECMAScript programs can be created and run while you're offline.Internet Explorer 4.0 and Netscape 4.5 are fully ECMA-262 compliant andmany scripts are compatible with earlier versions of these browsers.

BASIC has existed for 30 years in some form, while ECMAScript hasbeen around for only a few years. In its favor, there are at leaststandards-conforming implementations in place. Even though the ANSIBASIC standard has been available for many years, it has rarely beenadhered to. It is also worth pointing out that though free BASICcompilers and interpreters are available, long gone are the days whenevery computer was shipped with BASIC. It is infinitely easier to getyourself a Web browser these days.

Script Basics

ECMAScript is a general-purpose interpreted programming languagewhose environment is essentially limited to a browser. Nevertheless, thecombination of HTML and ECMAScript makes it possible to performarbitrary computations and easily create a graphical user interface as afront end to a program.

ECMAScript provides all the fundamental functions for computerprogramming: variables, data entry, mathematical operations, flowcontrol, and output. The syntax of ECMAScript will be familiar to C/C++and Java programmers, as will the case sensitivity of its keywords andvariable names and the available operators. It offers a rich variety ofiteration and selection constructs (such as "while,""for," and "if"). Variable declarations areoptional, except for variables that are local to a function. Variablesmay take on a value of any one of ECMAScript's data types: number,string (text), Boolean, array, or object. ECMAScript makes nodistinction between integers and decimal numbers -- all aredouble-precision (64-bit) floating-point values.

Numerous objects provide access to a Web page's componentssuch as text fields, pop-up menus, and status bars. They also providefunctionality such as date and sophisticated string manipulation, aswell as all the math functions (trigonometric and logarithmic) neededfor astronomical computations.

For example, the following code snippet takes the square root of144 and writes it to the current Web page:

document.writeln(Math.sqrt(144))

Here "document" is an object corresponding to the currentWeb page, "writeln" is a function (or method, in the parlance)offered by "document" objects, and "Math" isECMAScript's repository for built-in math functions.

ECMAScript adds dynamic capabilities to HTML, permitting, forexample, checking the values entered into the form fields beforesubmission of the data, generating a pop-up menu that could contain afixed set of values (such as the appropriate number of days for thecurrent month), or alternating advertisem*nt images.

I have converted a few BASIC programs to ECMAScript. The one shownat right is a converted script program for the terrestrial crater impactdimension program from John Kennewell's article in the November1996 Sky & Telescope. The BASIC versions are available online atwww.skypub.com/resources/software/basic/basic.html, and you can see myscript versions at www.adelaide.net.au/~dbenn/docs/projects.html.Examining the code behind my conversion is simple with Netscape andInternet Explorer. Both allow you to view the source HTML of any Webpage, including embedded ECMAScript, via their View menus.

The Downside

Alas, ECMAScript has limitations. It has no graphics capability,though with later versions of the browsers it is possible to communicatewith a Java program (an "applet") that can display graphics.My Web page (cited above) shows examples of using an applet as a screenthat ECMAScript can draw upon.

Programs cannot be written to access files on your hard disk(except in JScript version 5.0). This was motivated by the risk of rogueWeb-based code damaging local files. However it is possible for anECMAScript program to write output to a Web page that can then be savedas a text file. Many astronomical calculations do not require graphicsor files, including many of the BASIC programs published in thismagazine.

Also, there is no equivalent of BASIC's PRINT USING command,but ECMAScript's string functions could be used for rudimentaryformatting.

Other Options, Less Compatibility

Alternatives to ECMAScript exist. Microsoft's VBScript is ascripting language derived from Visual BASIC that runs only underInternet Explorer. Similarly, Microsoft's ActiveX, like VBScript,is not a cross-platform solution. Scripting languages such as Perl andPython are available for all major platforms (Windows, MacOS, and Unix)but must be downloaded from the Internet, and any choice between themwould be arbitrary.

Java is more than suitable as a general-purpose programminglanguage. It is freely available for the major platforms and producesapplets that can run within a Web page. However, it has its nuisances:the learning curve is steeper than for ECMAScript, download times forWeb pages with embedded Java applets can be long, integration withWeb-page components (forms) is minimal, checking a program takes longerbecause the code has to be compiled before being executed, and it isoverkill for some applications. For anything nontrivial, however, Javais a great choice.

My feeling is that the programs presented by Sky & Telescopemay be more useful as active programs running in your Web browser thanas code for which an interpreter or compiler may or may not be readilyavailable. When appropriate, ECMAScript programs could be offered inaddition to BASIC listings. An ECMAScript program is just a mouse clickor three away, can be used immediately, incurs very little overhead, andcomes with the source code, all in one neat package.

Alternatively, a free ECMAScript interpreter can be obtained fromthe Internet. Written in Java, it will run on any platform with a Javainterpreter (see http://home.worldcom.ch/~jmlugrin/fesi/).

A Simple Sample

To finish up -- and as some homework for the reader -- above is asimple, complete ECMAScript program example that will calculate anddisplay the square root of an entered number. By typing the text intoany word processor and then saving it to disk (as, say,"simple.html") you will have written your first ECMAScriptprogram.

When you open the file containing this code with a Web browser, thebrowser will display some title text and a form with two text boxes anda button, as shown in the sample screen. Most of the code is HTML withan ECMAScript function defined in the header section and a button-clickevent handler attached to the "Calculate" button. When thebutton is clicked, the form object is passed to the "doSqrt"function so that the form's fields may be accessed.

While this introductory article has only scratched the surface, Ihope that it and the accompanying examples give you a taste of howECMAScript could be applied to the task of disseminating astronomicalcomputation code.

David Benn ([emailprotected]) is a software engineer forMotorola at its Adelaide-based Software Centre and is pursuing amaster's degree in computer science. He's also a member of theAstronomical Society of South Australia.

Further Resources

ECMAScript standard; http://www.ecma.ch/stand/ecma-262.htmMicrosoft's JScript overview;http://msdn.microsoft.com/scripting/jscript/default.htm Netscape'sJavaScript Guide; http://developer.netscape.com/docs/manuals/communicator/jsguide4/index.htm

RELATED ARTICLE: BASIC Code

10 REM - IMPACT CRATER DIMENSIONS20 CLS : PI=3.1415930 CR1=18: CD1=940 PRINT "Terrestrial Impact Crater"50 INPUT " Impactor diameter (m)";ID60 INPUT " Impactor density (kg/m^3)";IR70 INPUT " Impactor velocity (km/s)";IK80 INPUT " Graze angle (deg. from horiz.)";GA90 IV=IK*1000: VI=PI*ID*ID*ID/6100 GF=(SIN(GA/180*PI))^.33110 MI=IR*VI: KE=.5*MI*IV*IV120 KT=KE/4.2E+12: REM impactor KE in kT TNT130 PRINT: PRINT "Impactor Parameters"140 PRINT USING " Volume ##.##^^^^ m^3"; VI150 PRINT USING " Mass ##.##^^^^ kg"; MI160 PRINT USING " KE ##.##^^^^ J"; KE

RELATED ARTICLE: ECMAScript

[less than]html[greater than][less than]head[greater than][less than]title[greater than]Terrestrial Impact Crater Dimensions.[less than]/title[greater than] [less than]script language = "JavaScript"[greater than] /* Note: values are global to a JavaScript * block unless explicitly scoped. * * The same variable names have been used * as the original BASIC program for ease * of comparison. */ PI=3.14159; CR1=18; CD1=9; function craterCalculations(impactor) { calcImpactor(impactor);

RELATED ARTICLE: Simple ECMAScript Example

[less than]html[greater than] [less than]head[greater than] [less than]title[greater than]Simple ECMAScript Example[less than]/title[greater than] [less than]script language = "JavaScript"[greater than] function doSqrt(form) { form.result.value = Math.sqrt(form.num.value); } [less than]/script[greater than] [less than]/head[greater than] [less than]body[greater than] [less than]h5[greater than]Simple ECMAScript example which displays the square root of an entered number.[less than]/h5[greater than] [less than]form name="sqrtForm"[greater than] Enter Number: [less than]input type="text" name="num" value="" size=7[greater than] [less than]input type="button" value="Calculate" onClick="doSqrt(document.sqrtForm)"[greater than] [less than]input type="text" name="result" value="" size=7[greater than] [less than]/form[greater than] [less than]/body[greater than][less than]/html[greater than]

COPYRIGHT 2000 All rights reserved. This copyrighted material is duplicated by arrangement with Gale and may not be redistributed in any form without written permission from Sky & Telescope Media, LLC.
No portion of this article can be reproduced without the express written permission from the copyright holder.

Copyright 2000 Gale, Cengage Learning. All rights reserved.


Scripting: A Programming Alternative : Who needs BASIC? Use your Web browser to run astronomical programs. (2024)
Top Articles
Chase Bank With Atm Near Me
Uno Online Cool Math
NYT Mini Crossword today: puzzle answers for Tuesday, September 17 | Digital Trends
Palm Coast Permits Online
Angela Babicz Leak
Voorraad - Foodtrailers
Botanist Workbench Rs3
Sam's Club Gas Price Hilliard
Craigslist Furniture Bedroom Set
Beds From Rent-A-Center
Campaign Homecoming Queen Posters
Ucf Event Calendar
Wordle auf Deutsch - Wordle mit Deutschen Wörtern Spielen
Marion County Wv Tax Maps
Gmail Psu
Top tips for getting around Buenos Aires
Lancasterfire Live Incidents
111 Cubic Inch To Cc
Arre St Wv Srj
Melendez Imports Menu
Aes Salt Lake City Showdown
Weve Got You Surrounded Meme
1145 Barnett Drive
Safeway Aciu
Emuaid Max First Aid Ointment 2 Ounce Fake Review Analysis
Marlene2295
49S Results Coral
Club Keno Drawings
Redding Activity Partners
Busted! 29 New Arrests in Portsmouth, Ohio – 03/27/22 Scioto County Mugshots
Wisconsin Volleyball Team Leaked Uncovered
Fastpitch Softball Pitching Tips for Beginners Part 1 | STACK
Nacogdoches, Texas: Step Back in Time in Texas' Oldest Town
Flaky Fish Meat Rdr2
Blackstone Launchpad Ucf
The Legacy 3: The Tree of Might – Walkthrough
Planet Fitness Lebanon Nh
Collier Urgent Care Park Shore
Babbychula
Mixer grinder buying guide: Everything you need to know before choosing between a traditional and bullet mixer grinder
Insideaveritt/Myportal
Armageddon Time Showtimes Near Cmx Daytona 12
Henry Ford’s Greatest Achievements and Inventions - World History Edu
Walmart Pharmacy Hours: What Time Does The Pharmacy Open and Close?
Kutty Movie Net
Az Unblocked Games: Complete with ease | airSlate SignNow
A rough Sunday for some of the NFL's best teams in 2023 led to the three biggest upsets: Analysis
Take Me To The Closest Ups
9294027542
Myapps Tesla Ultipro Sign In
Barback Salary in 2024: Comprehensive Guide | OysterLink
Mast Greenhouse Windsor Mo
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 6536

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.