ArticleslgStudy

science

Prototype-based programming

Prototype-based programming is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Prototype-based programming rather than just read about it. In short: Prototype-based programming is a style of object-oriented programming in which behavior reuse (known as inheritance) is performed via a process of reusing existing objects that serve as prototypes. This model can also be known as prototypal, prototype-oriented, classless, or instance-based programming.

Key takeaways

  • Prototype-based programming belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Prototype-based programming to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Prototype-based programming from memory before moving on to harder problems.

Reference excerpt

Prototype-based programming is a style of object-oriented programming in which behavior reuse (known as inheritance) is performed via a process of reusing existing objects that serve as prototypes. This model can also be known as prototypal, prototype-oriented, classless, or instance-based programming. Prototype-based programming uses the process generalized objects, which can then be cloned and extended. Using fruit as an example, a "fruit" object would represent the properties and functionality of fruit in general. A "banana" object would be cloned from the "fruit" object and general properties specific to bananas would be appended. Each individual "banana" object would be cloned from the generic "banana" object. Compare to the class-based paradigm, where a "fruit" class would be extended by a "banana" class.

History The first prototype-based programming language was Daniel G. Bobrow and Terry Winograd’s KRL. The 1976 Stanford AIM-293 makes it the first language to claim the term object-oriented in the modern sense, the one that formally introduced the term "inheritance" ("of properties"), actually implementing multiple inheritance, and the one that introduced the term "prototype" with the present meaning. Other early prototype systems include Director a.k.a. Ani (on top of MacLisp) (1976-1979), and contemporaneously and not independently, ThingLab (on top of Smalltalk) (1977-1981), respective PhD projects by Kenneth Michael Kahn at MIT and Alan Hamilton Borning at Stanford (but working with Alan Kay at Xerox PARC). Hewitt's Actors team at MIT added support for Prototype OO to ACT-1 in 1979 based on Kahn's work, calling the underlying mechanism "delegation" to distinguish it from the Class OO support they also added as "inheritance". Borning popularized the word "prototype" in this context in his 1981 paper in ACM Transactions on Programming Languages and Systems (TOPLAS). Meanwhile, Rees and Adams's implemented class-less OO using lexical closures in Yale T Scheme (1981-1989)—they didn't say "prototype", but it was isomorphic. Ken Dickey later published their OO model as portable Scheme code in 1992 as YASOS. The language that made the name and notion of prototypes popular among academics was Self (1985-1995), developed by David Ungar and Randall Smith. But the language that made prototypes common and ubiquitous is JavaScript (1995–present) by Brendan Eich. Since the late 1990s, the classless paradigm has grown increasingly popular. Some current prototype-oriented languages are JavaScript (and other ECMAScript implementations such as JScript and Flash's ActionScript 1.0), Lua, Cecil, NewtonScript, Io, Ioke, MOO, Rebol and AutoHotkey (AHK). Since the 2010s, a new generation of languages with pure functional prototypes has appeared, that reduce OOP to its very core: Jsonnet is a dynamic lazy pure functional language with a builtin prototype object system using mixin inheritance; Nix is a dynamic lazy pure functional language that builds an equivalent object system (Nix "extensions") in just two short function definitions (plus many other convenience functions). Both languages are used to define large distributed software configurations (Jsonnet being directly inspired by GCL, the Google Configuration Language, with which Google defines all its deployments, and has similar semantics though with dynamic binding of variables). Since then, other languages like Gerbil Scheme have implemented pure functional lazy prototype systems based on similar principles.

Design and implementation Etymologically, a "prototype" means "first cast" ("cast" in the sense of being manufactured). A prototype is a concrete thing, from which other objects can be created by copying and modifying. For example, the International Prototype of the Kilogram is an actual object that really exists, from which new kilogram-objects can be created by copying. In comparison, a "class" is an abstract thing, in which objects can belong. For example, all kilogram-objects are in the class of KilogramObject, which might be a subclass of MetricObject, and so on. Prototypal inheritance in JavaScript is described by Douglas Crockford as

You make prototype objects, and then … make new instances. Objects are mutable in JavaScript, so we can augment the new instances, giving them new fields and methods. These can then act as prototypes for even newer objects. We don't need classes to make lots of similar objects… Objects inherit from objects. What could be more object oriented than that?

Advocates of prototype-based programming argue that it encourages the programmer to focus on the behavior of some set of examples and only later worry about classifying these objects into archetypal objects that are later used in a fashion similar to classes. Many prototype-based systems encourage the alteration of prototypes during run-time, whereas only very few class-based object-oriented systems (such as the dynamic object-oriented system, Common Lisp, Dylan, Objective-C, Perl, Python, Ruby, or Smalltalk) allow classes to be altered during the execution of a program. Almost all prototype-based systems are based on interpreted and dynamically typed languages. Systems based on statically typed languages are technically feasible, however. The Omega language discussed in Prototype-Based Programming is an example of such a system, though according to Omega's website even Omega is not exclusively static, but rather its "compiler may choose to use static binding where this is possible and may improve the efficiency of a program."

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Prototype-based programming

Start with the simplest possible case. Write down what Prototype-based programming claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Prototype-based programming before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Prototype-based programming ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Prototype-based programming

In research
Prototype-based programming appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Prototype-based programming in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Prototype-based programming is common in secondary-school and first-year university syllabi. It links to neighbouring topics Object-oriented programming, Programming paradigms, Prototype-based programming, so understanding it makes those chapters shorter.
In everyday life
Look for Prototype-based programming outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Prototype-based programming in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Prototype-based programming means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Prototype-based programming out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Prototype-based programming in simple terms?

Prototype-based programming is a style of object-oriented programming in which behavior reuse (known as inheritance) is performed via a process of reusing existing objects that serve as prototypes. This model can also be known as prototypal, prototype-oriented, classless, or instance-based programm…

Why does Prototype-based programming matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Prototype-based programming?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Prototype-based programming.

Tags

  • Object-oriented programming
  • Programming paradigms
  • Prototype-based programming
  • Type theory

Keep exploring