Flylib.com

Books Software

 
 
 

Why Use a Scripting Language?


Why Use a Scripting Language?

A computer language is akin to a tool in the toolbox of any tradesman. Each tool is designed for a specific task, be it a hammer , a screwdriver, or wrench. Tools are an aid to productivity, but you only get the benefits of the tool by using it for the right task; hammers bang in nails and screwdrivers are for screws .

The same toolbox concept applies to software engineering. The choice of programming language for undertaking a specific task has a bearing on the developer's productivity.

Java is obviously the main language on any J2EE project. Nevertheless, introducing concepts and language constructs from other programming paradigms can help when tackling areas of functionality to which Java is not ideally suited.

Java is a strongly and statically typed programming language. By contrast, scripting languages tend to be weakly typed and highly dynamic.

Strong typing is important for production systems, as the compiler scrupulously checks for any unintended type conversions, raising them as an error before the system is even run.

Mission-critical systems, such as military software and air- traffic-control systems tend to use Ada , a language developed by the Department of Defense that is considerably more stringent on type safety than Java. For these systems, the presence of an undetected defect could have lethal consequences.

Type safety is therefore a mechanism for assisting in the development of reliable and robust software, and it is an important language feature for any software that requires high levels of reliability.

However, not all software developed on an enterprise project falls into this category, and there are many extraneous tasks surrounding the development of the main application for which less scrupulous languages are better suited. This is where scripting languages enter the picture.

Here are some examples of these additional project tasks that can benefit from the use of a scripting language:

  • Exploratory prototyping of user interfaces

  • Writing code generators

  • Writing automated test scripts

  • Controlling batch jobs

  • Generating ad hoc reports

  • Automating build and release procedures

The next section considers the features of a language that make it well suited for scripting purposes.


Features of a Scripting Language

Scripting languages lack the formal semantics of conventional languages like Java. They are loosely typed and highly dynamic, two features which make them ideal for noncritical project tasks .

The main features of a scripting language include

  • High level and informal language constructs

  • Expressive syntax

  • Loose typing

  • Interpreted as opposed to compiled

Over the years , the software industry has spawned a large number of languages that exhibit these features, a testimony to the benefits of scripting languages. There are many well-known and highly regarded examples:

  • Python

  • Perl

  • Ruby

  • Tcl

The biggest question facing a J2EE project team is which language to choose. The following lists some points to consider when making the choice. Does the language

  • Complement the experience of the project team?

  • Offer crossplatform support?

  • Integrate with Java, allowing access to existing Java classes?

In addition to these points, characteristics such as the language's maturity, performance, and quality must also be considered .

Team Experience

With a number of languages to choose from, looking to assess the expertise of members of the team with a particular scripting language is an important consideration. Although offering powerful language constructs and informal semantics, scripting languages are not easy to learn. They employ many concepts that are not available in Java, meaning training time must be set aside to bring a developer up to speed.

Tip

If the team is skilled in a language such as Python, then adopting Jython, the Java equivalent, is one way of leveraging that previous Python experience.


Investment in the education of a team in a particular scripting language should be part of a company's wider adaptive foundation for rapid development. Standardization on a common scripting language across project teams allows the sharing of scripts and modules between groups. Staff will also be available in a mentoring role for projects using the scripting language for the first time.

Crossplatform

Not all of the main scripting languages are crossplatform. Scripts can be migrated between machines with different operating systems and architectures only if an interpreter for the language exists for the target platform.

Java offers crossplatform support, and it would be preferable if a scripting language were available that offered the same capability. Language builders have addressed this problem by developing scripting languages that execute under a Java Virtual Machine (JVM). Thus, the language is supported on any platform that can host a JVM.

Several languages are available that fall into this category. Table 9-1 lists some of the open source offerings.

Table 9-1. Scripting Languages for the Java Platform

Name

Description

Reference

Groovy

New language that combines many popular features from languages such as Smalltalk, Python, and Ruby

http://groovy.codehaus.org/

Jacl

Jacl (pronounced Jackal ), or the Java Command Language, is a Java implementation of the Tcl scripting language

http://www. scriptics .com/software/java/

JRuby

Java implementation of the popular Ruby scripting language

http:// sourceforge .net/projects/jruby

Jython

Java version of the object-oriented scripting language Python

http://www.jython.org

Rhino

A JavaScript interpreter written entirely in Java

http://www.mozilla.org/rhino/


Several of the JVM scripting languages are implementations of popular scripting languages; for example, Jython brings Python to the Java platform, and JRuby is a Ruby implementation. Other languages, such as Groovy , have been created specifically for the Java platform.

Integration with Java Classes

For tasks such as writing ad hoc reports , producing automated test cases, or building user -interface prototypes , the scripting language must have the ability to work directly with Java objects.

This is the main reason for choosing a Java-based scripting language over one of the established languages. Without Java integration, many common scripting tasks are far more cumbersome, thereby negating the use of the scripting language.

To appreciate the relationship between scripting language and Java, the next section introduces Jython, a scripting language that is tightly integrated with the Java platform.