S2 programming language

S2 (Style System 2) is an object-oriented programming language developed in the late 1990s by Brad Fitzpatrick, Martin "Mart" Atkins, and others for the picture-hosting website code FotoBilder as well as the online journalling service LiveJournal in order to allow users full control over the appearance of their pages. S2 source code is compiled into Perl, which the webserver can then execute directly for individual web page requests.

The S2 system is, at its heart, completely general and can be used for almost any web application. There is no documentation for the implementation of S2 within other applications, although this is planned for the future.

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.

Contents

Language features

S2's structure closely resembles that of most imperative programming languages, and includes basic instructions such as variable assignments, arithmetic operations, conditional flow control 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 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.

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

Novel in S2 is 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 customisation wizard

The S2 web user interface 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 "customisation 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 [1] (http://lj-dev.livejournal.com/603894.html), two versions of Tic Tac Toe, and a game called "Pawns" [2] (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.

See also

External links

  • LiveJournal's S2 documentation (http://www.livejournal.com/doc/s2/)
  • History of S2 (http://www.livejournal.com/doc/s2/history.html) - outlines shortcomings of LiveJournal's previous style system, now referred to as S1.
  • S2 Resource Repository (http://www.livejournal.org/s2/) - contains various trinkets of S2 information that have no other home.
Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools