S2 programming language
Encyclopedia
S2 is an object-oriented
Object-oriented programming
Object-oriented programming is a programming paradigm using "objects" – data structures consisting of data fields and methods together with their interactions – to design applications and computer programs. Programming techniques may include features such as data abstraction,...

 programming language
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 in the late 1990s by Brad Fitzpatrick
Brad Fitzpatrick
Bradley Joseph "Brad" Fitzpatrick , is an American programmer. He is best known as the creator of LiveJournal and is the author of a variety of free software projects such as memcached....

, Martin "Mart" Atkins, and others for the online journaling service LiveJournal
LiveJournal
LiveJournal is a virtual community where Internet users can keep a blog, journal or diary. LiveJournal is also the name of the free and open source server software that was designed to run the LiveJournal virtual community....

 in order to allow users full control over the appearance of their pages. S2 source code is compiled into Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, which the webserver can then execute directly for individual web page requests
Hypertext Transfer Protocol
The Hypertext Transfer Protocol is a networking protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web....

.

The S2 system is, at its heart, completely general and can be used for almost any web application
Web application
A web application is an application that is accessed over a network such as the Internet or an intranet. The term may also mean a computer software application that is coded in a browser-supported language and reliant on a common web browser to render the application executable.Web applications are...

; however there exists no documentation for the implementation of S2 within other applications, which ties it relatively closely to LiveJournal.

This article will make use of LiveJournal's implementation of S2 for examples. A link to detailed documentation about this implementation can be found at the bottom.

Language features

S2's structure closely resembles that of most imperative programming
Imperative programming
In computer science, imperative programming is a programming paradigm that describes computation in terms of statements that change a program state...

 languages, and includes basic instructions such as variable assignments, arithmetic operations, conditional flow control
Flow control
In data communications, flow control is the process of managing the pacing of data transmission between two nodes to prevent a fast sender from outrunning a slow receiver. It provides a mechanism for the receiver to control the transmission speed, so that the receiving node is not overwhelmed with...

 and for loops over finite sets (however, it distinctly lacks while loops). Being object-oriented, S2 allows the declaration of classes with members and methods, but global (non-class-specific) functions can also be defined. Recursion is allowed, but nesting functions is not.

Layers and properties

A distinguishing feature of S2 is that source code
Source code
In computer science, source code is text written using the format and syntax of the programming language that it is being written in. Such a language is specially designed to facilitate the work of computer programmers, who specify the actions to be performed by a computer mostly by writing source...

 is organised into individual layers, of which there are six different types (core, i18nc, layout, i18n, theme and user). These layers form a tree-like structure.

At the root lies the core layer, a layer which specifies all the classes and their methods which are specific to the website on which S2 is being used. In the case of LiveJournal, these classes represent individual journal views (Recent Entries, Archive, etc.) and site-related objects (users, journal entries, etc.). It provides simple default implementations of all the methods, but also global functions that are of general use. Some of the functions are specified as being "built-in" functions and are implemented in Perl in the S2 subsystem; all other functions are implemented in S2 itself and are compiled into Perl code by the S2 compiler.

The S2 language introduces a concept of properties — these are variables that are not specific to a particular object or class, but to a layer. Such a property can be a textual string, an integer number, a hexadecimal colour code, etc. The core layer, for instance, defines textual string properties to hold user-visible text in the English language
English language
English is a West Germanic language that arose in the Anglo-Saxon kingdoms of England and spread into what was to become south-east Scotland under the influence of the Anglian medieval kingdom of Northumbria...

.

Subordinate to the core layer are the i18nc ("core internationalisation") layers, which allow for the textual string properties in the core layer to be overridden with translations into other languages.

Also subordinate to the core layer are the layout layers. A layout layer specifies a particular site layout (journal layout in the case of LiveJournal), and it may provide new properties that influence the look and behaviour of the layout in various ways. A layout layer normally overrides almost all of the methods defined in the core layer, and it may introduce new ones to perform certain layout-specific tasks. If a core-defined method is called which is not overridden in the layout layer, but the same method is overridden for a superordinate class, then this superordinate method is called, rather than the class-specific default implementation in the core layer.

The remaining three types of layers — i18n layers, theme layers and user layers — are all subordinate to a specific layout layer. In general, all three of them can override both properties and functions/methods from the layout layer, but their intended purpose varies. i18n are provided to internationalise the layout; this is to allow the layout to be used by speakers of other languages, but not primarily to provide a way to customise the user-visible text. theme layers can be used to provide suggested sets of values for the properties of a layout. A common application of this is to create aesthetically consistent colour themes, but in principle non-colour properties (fonts, sizes, etc.) can also be overridden in a theme layer. user layers, finally, are meant to store a particular user's preferences with regard to the values of the properties. The user layer ultimately has the "final say" on the values of the properties.

Internationalisation

As mentioned in the previous section, i18nc layers are used to translate the core layer, while i18n layers are used to translate a layout. In its simplest form, such an internationalisation layer overrides textual string properties in order to replace English text with a translation into another language.

However, often the intricacies of languages require more sophisticated mechanisms, which is why the internationalisation layers sometimes override entire functions. For example, a plural-mapping function is provided which specifies how many and which strings a language uses following an integer number.

Documentation

S2 incorporates the idea of providing documentation for a class, method, function or property directly within the source code, separate (machine-distinguishable) from conventional comments. Small strings of explanatory text can be added after the header of a class, method, function or property, and they can be used to generate documentation.

At the time of this writing, however, none of these strings are actually used, except for those associated with properties, which appear in the customisation wizard; see below. An i18n layer can override these documentary strings for properties in order to allow for speakers of other languages to be presented with explanations of the available options in their language.

The customization wizard

The S2 web user interface
User interface
The user interface, in the industrial design field of human–machine interaction, is the space where interaction between humans and machines occurs. The goal of interaction between a human and a machine at the user interface is effective operation and control of the machine, and feedback from the...

 allows users to change the values of the properties of a layout without requiring them to write actual S2 source code. This interface is termed the "customization wizard", and it creates a user layer which stores the user's preferred values of the properties.

Unintended uses of S2

S2 was entirely designed to be a web layout programming language. It had not originally been anticipated that it would soon be used to create "geeky" applications.

In particular, at the time of this writing, four games have been written in S2: Towers of Hanoi http://lj-dev.livejournal.com/603894.html, two versions of Tic Tac Toe, and a game called "Pawns" http://lj-nifty.livejournal.com/93092.html. One of the Tic Tac Toe versions has been embedded into a journal style as a box in a side-bar.

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK