Is UML a programming language?
Asked Answered
E

13

20

Could UML be used to program a computer system on its own, without a supporting implementation language, e.g. diagrams straight to machine code (maybe via C or C++ etc), without human coding intervention.

Eureetloir answered 21/3, 2010 at 3:5 Comment(8)
Google Model Driven Development.Inquiring
Not talking simple Template generation people, but full on, seat of your pants, wow stuff, straight to executable code.Eureetloir
@John Thanks John, great link, keep up the good work fella, attaboy :)Eureetloir
@WeNeedAnswers: smart comment, not.Inquiring
@John, Sorry john, I thought you were being funny. I thought there was a comma between google, and Model :) I thought that you were saying, "you google Model Driven Development".Eureetloir
@WeNeedAnswers: I was in a hurry and though I'd introduce the term "model driven development" into the discussion. Thought you might have fun looking that up until I got back.Inquiring
@John: All of the work I mention in my answer is based on concepts of Model Driven Architecture / Model Driven Development.Arette
@Eric: I know. I'm familiar with it. When I added my comment, your answer wasn't there yet.Inquiring
A
25

I'm going to go against the general trend and share an experience that shows what UML can do today, and what some future version of UML (or another modeling approach) could be.

First a bit of history.

Way back when, people programmed computers in assembly (not going ALL the way back here). Then along came higher level languages like C and Basic. Programmers that were very good in assembly argued that you can't fully express everything the processor is capable of doing (in an optimized manner) in a higher level language. In fact, they were right. Some things were much less optimal from a memory and performance perspective in higher level languages because you could not fully control the instructions issued to the processor.

The thing is, higher level languages provided a much more abstract form of expression. So, they caught on and after a while, people didn't really care that you could not fully control every aspect of the processor because the developers were so much more productive (Moore's Law also helped).

Similar rounds happened with object oriented languages, and again with managed languages. Each time, a higher level of abstraction became available and eventually won out because it was more efficient to use as a developer. In fact, generally inefficiencies in the higher levels of expression disappear as compilers become better and optimization techniques improve.

Model driven development is a higher level of expression. You cannot fully represent any code you could write in, say, C# or Java. Especially not out of the box. However, it is possible to generate a very substantial portion of an application directly from a UML model.

I led the UML-based code generation effort for several rather large projects. In many cases, we could generate 30% to 60% of the entire source code of the (real life, enterprise-class) applications. And that's just with a small team writing generators for a particular domain. Eventually, an entire industry will be behind tools to generate more and more of real-life application from models.

That is the next step in the natural evolution we have seen in our industry time and time again, ever since the first assembly codes abstracted opcodes (there was probably something before that, but that was before my time).

