»Chapter 13. Comparing Style Systems

When we designed S2, there were specific features that we had in mind that would fix certain design flaws inherit with S1. The table belows explains some of the reasoning behind these changes.

FeatureS1S2
Flexible & Extensible

S1 forces users to define a template for each new type of view: recent entries, friends page, day view, calendar, etc. If we want to add a new view type, users have to basically write their style again.

In S2 you describe the formatting of objects, not the formatting of views. Thus, we can easily add new views in the future, and making a “recent” view pretty much makes all your other views automatically.

Safety

S1 is completely safe. It's so brain-dead that it can't be anything but but safe. You have to have some intelligence to be harmful.

The new style system is its own language that gets compiled into another language, and run on the webserver. Letting users run code on the server is inherently dangerous... it obviously has to be free of things like rm -rf /, but also, it has to be free from infinite loops, and anything that could consume large amounts of resources.

The S2 language does not have while loops, gotos, or any other control construct that would permit an infinite loops. It only has if/else blocks and foreach over finite lists.

There is also a limit on execution time of a resulting style, to avoid situations we can't easily trap such as functions calling each other in cycle, or badly-written recursion.

Speed

S1 is a CPU hog, doing tons of parsing, text munging and substitutions and run-time.

In the new system, S2 code will be parsed, checked, and compiled before the page is loaded. When a page is loaded in the future, the code will just be run, which will already be in the language that the LiveJournal server runs on. At the moment this is Perl but in the future we could write a PHP or Java servlet backend to the S2 compiler.

Internationalizablilty

S1 can support non-English languages and locales, but hardly:

  • The server injects a lot of English into S1 variables, especially in dates.
  • The calendar always begins weeks on Sunday.
  • The system to make nouns plural (2 Comments, 3 Replies) is very English-specific.
  • Porting a style to a new language involves forking the style and modifying away, losing all future changes to the original style. S1 forces users to define a template for each new type.

The new style system has been designed for internationalization. One of the S2 layers is an “i18n layer”, which overrides English method definitions from the core and sets properties, like the day weeks start on.

Ease of Use

S1 was never designed to be easy. It was designed for a few administrators to make styles, which would then be made public.

Wizards and tools generate S2 behind the scenes for most users. The hard-core users can write their own layouts and overlay other layers in the raw S2 language.