Objective-J
Encyclopedia
Objective-J is a programming language
developed as part of the Cappuccino
web development framework. Its syntax is nearly identical to the Objective-C
syntax and it shares with JavaScript
the same relationship that Objective-C has with the C
programming language: that of being a strict, but small, superset; adding traditional inheritance
and Smalltalk
/Objective-C style dynamic dispatch
. Pure JavaScript, being a prototype
-based language, already has a notion of object orientation and inheritance, but Objective-J adds the use of class-based programming
to JavaScript.
Programs written in Objective-J need to be preprocessed before being run by a web browser's JavaScript virtual machine. This step can occur in the web browser at runtime or by a compiler
which translates Objective-J programs into pure JavaScript code. The Objective-J compiler is written in JavaScript; consequently, deploying Objective-J programs does not require a web browser plug-in.
The following example shows the definition and implementation in Objective-J of a class
named Address; this class extends the root object CPObject, which plays a role similar to the Objective-C's NSObject. This example differs from traditional Objective-C in that the root object reflects the underlying Cappuccino
framework as opposed to Cocoa
, Objective-J does not use pointers and, as such, type definitions do not contain asterisk characters (in Objective-C, all objects must be dynamically allocated
). In addition, instance variable
definitions are never done in the @implementation file.
As with Objective-C, class method definitions and instance method definitions start with '+' (plus) and '-' (dash), respectively.
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
developed as part of the Cappuccino
Cappuccino (Application Development Framework)
Cappuccino is an open source application development framework for developing web applications that look and feel like desktop applications on Mac OS X. Cappuccino was developed by University of Southern California graduates Francisco Tolmasky, Tom Robinson and Ross Boucher, who are also the three...
web development framework. Its syntax is nearly identical to the Objective-C
Objective-C
Objective-C is a reflective, object-oriented programming language that adds Smalltalk-style messaging to the C programming language.Today, it is used primarily on Apple's Mac OS X and iOS: two environments derived from the OpenStep standard, though not compliant with it...
syntax and it shares with JavaScript
JavaScript
JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....
the same relationship that Objective-C has with the C
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
programming language: that of being a strict, but small, superset; adding traditional inheritance
Inheritance (computer science)
In object-oriented programming , inheritance is a way to reuse code of existing objects, establish a subtype from an existing object, or both, depending upon programming language support...
and Smalltalk
Smalltalk
Smalltalk is an object-oriented, dynamically typed, reflective programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human–computer symbiosis." It was designed and created in part for educational use, more so for constructionist...
/Objective-C style dynamic dispatch
Dynamic dispatch
In computer science, dynamic dispatch is the process of mapping a message to a specific sequence of code at runtime. This is done to support the cases where the appropriate method can't be determined at compile-time...
. Pure JavaScript, being a prototype
Prototype-based programming
Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior reuse is performed via a process of cloning existing objects that serve as prototypes. This model can also be known as classless, prototype-oriented or instance-based programming...
-based language, already has a notion of object orientation and inheritance, but Objective-J adds the use of class-based programming
Class-based programming
Class-based programming, or more commonly class-orientation, refers to the style of object-oriented programming in which inheritance is achieved by defining classes of objects, as opposed to the objects themselves .The most popular and developed model of OOP is a class-based model, as opposed to an...
to JavaScript.
Programs written in Objective-J need to be preprocessed before being run by a web browser's JavaScript virtual machine. This step can occur in the web browser at runtime or by a compiler
Compiler
A compiler is a computer program that transforms source code written in a programming language into another computer language...
which translates Objective-J programs into pure JavaScript code. The Objective-J compiler is written in JavaScript; consequently, deploying Objective-J programs does not require a web browser plug-in.
Applications
The first widely known use of Objective-J was in the Cappuccino-based web application 280 Slides, which was developed by 280 North itself. Even though Objective-J can be used (and has been designed) independently from the Cappuccino framework, Objective-J has primarily been invented to support web development in Cappuccino.Applications designed using the Cappuccino Framework
- Mockingbird
- PicEngine
- GithubIssues
- TimeTable
- Enstore
- Almost At
- Akshell - Online JavaScript Web-App IDE
- Archipel Project - Virtual machine orchestrator
Syntax
Objective-J is a superset of JavaScript, which means that any valid JavaScript code is also valid Objective-J code.The following example shows the definition and implementation in Objective-J of a class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
named Address; this class extends the root object CPObject, which plays a role similar to the Objective-C's NSObject. This example differs from traditional Objective-C in that the root object reflects the underlying Cappuccino
Cappuccino (Application Development Framework)
Cappuccino is an open source application development framework for developing web applications that look and feel like desktop applications on Mac OS X. Cappuccino was developed by University of Southern California graduates Francisco Tolmasky, Tom Robinson and Ross Boucher, who are also the three...
framework as opposed to Cocoa
Cocoa (API)
Cocoa is Apple's native object-oriented application programming interface for the Mac OS X operating system and—along with the Cocoa Touch extension for gesture recognition and animation—for applications for the iOS operating system, used on Apple devices such as the iPhone, the iPod Touch, and...
, Objective-J does not use pointers and, as such, type definitions do not contain asterisk characters (in Objective-C, all objects must be dynamically allocated
Malloc
C dynamic memory allocation refers to performing dynamic memory allocation in the C via a group of functions in the C standard library, namely malloc, realloc, calloc and free....
). In addition, instance variable
Instance variable
In object-oriented programming with classes, an instance variable is a variable defined in a class , for which each object of the class has a separate copy. They live in memory for the life of the object....
definitions are never done in the @implementation file.
@implementation Address : CPObject
{
CPString name;
CPString city;
}
- (id)initWithName:(CPString)aName city:(CPString)aCity
{
self = [super init];
name = aName;
city = aCity;
return self;
}
-(void)setName:(CPString)aName
{
name = aName;
}
-(CPString)name
{
return name;
}
+(id)newAddressWithName:(CPString)aName city:(CPString)aCity
{
return elf alloc] initWithName:aName city:aCity];
}
@end
As with Objective-C, class method definitions and instance method definitions start with '+' (plus) and '-' (dash), respectively.