UML for functional programming?

This question was asked on Stackoverflow and ModelingLanguages and prompted me to attempt to make some persistent preconceptions about UML clearer. First of all: UML is not about modelling object-oriented software. Origin of object-orientation But maybe we should go back to what object-orientation is. OO (shorthand for object-orientation) is invented around 1970. Xerox had a…

This question was asked on Stackoverflow and ModelingLanguages and prompted me to attempt to make some persistent preconceptions about UML clearer. First of all: UML is not about modelling object-oriented software.

Origin of object-orientation

But maybe we should go back to what object-orientation is. OO (shorthand for object-orientation) is invented around 1970. Xerox had a group called the Software Research Group which was part of a think tank created to do research into the possible threats of the modern computer for Xerox’s prime business: copying machines. This group invented in a short period of years almost everything around what we now call the modern computer: displays with bit-mapped overlapping windows, a keyboard with a mouse to manipulate the objects on the display, icons to represent various types of information, and even the network to link all those computers together called ethernet.

To create the complex software that was needed to run those personal computers, an object-oriented programming language, as well as by the way an object-oriented operating system, was deemed necessary. Alan Kay originally coined the term “object-orientation” although he later stressed that a better term would have been “message-oriented” since he envisioned a complex system of interacting elements creating complex behaviour by sending messages to each other.
For more info on this original vision please read the august 1981 Byte magazine devoted to Smalltalk.

The assumption was that we needed a powerful new way of thinking about problems, to enable creating multiple orders of magnitude more complex software. But you see, this was not just about software. It was about a paradigm that helps in managing complexity. OO was just that, and it still is.

Origin of UML

When the UML effort started it only tried to merge a multitude of approaches that helped in visually representing those OO programs. So UML is not so different from OO. It is just a view on the same thing: a complex system.

UML introduced something new, however, and that was the meta model. Mainly for the tool developers, this meta model helps in designing the power of the OO modelling paradigm itself. It defines classes and metaclasses, properties and associations (as access paths for message passing).

The metamodel of UML is extensible. You can extend the metamodel with Profiles, effectively creating a specific set of language elements with a tightly defined semantics for a specific problem domain. This should not be confused with Domain Specific Languages (DSL’s), because a DSL specifies a set of elements or building blocks in the domain, for example the financial domain. A UML Profile contains the semantic definitions of the syntax used to describe those domains. For example you might create a Profile for Entity Relationship modelling. And you might define a Profile for functional languages.

Object-oriented mathematics

One of my first endeavours when I learned object-oriented programming was to create a planetarium. This has been a hobby of mine all my life. To simulate the movements of bodies in the solar system a mathematical model is used. The orbit of, say, the moon can be described with an equation with a lot of variables (to approximate the orbit, since there is no analytical solution of the many body problem in physics, that is until recently). My first thought was, well this is mathematics, I probably will have a hard time moulding the mathematical equations into objects and methods and messages. But to my delight I found this was not the case at all. Once I realised that my problem domain was mathematics, and specifically equations, the follow-up was easy and everything fell into place perfectly. I had Equation objects, CelestialBody objects using those to tell their location, and time nicely proceeding helping the celestial bodies to move.

To summarise: object orientation, and UML as a domain-independent language, can be used to describe any problem domain efficiently, and help with the complexities in those domains. And you are free to implement your solution in an object-oriented language like Smalltalk, or a functional language like Haskell. OO is domain-agnostic, and implementation-agnostic.

Tags:

Response to “UML for functional programming?”

  1. Steven Kelly

    Thanks, Rob, for your comments on this interesting topic. There’s a discussion here too: http://modeling-languages.com/uml-functional-programs-anybody/

    Object-orientation and metamodels are powerful concepts indeed. I find their history fascinating too, hopefully you don’t mind if I throw in a few of my own thoughts, even if some of them differ from yours.

    UML was indeed designed for modelling any discrete system, albeit with a strong OO focus – as a fusion of Rumbaugh’s Object Modeling Technique, Booch’s Object-Oriented Design, and Jacobson’s Object-Oriented Software Engineering, it couldn’t really claim to have nothing to do with OO! Although like any language it can be used to some extent for things it wasn’t designed for, most use these days is still connected to OO implementations, either as a sketch or a blueprint.

    As far as I know, the mouse wasn’t invented at Xerox PARC (founded 1970), but in the 1960s at Stanford Research Institute by Doug Engelbart and Bill English. Most people would say the first OO programming language was Simula 67.

    UML certainly didn’t introduce the metamodel. There were metamodels of object-oriented modeling languages well before UML. In 1993 MetaEdit offered metamodels and modeling support for OODA, OOAD and OMT, and by the first version of MetaEdit+ in 1995, there were already OOA/OOD, FUSION, OODA, OMT, Moses, OSA and OODLE – all before the first full UML draft (0.9 in June 1996). Some other modeling tools, even some fixed to a particular language, also used metamodels, either explicitly or under the covers.

    UML came to the metamodel party rather late and with a surprising date – the Meta Object Facility, born out of work on CORBA and eventually shoehorned to be a subset of UML intended to allow UML to represent itself (mostly for documentation). The first mechanism for supporting UML extension, profiles, is not really a metamodeling mechanism, more just simple tagging. Later MOF and its subsets were promoted by the OMG as ways of extending UML by metamodeling. In practice that doesn’t seem to have happened much; instead, the OMG itself has used MOF as a way of specifying various more or less UML-related languages for business processes or system modeling.

    UML is able to describe many domains, including ones outside its initial area, but I wouldn’t say it is efficient for those. Similarly MOF isn’t particularly good at describing languages other than UML – MOF-based tools seem to require 10-50x the amount of work as tools based on concepts designed from the ground up for metamodeling (http://tinyurl.com/dsm13ElK – and that study was by MOF experts on a MOF-based language!).

Leave a Reply

Your email address will not be published. Required fields are marked *