Chapter 17: Dynamic Languages and XML


Overview

Although much attention is currently directed to Java and .NET, many developers work with dynamic programming languages such as Perl, Python, and Ruby. Dynamic languages differ from languages such as Java or C# in that the variables are usually not fixed to a particular type. For example, the following code fragment is perfectly valid in a dynamic language:

      var x;      x = 5;      x = "testing"; 

Notice that the variable declaration does not identify the type of the variable, and that it may be used to store numeric, string or even object values. In most dynamic languages, the variable declaration is not even needed: You can simply begin to use a variable. Some languages, such as Python and Ruby, go even further, supporting what has become known as duck typing. With duck typing, a variable is treated as a particular type as long as it supports the same method and property calls as the desired type does. That is, if a block of code is expecting a method called toString, then any object may be used as long as it supports a toString method. This demonstrates a powerful feature in dynamic languages, the ability to rapidly prototype and test a block of code. (The term duck typing derives from the old expression, "If it walks like a duck, and quacks like a duck, it must be a duck.")

Dynamic languages are frequently also known as scripting languages, as many of them are interpreted languages that may be used directly from the command-line, without requiring a separate compilation step. These two features-dynamic variables and flexibility in release-outline the benefits many developers see in dynamic languages: It is very easy to rapidly develop and iterate applications written in dynamic languages. In addition, some programming concepts are much more difficult to implement in statically typed languages when compared with dynamic languages.

Dynamic languages are also ideal for manipulating XML. Most have strong text-manipulation capabilities, and libraries for processing XML in a variety of ways. This chapter looks at three of the most commonly used dynamic languages (Perl, Python, and Ruby). For each of these languages, it will show some of the common methods of using these languages to read and write XML and related technologies.




Professional XML
Professional XML (Programmer to Programmer)
ISBN: 0471777773
EAN: 2147483647
Year: 2004
Pages: 215

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net