Arette answered 21/3, 2010 at 3:29 Comment(18)
great answer. Was it autogenerated :)Eureetloir
@Eric, only joking thank you, how long does the 40% of the code that needs to be human develop take? Is there a problem with the transition between machine to human, what is the error rate of the code generated (funny symbols and the like)?Eureetloir
@WeNeedAnswers: It took a long time (2-3 months with 3 people) the first time we ever did it. The last time I did it (with the benefit of experience and previously developed tooling) it took around a month with 3 people. The first 10%-15% comes very fast. The effort increases more than linearly (but not exponentially) the more you want to generate, because you tend to do the easy stuff first.Arette
thats impressive stuff. Thanks for your input. real food for thought. What's your opinion of The M programming language (Domain Language), is it a winner, or is it just reinventing the wheel, and not really solving the interface between Domain expert and Programmer, because the domain language has to be developed first. I Don't get it. Why do we need another domain describing tool when in my opinion that is what UML was designed for.Eureetloir
@WeNeedAnswers: A major shortcoming of UML is the design by committee. There's many ways to accomplish the same thing, making standardized code generation hard. I have not spent much time with Microsoft's DSL's, but on the surface M seems to solve that problem by passing it to each entity that wants a DSL. Not a lot of leverage in that. I suspect at some point, a more standardized modeling approach will establish itself as a basis for wide-spread generation as industry effort/open source/... Might be based on M. Probably be many flavors just as there are many programming languages.Arette
Be careful with your history. Object orientation and "managed" languages were both available in the '70s. Progress has been more incremental than step-like, and levels of abstraction can co-exist peacefully for a long time because they strike different balances in the power/programmer-time/compactness/maintainability space.Berezina
@dmckee: I know it's a vast generalization (as must be any brief history of computer science). I actually worked on Smalltalk way back when it first came out, and found it great for a certain domain of problems.Arette
There are already many flavors of more standardized modeling languages: web page designers, Matlab Simulink, business workflows, LEGO Mindstorm just off the top my head. All work rather fine in their respective niches. UML is a different story - it's a low-level modeling solution that doesn't introduce any new concepts. It allows to you to draw classes and sequences instead of coding them - but it's just different method of input, not really a new, more abstract level. (note: I do use UML for documentation a lot, but code generation from it always seemed to be lots of problems for no benefit).Clergy
@ima: In UML (done properly), I can use one requirement node to express (for example): The First Name field must be 40 characters long or less, that condition needs to be enforced in every UI field that is a first name, business objects that contain a first name (usually just one), and by the way, generate DDL for that column that allows for 40 characters. By creating one requirement node, I specify behavior for the UI, business and data layers. That's more abstract than standard languages in my book.Arette
That is not an abstraction of UML, it is an abstraction of your code generator. Just as well it could be an abstraction of a library or framework used directly from code (and there is number of options here, for defining data validation only once).Clergy
For example: placing UI control visually instead of specifying numbers is a new level of abstraction that can't be achieved from raw code, whatever libraries you use.Clergy
I'm not saying that UML code generation is completely useless, it is a language in it own right, even if not radically new. It is more suitable for certain kinds of problems, less for others - just not enough to say it's generally superior to writing code.Clergy
@Ima: I agree, it's not generally superior to writing code (now). It takes quite a bit of initial investment to get a good degree of code generation. However, I think that executable models raise the level of abstraction significantly. UML + My code generation is how I have personally achieved executable models. There are many other efforts, all in their infancy. Given the past evolution of computer science, it's very reasonable to expect that some of those infants will grow up to be the tools we use tomorrow.Arette
Been a long tome coming though Eric, I think that only now the tooling is making inroads. UML is great and I feel is complete as a language. It comes into its own when expressing ideas to non-technical people and really captures the essence of a system without worrying about the implementation engine. Although if your technical and have some coding skill, it does feel as if the problem is being taken away from you and handed to people who don't understand the developed code. Also the dreaded impedance mismatch (OO/DB) always raises its ugly head.Eureetloir
@WeNeedAnswers: Yes, it's been a long time coming. There are actually people working on executable UML (en.wikipedia.org/wiki/Executable_UML), so at least in that context it's probably a fairly complete language. I have worked for people that have made strategic decisions for .NET or Java and so needed to generate code for that platform so never really investigated xUML, but it may be worth it for you to look at. Then again, some of the early C++ compilers were pre-compilers that turned C++ into C, which was then compiled. I'm filling that same role with my stuff :-)Arette
UML is based on MOF and look at many DSLs that are developed on top of MOF (EMF).Shurlocke
The problem with executable UML is unclear semantics of UML and the general problem of UML not being suited for programming, it was ment as a notation. However as I tried to mention above, UML is based on MOF, in which you can model another language. UML and MOF is not too strict about concrete syntax and you can really use textual syntax without any problem (there is even a standard - HUTN). The actual execution is just about semantics - if languages has defined semantics, it can be used for programming and if it is Turing complete, you can program any algorithm.Shurlocke
@Gabriel: Very good comments. When I did code generation based on UML models, we agreed on a strict subset of UML and strict modeling standards.Arette
D
11

Short answer: no. Some UML modeling tools can generate Java, C++, and code in other programming languages. However, what it generates are usually interfaces and class relationships. These tools generate stubs for which the implementation still needs to be provided, so human intervention is necessary.

