Jump to content

NewtonScript

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Akmaverick (talk | contribs) at 22:46, 22 September 2016 (Added citations.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
NewtonScript
ParadigmPrototype Object-oriented
Designed byWalter Smith
DeveloperApple Computer
First appeared1993; 32 years ago (1993)
Typing disciplineDynamic
Influenced by
Self, Dylan
Influenced
Io

NewtonScript is a prototype-based programming language created to write programs for the Newton platform.[1] It is heavily influenced by the Self programming language, but modified to be more suited to needs of mobile and embedded devices.[2]

History

Traditional computers, at least in the desktop role, have two modes; "on" and "off". When moving from one mode to the other the state of the machine is lost from memory, and requires a sometimes lengthy "boot" process to return the machine to the "on" state. This does not suffice for a PDA type device where the user expects the machine to be available almost instantly for taking down quick notes. Yet, during early years of 1990, leaving a PDA "on" for any length of time was impractical, as this would drain the battery too much to make it useful for carrying around.

In the Newton platform, the system had two states that were more like "on" and "sleeping". When moving to the sleeping state the memory was not lost and instead the system simply stopped working on the contents of memory, which allowed for many of the chips inside to be turned off. This greatly extended battery life, yet still allowed the machine to turn back on almost instantly.

With the main memory always being kept alive, the system becomes much more amenable to use as a persistent object store. Many object-oriented systems, like Smalltalk, are based on a continually running object world (known as an image or, when saved as a disk file, a snapshot), so using the Newton platform with an object-oriented system seemed quite natural.

The developers then began looking for languages to use on the system. The Newton platform was originally going to be programmed in the new Dylan programming language, but a lengthy series of delays eventually led to it being abandoned. The team had looked at Self and were very interested in it, but at the time Self was not yet ready for real-world use.

The result was a modified version of Self known as NewtonScript. Written primarily by Walter Smith, the language was a part of the Newton Toolkit, introduced along with the first Newton device (the Apple MessagePad) on August 3, 1993.

Features

NewtonScript was heavily influenced by Self. However, there were some differences in both the languages.

Differences aroused due to three perceived problems with Self.

  1. One is that the typical Self snapshot requires 32 MB of RAM to run in, whereas the Newton platform was designed to use only 128 KB for the operating system. This required some serious paring down of the engine to make it fit and still have room for applications.
  2. Another issue was performance. Since the language would be used for the entire system, as opposed to just running on an existing operating system, it needed to run as fast as possible.
  3. Finally, the inheritance system in the normal Self engine had a single parent object[3], whereas GUIs typically have two — one for the objects and another for the GUI layout that is typically handled via the addition of a slot in some sort of GUI-hierarchy object (like View).

The syntax was also modified to allow a more text-based programming style, as opposed to Self's widespread use of a GUI environment for programming. This allowed Newton programs to be developed on a computer running the Toolkit, where the programs would be compiled and then downloaded to a Newton device for running.

One of the advantages of NewtonScript's prototype based inheritance was reduced memory usage, a key consideration in the 128 KB Newton. The prototype of a GUI object could actually be stored in ROM, so there was no need to copy default data or functions into working memory.

Unlike class based languages, where creation of an object involves memory being allocated to all of it's attributes, NewtonScripts' use of prototype inheritance allowed it to allocated memory to few fields like _proto and _parent instead of creating whole new object. Here, _proto and _parent signifies whether the object is using prototype or parent inheritance.[4]

An example to illustrate above concept, a developer might create a new button instance. If the button uses the default font, accessing its font "slot" (i.e., property or member variable) will return a value that is actually stored in ROM; the button instance in RAM does not have a value in its own font slot, so the prototype inheritance chain is followed until a value is found. If the developer then changes the button's font, setting its font slot to a new value will override the prototype; this override value is stored in RAM. NewtonScript's "differential inheritance" therefore made efficient use of the Newton's expensive flash RAM by storing the bulk of the default data and code in the PDA's cheaper and much larger ROM.

Advantages and Disadvantages

Advantages

  • NewtonScript is a dynamic prototype based programming language, which uses differential inheritance. This means that it is very effective is using memory space. Being dynamic, it is easy to modify objects, type checking, etc. at run time, giving great flexibility for developers.
  • Objects created can be stored in permanent memory like flash card or internal memory. The RAM is used only for storing attributes whose values change during runtime. This reduces memory consumption.
  • Writing interfaces for GUI applications can be implemented effectively using the prototype model, since we can directly write an object for a GUI control rather than creating a class and instantiating it.
  • Garbage collection is carried automatically by the system. This helped the developers to focus more on application development rather than worrying about memory management. Garbage collection also helped in mitigating problem of dangling pointers where a pointer erroneously points to a memory location that was deallocated.[4]

Disadvantages

  • Since NewtonScript code was written on one platform and run on another, it was practically impossible to debug[2]. Better debugging code in the Newton engine would have helped offset this problem to some degree, but the limited memory made this difficult. Instead the developer would get a vague indication along with an error code, without any ability to match it to lines in the original code. However, software packages exist to allow Newton programs to be written on the Newton device itself.
  • Another disadvantage is that, dynamic variable reduces the speed of operation since simple pointer dereference cannot be used as in statically typed like C++ and Java.

Legacy

NewtonScript is also one of the conceptual ancestors (together with Smalltalk, Self, Act1, Lisp and Lua) of a recently created general-purpose programming language called Io.[5]

NewtonScript employs an inheritance model called differential inheritance where only the differences with its parent prototype are stored in a list of properties (known as slots in Io). This is a very useful feature for resource-constrained systems. The Io language implements the same differential inheritance model.

The prototype-based object model of Self and NewtonScript was used in JavaScript, the most popular and visible language to use the concept so far.

References

  1. ^ Smith, W. R. (1994-02-01). "The Newton application architecture". Compcon Spring '94, Digest of Papers.: 156–161. doi:10.1109/CMPCON.1994.282931.
  2. ^ a b Schödl, Arno (2004-10-10). "The NewtonScript Programming Language". Retrieved 2016-09-15.
  3. ^ Chambers, C.; Ungar, D.; Lee, E. (1989-01-01). "An Efficient Implementation of SELF a Dynamically-typed Object-oriented Language Based on Prototypes". Conference Proceedings on Object-oriented Programming Systems, Languages and Applications. OOPSLA '89. New York, NY, USA: ACM: 49–70. doi:10.1145/74877.74884. ISBN 0897913337.
  4. ^ a b "The NewtonScript Programming Language" (PDF). 1996. Retrieved 1 May 2025.
  5. ^ "io guide". iolanguage.org. Retrieved 2016-09-15.

Citations