Data-driven programming
Programming paradigms |
---|
|
In computer programming, data-driven programming is a programming paradigm in which the program statements describe the data to be matched and the processing required rather than defining a sequence of steps to be taken.[1] Standard examples of data-driven languages are the text-processing languages sed and AWK,[1] where the data is a sequence of lines in an input stream – these are thus also known as line-oriented languages – and pattern matching is primarily done via regular expressions or line numbers.
Related paradigms
Data-driven programming is similar to event-driven programming, in that both are structured as pattern matching and resulting processing, and are usually implemented by a main loop, though they are typically applied to different domains. The condition/action model is also similar to aspect-oriented programming, where when a join point (condition) is reached, a pointcut (action) is executed. A similar paradigm is used in some tracing frameworks such as DTrace, where one lists probes (instrumentation points) and associated actions, which execute when the condition is satisfied.
Adapting abstract data type design methods to object-oriented programming results in a data-driven design.[2] This type of design is sometimes used in object-oriented programming to define classes during the conception of a piece of software.
Benefits and issues
While the benefits and issues may vary between implementation, there are a few big potential benefits and issues of this paradigm. Functionality simply requires that it knows the abstract data type of the variables it is working with. Functions and interfaces can be used on all objects with the same data fields, for instance the object's "position". Data can be grouped into objects or "entities" according to preference with little to no consequence.
While data-driven design does prevent coupling of data and functionality, in some cases, data-driven programming has been argued to lead to bad object-oriented design, especially when dealing with more abstract data. This is because a purely data-driven object or entity is defined by the way it is represented. Any attempt to change the structure of the object would immediately break the functions that rely on it.
As an example, one might represent driving directions as a series of intersections (two intersecting streets) where the driver must turn right or left. If an intersection (in the United States) is represented in data by the zip code (5-digit number) and two street names (strings of text), bugs may appear when a city where streets intersect multiple times is encountered. While this example may be oversimplified, restructuring of data is fairly common problem in software engineering, either to eliminate bugs, increase efficiency, or support new features. In these cases responsibility-driven design may be promoted as a better approach, where functionality and data can be coupled together, so functions don't have to deal with the data representation itself.[2]
Data-driven programming languages
References
- ^ a b c Stutz, Michael (September 19, 2006). "Get started with GAWK: AWK language fundamentals". developerWorks. IBM. Retrieved 2010-10-23.
[AWK is] often called a data-driven language -- the program statements describe the input data to match and process rather than a sequence of program steps
- ^ a b Wirfs-Brock, R.; Wilkerson, B. (1989). "Object-oriented design: a responsibility-driven approach". Conference Proceedings on Object-Oriented Programming Systems, Languages and Applications (New York: ACM): 71–75. doi:10.1145/74877.74885.