Deadening answered 21/3, 2010 at 3:16 Comment(4)
I have generated up to 60% of the total code in some enterprise-class applications (using custom code generation).Arette
@Eric: Which only left you the hard 40% to write, no? Not that that is not a win.Berezina
@dmckee: I generated the UI layout, UI validation rules, UI/Business object binding, business logic validation rules (using the same UML element for UI and Business Object for guaranteed consistency), ORM bindings... in the first 15%. The remaining stuff got more into generating workflows, security constraints for web services/business object methods/UI elements based on models of roles and complex calculations (generated from activity diagrams with specialized annotations). For me, that's the hard part because it's routine and boring ;-)Arette
You can generate anything, it is up to you, the question is only if UML (e.g. sequence diagram in particular) is the best way to write complex algorithm.Shurlocke
C
5

There are some tools to convert UML modeling diagrams to into code - specifically, UML state diagrams. For example, I used a tool called "Rhapsody" (from I-Logix) back in 2000 that would convert a UML diagram to C++. It was cool because the tool could run the state machine directly, and could also run code on a remote machine (in this case, a board running vxworks).

But generally speaking, UML is best used as a modeling tool. Use it to model your system and provide diagrams for your design papers, or whatever. Then use that knowledge to develop your system in an organized manner.

Coacervate answered 21/3, 2010 at 3:9 Comment(2)
If you only use UML as a modeling tool, the model will become stale rather fast. If you make full use of the potential for code generation, the model remains fresh because it adds continuing value over the life of the project.Arette
True, that's an excellent point. Design documents and diagrams are the first thing to go stale once the code starts being written. But the trade-off is that you need to develop your "code" in UML. Think about that for a moment. You will need to use the UML tool to debug your code, and any new developers to the team will need to learn a tool they have probably never used before. Over the life of your project it may still be more practical to just go back and update your UML diagrams.Coacervate
A
2

In theory? Yes - you could use a gajillion state machine diagrams and specify everything in painstaking detail, then connect the state machine diagrams to methods in your class diagram and run some horribly complicated tool to generate all of this.

But this isn't something you'd want to do. You won't be getting any more freedom in the way you express yourself, because you have to use the right kind of syntax so that the tool will understand everything you write. Not only that, but you'd be able to write the actual code yourself in far less time than it would take you to make all of those diagrams - and the only thing it gives you is that the code is a carbon copy of the spec (because the spec generates the code). That may be a good thing, but since you have no actual code, that also means that debugging means debugging the diagrams - and that is almost surely going to be near impossible.

Anarchism answered 21/3, 2010 at 3:17 Comment(1)
except state machines aren't part of UML.Shiflett
T
1

UML can model a state machine. Thus, it can represent a Turing machine. A compiler with enough sophistication can read this representation and create a binary (executable) representation of the Turing machine.

So, my answer is yes.

Edit

Since my answer seems to be disagreeable to some... let me clarify that this "compiler with enough sophistication" is completely imaginary and probably far in the future... but it seems from the other answers, there are some programs that can generate some boilerplate code or even generate and run a whole program.

I think that proves that UML (or some subset of it) qualifies as a programming language, but probably not a good one.

