-
18
pages
-
English
-
Documents
Description
1Evolutionary Programming and Gradual Typing in ECMAScript 4
(Tutorial)
29 November 2007
Lars T Hansen, Adobe Systems
(lhansen@adobe.com)
Introduction
ECMAScript 4 (ES4) provides a range of facilities for evolutionary programming – evolving a program in
stages from a simple script to an ever larger and more reliable software system. The most important facility
for evolutionary programming is the gradual type system; also important are namespaces and packages,
union types, generic functions, and reflection.
Evolutionary programming has two aspects: making the code more robust, and working around robustness
that gets in the way but cannot be removed.
The robustness of a program is improved by adding invariants to the program, or equivalently, restricting
the range of its behavior. Starting with an untyped program built on ad hoc extensible objects and hand-
coded data validation—a typical ES3 program—we can apply structural types and type annotations at key
points to make validation faster and more reliable. We can also apply structural types to objects in order to
fix their properties, thereby providing integrity and making type checking and data validation even faster.
We can rewrite ad hoc typed objects as instances of classes when a new level of integrity is required, and
when program-wide protocols are introduced the classes can even be constrained to match separately
defined interfaces. Finally, we can use packages to hide ...
(Tutorial)
29 November 2007
Lars T Hansen, Adobe Systems
(lhansen@adobe.com)
Introduction
ECMAScript 4 (ES4) provides a range of facilities for evolutionary programming – evolving a program in
stages from a simple script to an ever larger and more reliable software system. The most important facility
for evolutionary programming is the gradual type system; also important are namespaces and packages,
union types, generic functions, and reflection.
Evolutionary programming has two aspects: making the code more robust, and working around robustness
that gets in the way but cannot be removed.
The robustness of a program is improved by adding invariants to the program, or equivalently, restricting
the range of its behavior. Starting with an untyped program built on ad hoc extensible objects and hand-
coded data validation—a typical ES3 program—we can apply structural types and type annotations at key
points to make validation faster and more reliable. We can also apply structural types to objects in order to
fix their properties, thereby providing integrity and making type checking and data validation even faster.
We can rewrite ad hoc typed objects as instances of classes when a new level of integrity is required, and
when program-wide protocols are introduced the classes can even be constrained to match separately
defined interfaces. Finally, we can use packages to hide ...
-
Publié par
-
Langue
English