Diagnosing Java code: Designing an Extensible Application, part 4th

Source: Internet
Author: User

In last month's column, if you had the following points, you would understand that the availability of the underlying code would not be a problem:

How to identify configuration scripts

How to choose which configuration to allow

Identify which environment requires black box scalability

Measuring the build complexity of scalability

When you provide this extensibility to the configuration script, you are actually building a language.

You also recognize that using s-expression is an effective way to quickly build a configuration language, given the black box scalability of your application. We'll delve into the s-expression in this article and provide an example of how these s-expression can be used to quickly and easily establish a configuration language for a particular application.

Some knowledge about S-expression

Let's recall that s-expression is a syntactic representation of the list of elements separated by parentheses. There are three forms of s-expression:

Empty element list

Non-empty element list

A single atomic element (such as a word)

S-expression is useful as a configuration language because they are easy to parse. The general S-expression parser reads the data into the program, and then the program checks to see if the expression adheres to more specific syntax constraints. In this way, we get all the benefits of parsing input-such as early error-input detection and increased security--eliminating the energy costs and overhead of writing and maintaining a regular parser. Similarly, the output of an error message can be precise and helpful when tracing the source of a syntax error, unlike the parser builder constructs.

"S" is more advantageous than XML

As I mentioned in the previous article, many of the benefits of using s-expression can also be obtained by using an xml-based configuration language. The main advantage over XML based on the S-expression configuration language is that it is very lightweight and fast-built.

Similarly, in many cases, s-expression configuration scripts are easier to read and edit than equivalent xml-based scripts. When we discuss some of the following examples based on s-expression scripts, consider what they look like in XML notation.

Example: adding macro support to the editor

Suppose we want to add simple macro support to a text editor, allowing users to define complex sequences of basic operations. We may even want to add support for loops or recursive constructs.

Here is an example of a possible scenario for a macro:

Listing 1. A simple macro

(define (cutAndPasteAtEnd)
(sequence
  (cut HIGHLIGHTED_TEXT)
  (move-to END_OF_DOCUMENT)
  (paste CLIPBOARD))

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.