Tericaterina answered 21/3, 2010 at 3:14 Comment(12)
This is sooooo wrong in sooo many ways. 1. A state machine is not Turing complete, so it can't model a Turing machine. 2. Just because you can model it in UML doesn't mean UML can describe how to run it. Tell me how you can translate a UML diagram into something runable.Shiflett
@Jeff Meatball Yang: How many years away are we talking there, or is it just theory?Eureetloir
I think you inverted my meaning - a Turing machine is a state machine. And this seems paradoxical to me: "just because you can model it in UML doesn't mean UML can describe how to run it".... isn't that EXACTLY what UML does? It shows you possible states, transitions, values, etc. My "magic" compiler turns it into binary so it can run on a processor. Just like you can't write gobbledy-gook C++ and expect it to compile, you'll probably need to follow particular conventions/syntax in your UML.Tericaterina
I thought Turing machines were more powerful than automata. If I understand your answer, you are saying that the automata is more powerful.Mouldon
@Mouldon - I think automata are examples of Turing machines. So all I'm saying is that if UML can model a Turing machine's behavior, all you need is something (a compiler) that builds an executable that does what the UML models. That's the generally accepted definition of a programming language.Tericaterina
@Jeff: When we use the term "automata", or just state machines with no qualifier, we mean finite state machines. FSMs have no memory and cannot "rewind" over their input - they can recognize regular languages. TMs, however, can do exactly that - and they can recognize recognizable languages, which is much higher in the hierarchy of formal language classes. Now, this doesn't necessarily mean that UML state machines cannot be used to represent TMs, since they aren't the same thing, but the argument that "it can model a state machine, so it can model a Turing machine" is definitely wrong.Anarchism
Isn't a Turing machine a state machine?Tericaterina
@Jeff, No. A state machine (what I was refering to as an automata) is the most basic of the automaton classes. It can only generate/recognize regular languages. On the other hand, a Turing Machine is an automaton that can generate/recognize ALL kinds of language from the Chomsky hierarchy.Mouldon
@Jeff: A TM is a state machine in the sense that it has states - but it also has that tape, which provides it with memory and such, making it more powerful than a plain FSM, which only has states and transitions. Thus, a TM can emulate a finite state machine (just don't use the tape for anything except reading the input one character at a time), but a finite state machine cannot emulate a TM, because it would need a state for every possible tape configuration (of which there are infinitely many, meaning it is no longer a finite state machine).Anarchism
@Michael: Thanks for the refresher - I see the error of my logic! I've edited my answer to reflect it. Still, doesn't UML's support for 1) state machine diagrams and 2) control flow diagrams, lead to the conclusion that it is Turing complete?Tericaterina
@Jeff: Well, those two things aren't a proof in and of themselves, but I think it is fairly likely. If it's not the case, then I think it would be a relatively small change to make it Turing-complete. I don't exactly tend to sit down and prove it now, though, but if you want to, say, implement a Brainf**k interpreter in pure UML, then you could do that and thereby prove Turing-completeness (because if X can emulate something that is Turing-complete, then X is also Turing-complete).Anarchism
In UML, state machines have stacks and are actually full blown Turing machines. Read more about UML State machine diagrams. I guess the reason for calling them only "state machines" is because state machine is more general concept and more familiar.Shurlocke
T
1

Yes, it is possible, just check approaches like ExecutableUML (and a new standard along the same lines is coming) that rely on the use of an action language to express the details of the system behaviour (kind of a psedocode with iterators, conditions, and create,read, update and destroy actions).

A completely different discussion is this is worth. Modeling the system with enough precision and detail to be able to generate 100% of the code does not always pays off. I prefer to stick to my pareto principle (or 80-20 rule) for model-driven development: 20% of the modeling effort suffices to generate 80% of the application code

More detailed explanation here: http://modeling-languages.com/blog/content/pareto-principle-applied-mdd

Tompkins answered 21/3, 2010 at 5:18 Comment(2)
Vilfredo Pareto, who observed in 1906 that 80% of the land in Italy was owned by 20% of the population. Hmmm think that economics and auto generated software are two different spheres. Eric J points out in his post above that its more like 60% auto 40% man made. I like that stat better as it outlines that although the stuff has been auto generated you still going to have to put in some hours, but it has saved time and money. 80/20 rule was an observation made at the time in the time of landed wealth. People like the combo and use it a lot as it sounds flashy.Eureetloir
did you know that 20% of all stats are made up on the spot. To back that up I once worked with an economist, who after applying some figures to a return questionaire data, did exactly that because the return count was so low. He got into a bit of trouble with the British Dental Association :)Eureetloir
K
1

There is now a fully OMG standardized, Turing-complete, execution semantics for a subset of UML 2.3, known as "Foundational UML" (fUML). Look here for a reference implementation and pointer to the OMG spec. There is also ongoing work on an OMG standard UML action language.

For better or worse, when this work is done, fUML will be a programming language.

-- Ed

Kindergarten answered 18/4, 2010 at 10:48 Comment(1)
You can also find the latest draft of the action language spec submission at lib.modeldriven.org/MDLibrary/trunk/Applications/….Kindergarten
P
0

Class diagram can be forward engineered into programming language depends on the UML tool you are using. I think you still need to code your own business logic etc.

Paphian answered 21/3, 2010 at 3:10 Comment(3)
@codemeit: except that the better UML tools allow you to specify the behavior of operations in class diagrams by using activity or sequence diagrams, from which code can be generated.Inquiring
@John: I use Sparx EA on the code generation projects I reference in my answer because you have the option to model behavior, and also because all model data is in a SQL database (and most of it is available through an API).Arette
@Eric J - ROFLMAO. I had an argument a while ago with someone who very loudly proclaimed Sparx could never do all of that and we could only rely on a UML/MDA tool from a 'mainstream' vendor that cost $$$$$$+++++++. Well, I shouldn't say it was an argument, because I barely got to even say anything past "hello".Sourpuss
S
0

