Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Semantics and the Evolution of Specialized Languages : Page 2

Precise semantics for data elements allow sets of highly specialized languages to evolve quickly, giving you concise, little languages as an alternative to procedural languages for creating business applications.

Little Languages
Take a look at some examples of little languages in common use today, and see how they relate to Darwin's finches:

Using a CSS rules engine for semantic markup. Some HTML developers have created a style of HTML coding called semantic HTML or semantic markup. Semantic HTML attempts to put HTML in the body of a web page and places the presentation aspects of the document into another language: cascading style sheets (CSS). CSS in an interesting case study in that, similar to Darwin's finches, it evolved to meet a specialized need. CSS is a declarative language rather than a general-purpose language because it specifies a set of rules in an abstract way. CSS specifies a set of if statements (a pattern match) and applies the appropriate attributes in the body of an HTML document if the pattern match is true. Here is a sample CSS:

/* sample CSS */ body { font-family: Arial, Helvetica, sans-serif; font-size: 75%; margin: 0; padding: 0; width: 1000px; } h1 { color: blue; padding: 0 15px; }

The structure of this CSS file is a set of if-then rules. The first rule sets properties for all HTML tags inside the body. The second rule applies properties to only HTML tags under heading level 1 (h1). Note that both the body and h1 levels have a padding attribute, but because h1 is more specific its rule will override the body's padding property. Maintaining CSS files and the entire web site is much easier when you use defaults and overrides.

What is important about the CSS approach is not the syntax of the file (you could use XML format), but the fact that CSS leaves out many constructs that would make CSS harder to learn. If you learn how to use the pattern-matching rules, you can write a CSS file. There are fewer than a dozen ways to match the patterns, which means that a web designer can focus on the rules of the CSS file without being concerned as to how the HTML is created.

Like Darwin's finches, CSS has evolved from precise and consistent requirements. Web pages live in trees of data, and you can apply rules to subsets of these trees, regardless of the specific HTML tags that are used. When there are large numbers of people and organizations trying to solve similar problems, small yet semantically precise languages will evolve to fill a niche. XML Schema for capturing document requirements. The XML Schema language is also cited frequently as a critical piece in declarative systems. XML schemas are used not only to validate documents transmitted between computers and organizations, but they also serve as mini models in model-driven development (see the sidebar, "Business Requirement Capture").

XForms for presenting forms. XForms is one of the newest W3C standards that is gaining widespread adoption. XForms has been brewing at the W3C for over five years. The specifications were delayed by the need to fit precisely with XPath, XML Schema, and CSS. XForms appears to work most efficiently when the development environment utilizes REST interfaces and native XML databases. The XForms specification contains only 21 data elements, and because XForms works with XML Schema, a small Extensible Stylesheet Language Transformations (XSLT) file can transform your XML schema directly into an XForms application.

XForms and Asynchronous JavaScript and XML (AJAX) present an interesting contrast of what happens when you use a procedural approach to add new features to existing systems. There are many books written about technologies such as AJAX because although useful, the implementation is complex. A web programmer must define all of the details of how updates are made to a web application. In contrast, by using XForms the functionality of asynchronous updates is defined by a single XForms data element: submit. The code to perform rich behavior is brief, concise, standardized, and abstract.

XSLT for transformation rules. When you think of the king of transformation using pattern matching for XML, XSLT is the first language that comes to mind. XSLT is a widely adopted standard that is in use in many software development environments and executes directly in most browsers. It allows structured XML data to transform into almost any other XML representation. XSLT relies on a series of templates that match pattern rules. If a pattern matches and a rule fires, fragments of XML are placed in an output tree. The exact order in which the rules fire is determined by the structure of the incoming data.

XSLT is powerful in that simple transformations such as adding, removing, or changing XML structures (even on large data sets) is just a few lines of XSLT code. Good programmers using XSLT don't create subroutines with names that must be chosen carefully to document meaning to future developers. They rely on the fact that both input and output formats have meaning to a wide audience. Here is a list of sample XML transform elements:

  • call-template
  • choice
  • element
  • for
  • if
  • import
  • output
  • param
  • sort
  • stylesheet
  • template
  • text
  • value-of
  • when
  • with-param

SQL for data selection from tables. Structured Query Language (SQL) began with a small vocabulary in which basic operations of data selection from tables were required: SELECT, INSERT, UPDATE, and DELETE. Although many SQL languages have been extended to include features such as stored procedures, looping, and conditional expressions, the core functionality of the language is still very small.

XQuery, XML's SQL. XQuery is a simple language that contains only five important tags and header tags for declarations and imports. XQuery can perform all of the same operations that standard SQL can perform (selection, joins, and so on), but XQuery works on trees of data rather than tables. XQuery's five main tags are for, let, order, were, and return, which are known collectively as a FLOWR (pronounced "flower") expression. XQuery also has functions for selecting data from collections and documents.

XPath for data selection and functions. XSLT, XForms, and XQuery all depend on data-selection expressions using the XPath language. Although XPath is a small language with just a few key concepts it also has a rich library of functions for manipulating strings, numbers, and dates. Many declarative systems leverage XPath data selection techniques, and XPath's use is relatively consistent across these languages. Nonetheless, familiarity with XPath seems to be a vital skill in the world of declarative languages, even though it is not taught in most computer-science curriculums today. Lack of knowledge of XPath remains a common reason many people give for being reticent about moving toward declarative systems.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date