45

Are there any object-oriented programming languages that are not based on the class paradigm?

2
  • 1
    Technically speaking, C. Though oriented is quite a stretch in the sense of the language making it easy. I know that's not the kind of answer you are looking for, but if you care to look into how C can do it, it might provide some insight into what it is that classes actually do and how alternative approaches can work.
    – kylben
    Oct 20, 2011 at 19:58
  • 4
    @kylben: "Oriented" is an uncalled-for stretch. You can bludgeon C into object-oriented behavior. You can't bludgeon it into being oriented that way. Oct 20, 2011 at 20:54

8 Answers 8

74

As far as I know, Self is the original language that invented the "class-free" paradigm based on prototypes. It already existed (in an experimental stage) in the 1980s and pushes Smalltalk's elegant usage of the prototype pattern to the extreme, such that classes are completely eliminated.

It influenced all the other "class-free" OO languages I know of:

  • most prominently Javascript,
  • the classical programming language and environment Squeak (which is built on top of Smalltalk)
  • the multi-paradigm script language Lua.
13
  • 2
    @Adam: without static typing, isn't it ALL just syntactic sugar? Oct 20, 2011 at 21:13
  • 5
    @DeadMG OO language is not the one which enables you to implement OO ideas but one which does it for you :) Oct 20, 2011 at 22:00
  • 4
    Actually, both Simula (1960) and Smalltalk-71 (as well as Smalltalk-72) didn't have classes, either, which predates Self by almost three decades. Classes were only added in Simula-67 and Smalltalk-74 (and Alan Kay considered them a mistake, or more precisely a necessary evil). Oct 20, 2011 at 23:56
  • 2
    @kevincline: Not sure what you're basing that on; OO and static typing are completely orthogonal. Oct 21, 2011 at 7:52
  • 2
    Apart from Simula (which did take on the class paradigm) Flavors was introduced at MIT in 1979, and was a precursor to CLOS, both of which predate Self. Aug 9, 2012 at 17:29
31

Languages like JavaScript are based on prototypes, where behavior is reused by cloning existing objects. The Wikipedia article that I linked to indicates that Lua, ActionScript, and a number of other languages follow this paradigm.

3
  • 2
    Any ECMAScript variant uses the prototype paradigm.
    – zzzzBov
    Oct 20, 2011 at 20:05
  • Well, almost any variant. ActionScript (the Flash language) uses classes, although the underlying VM might be implementing them in terms of prototypes.
    – mjfgates
    Oct 21, 2011 at 4:18
  • @mjfgates, Actionscript 2 used to be ECMAScript based and resembled Javascript a lot. Actionscript 3 is moving away from that, but still holds its dynamic nature. You can strong/weak type any variable since in essence everything is an Object.
    – J_A_X
    Oct 21, 2011 at 5:41
13

The most popular object-oriented programming language in the world doesn't have classes, it's called Javascript and is prototype based : http://en.wikipedia.org/wiki/Prototype-based_programming

8
  • 12
    "Most popular object-oriented programming language in the world"? I'm not sure about that claim at all.
    – Thomas Owens
    Oct 20, 2011 at 19:11
  • 8
    @ThomasOwens, due to its inclusion on the web, you can easily say that every modern web-enabled platform (including mobile devices) has a JavaScript interpreter included. That's a very strong case that it is currently the most popular prototype based language in existance. (unless you think you can make a similar argument for "SELF")
    – riwalk
    Oct 20, 2011 at 19:46
  • 1
    Javascript is certainly one of the most widely-used programming languages in the world, but I'd expect most usages to be plain old imperative or procedural, with maybe a bit of aspect-oriented programming (callbacks? AJAX? event handlers?) here and there, so calling javascript the 'most popular OOP language' isn't quite justified.
    – tdammers
    Oct 20, 2011 at 20:02
  • 9
    I would also say "ubiquitous" in order to sidestep a discussion on the merits of its popularity. Oct 20, 2011 at 20:03
  • 3
    @Stargazer712: I don't like being a language bigot, but he does claim that "the most popular object-oriented programming language in the world [ed: Javascript] doesn't have classes". It can be decomposed of two claims: "Javascript is the most popular object oriented programming language" and "Javascript doesn't have classes"; both of which, I agree with.
    – Lie Ryan
    Oct 21, 2011 at 4:24
6

Object-orientation is an umbrella term for several important concepts that are only partly contingent upon each other. For instance, inheritance can be declared on a case-by-case basis between instances rather than between classes, or the entire class can be represented by a concrete prototype object, as Thomas wrote. It's just more usual to separate structure description from instance creation. Similarly, late binding means that objects with nominally the same method don't necessarily do the same thing when it is invoked, and that the decision is made at runtime. That is likewise possible with the prototype-based approach. And encapsulation is essentially completely independent of whether your objects are instances of declared classes or not.

That said, most OO languages are firmly in the class-based camp. But even then there are idioms that blur the line: the domain-driven design often leads to systems in which the identity of particular objects is much more important than the static class diagram, and decorators allow objects of the same class or interface to have very different behavior.

6

Fortress is an object-oriented language based on traits instead of classes. The difference is mainly in implementation composition. An object's behavior (method definitions) is still determined by the declarations at a specific point in the program text. So in that sense it's similar to class-based systems.

There are object calculi (by Cardelli, I think), that are purely object-based. Every method is an instance member. You form new objects by taking the contents of an existing object and adding, removing, or replacing some of its members. It's slightly different from prototypes, since the new object has no link to the old object, just some of its contents.

IIRC, it's possible to program in a similar way using Python and other hashtable-oriented languages: you can add a function as an instance member and then call it as a method.

5

Ada, as of its 1995 revision, Ada is object-oriented, but unlike a lot of other OO languages it doesn't combine object-oriented types and modules into a single construct called a "class". Rather than declaring a type as "class Foo", and putting all the associated method declarations inside the class declaration, you declare a package and declare the type (as a record) and other things inside the package. It's not "class-free" in the way that some of the other mentioned languages are, it's just a slightly different way of organizing things.

Ada 95's object-oriented features were added onto the existing 1983 version of the language; it extended the existing record and package constructs to support inheritance et al.

2
  • that's what I remembered, also you need to pass your record to each member function
    – Nikko
    Oct 21, 2011 at 8:08
  • @Nikko: That is what happens behind the scenes in every object-oriented language, and fairly explicitly in Python and CLOS (common lisp).
    – Marcin
    Oct 21, 2011 at 8:24
5

Io is another prototype-based object-oriented language. It actually draws inspiration from several of the languages already mentioned in other answers.

Io is a dynamic prototype-based programming language. The ideas in Io are mostly inspired by Smalltalk (all values are objects), Self (prototype-based), NewtonScript (differential inheritance), Act1 (actors and futures for concurrency), Lisp (code is a runtime inspectable / modifiable tree) and Lua (small, embeddable).

4

Erlang. And yes, Erlang is an object-oriented language, as it fulfills all three points of the definition of OO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.