It is not. Not at all.

It can't make decisions (if's) or run loops. It is less of a programming language than a finite state machine. At least a FSM can make decisions. UML dosen't even have state.

Shiflett answered 21/3, 2010 at 3:14 Comment(5)
neither does Functional Programming languages such as Haskell in theory :). It does have loops. funny squiggly things that can be drawn to depict a loop.Eureetloir
but they have function calls. UML doesn't define a "main method" even.Shiflett
true true, but main shouldn't really exist in any OO language, it hacks back to procedural code, and before that Assembler. How low can you go? I think Main is implied.Eureetloir
You can model loops in UML 2 ibm.com/developerworks/rational/library/3101.htmlArette
Regions in sequence diagrams allow loops without problems, just as state machine diagrams do.Shurlocke
M
0

Short answer: As it is right now, you can't generate 100% of the code.

You could probably generate the class structure of your systems via Class Diagram, and probably part of the methods' body via Interaction Diagrams and/or State Charts but I think that's about it.

Mouldon answered 21/3, 2010 at 3:26 Comment(1)
heh, and that is about all you need, it is Turing-complete:)Shurlocke
I
0

Some links for WeNeedAnswers since I was so affected by his comment:

That should be a start.

Inquiring answered 21/3, 2010 at 4:14 Comment(5)
Thanks, but what is YOUR answer on this. I can read google till the cows come home, but what about your experiences, inside knowledge and the like. Its the one thing I get a real kick out of these forums. Its the personal touch. Take a look at Eric J's comments real world solution to a problem that's been kicking about since the promises in the 80's. Hey your comments may not be the VAILD answer, but the answer is still valid as it comes from you and not the many many people selling ideas on google.Eureetloir
@WeNeedAnswers: I have rarely generated code from UML diagrams. I did once use Sparx EA to help develop an XML Schema by transforming a class diagram into XSD, but that's it. That experience taught me it co uld be done, but I haven't done it.Inquiring
Thanks John. did the experience make you feel that there is more that can be done? As for my experience, I have seen a few code generators that work off the back of UML, last I played with was Umbrello or something like that in the open source domain. It did a good job of creating shells of Domains from the basic Dictionary, but it was certainly not complete enough to let it write itself. I first started looking at this stuff back in 1998, was a tool floating about called Select Enterprise, and used OMT and SSADM diagrams. It never generated code though, but it did promise to do so!Eureetloir
I am slowly coming around to the idea of Domain Modelling in the M programming style. Although my main interest in the moment is making data describe itself better, semantic web and the like using the Dublin Core schemas. I feel that if data describes itself, I think that domains with be easier to write.Eureetloir
Hey do we need DB modelling at all with triplet stores and super fast wizzy algorithms that can fetch triplets at the speed of light.Eureetloir
P
0

UML action semantics has support for object allocation/disposal, reading/writing attributes and local variables, invoking an operation, throwing and catching exceptions, navigating a relationship, blocks, loops and conditional behaviour, and a whole lot more.

See:

http://abstratt.com/blog/2008/11/02/what-can-uml-do-for-you/

http://abstratt.com/blog/2008/11/07/executable-models-with-textuml-toolkit-12-m1/

To those saying "no": the question is about UML, not the "UML tools you use", folks. UML is a huge language, and tools implement a subset of it, which often can be quite small.

Pyaemia answered 12/4, 2010 at 21:14 Comment(0)
G
0

UML2 is just the data for your code generator.

The code generator generalises code by using data from the model (like C++-templates generalise code by using C++-structures as a model).

Working like that, you are able to produce a complete Create, Replace, Update, Delete (CRUD) and Search Application for any given model.

That code implements hooks, callbacks, inheritance or similar techniques, that allow to extend the functionality by hand-written-code, without touching the generated code (which must be seen as intermediate code).

Gout answered 29/8, 2019 at 11:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.