UML 是一种编程语言吗?

发布于 2024-08-26 07:48:35 字数 81 浏览 4 评论 0原文

UML 是否可以用来对计算机系统进行独立编程,而无需支持实现语言,例如直接将图表转换为机器代码(可能通过 C 或 C++ 等),而无需人工编码干预。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

陈年往事 2024-09-02 07:48:35

我将与一般趋势相反,分享一个经验,展示 UML 今天可以做什么,以及 UML(或其他建模方法)的未来版本可以做什么。

首先介绍一下历史。

很久以前,人们用汇编语言对计算机进行编程(并不是一直回到这里)。然后出现了更高级的语言,如 C 和 Basic。擅长汇编的程序员认为,您无法用高级语言完全表达处理器能够执行的所有操作(以优化的方式)。事实上,他们是对的。从高级语言的内存和性能角度来看,有些事情不太理想,因为您无法完全控制发送给处理器的指令。

问题是,高级语言提供了更加抽象的表达形式。因此,他们流行起来,过了一段时间,人们并不真正关心你无法完全控制处理器的各个方面,因为开发人员的工作效率要高得多(摩尔定律也有帮助)。

类似的情况也发生在面向对象语言和托管语言上。每一次,都会出现更高级别的抽象,并最终胜出,因为开发人员使用它的效率更高。事实上,随着编译器变得更好和优化技术的改进,较高级别表达式中的低效率通常会消失。

模型驱动开发是更高层次的体现。您无法完全表示您可以用 C# 或 Java 等语言编写的任何代码。特别是不是开箱即用。然而,可以直接从 UML 模型生成应用程序的很大一部分。

我领导了几个相当大的项目的基于 UML 的代码生成工作。在许多情况下,我们可以生成(现实生活中的企业级)应用程序的整个源代码的 30% 到 60%。这只是一个小团队为特定领域编写生成器的情况。最终,整个行业将支持从模型生成越来越多现实生活应用程序的工具。

自从第一个汇编代码抽象操作码以来,这是我们在行业中一次又一次看到的自然进化的下一步(在那之前可能有一些东西,但那是在我的时代之前)。

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).

我是男神闪亮亮 2024-09-02 07:48:35

简短的回答:不。一些 UML 建模工具可以生成 Java、C++ 和其他编程语言的代码。然而,它生成的通常是接口和类关系。这些工具生成的存根仍需要提供实现,因此需要人工干预。

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.

空城旧梦 2024-09-02 07:48:35

有一些工具可以将 UML 建模图转换为代码 - 特别是 UML 状态图。例如,我在 2000 年使用了一个名为“Rhapsody”(来自 I-Logix)的工具,它将 UML 图转换为 C++。这很酷,因为该工具可以直接运行状态机,还可以在远程计算机(在本例中是运行 vxworks 的板)上运行代码。

但一般来说,UML 最好用作建模工具。使用它来建模您的系统并为您的设计论文或其他内容提供图表。然后利用这些知识以有组织的方式开发您的系统。

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.

腹黑女流氓 2024-09-02 07:48:35

理论上?是的 - 您可以使用大量状态机图并详细指定所有内容,然后连接状态机图到类图中的方法,并运行一些非常复杂的工具来生成所有这些。

但这不是您想要做的事情。您将不会在表达自己的方式上获得更多自由,因为您必须使用正确的语法,以便该工具能够理解您编写的所有内容。不仅如此,您自己编写实际代码的时间比制作所有这些图表所需的时间要短得多 - 而且它给您的唯一好处是代码是规范的副本(因为规范生成代码)。这可能是一件好事,但由于您没有实际的代码,这也意味着调试意味着调试图表 - 这几乎肯定是不可能的。

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.

桃气十足 2024-09-02 07:48:35

UML 可以对状态机进行建模。 因此,它可以表示图灵机。 具有足够复杂性的编译器可以读取此表示形式并创建 图灵机 的二进制(可执行)表示形式。

所以,我的答案是肯定的。

编辑

由于我的回答似乎对某些人来说是不愉快的...让我澄清一下,这个“具有足够复杂性的编译器”完全是想象出来的,并且可能是遥远的未来...但从其他答案来看似乎,有一些程序可以生成一些样板代码,甚至生成并运行整个程序。

我认为这证明了 UML(或其某些子集)有资格作为一种编程语言,但可能不是一种好的语言。

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.

吃素的狼 2024-09-02 07:48:35

是的,这是可能的,只需检查像 ExecutableUML 这样的方法(并且即将推出类似的新标准),这些方法依赖于使用动作语言来表达系统行为的细节(类似于带有迭代器、条件的伪代码,以及创建、读取、更新和销毁操作)。

一个完全不同的讨论是这是值得的。以足够的精度和细节对系统进行建模以生成 100% 的代码并不总是有回报。
对于模型驱动开发,我更喜欢坚持帕累托原则(或 80-20 规则):20% 的建模工作足以生成 80% 的应用程序代码

更详细的解释请参见:http://modeling-languages.com/blog/content/pareto-principle-applied-mdd

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

倾其所爱 2024-09-02 07:48:35

现在 UML 2.3 的子集有一个完全 OMG 标准化、图灵完备的执行语义,称为“基础 UML”(fUML)。请在此处查找参考实现和指向 OMG 规范的指针。 OMG 标准 UML 动作语言的工作正在进行中。

无论好坏,当这项工作完成后,fUML 将成为一种编程语言。

——艾德

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

离笑几人歌 2024-09-02 07:48:35

类图能否被正向工程化为编程语言取决于您使用的 UML 工具。我认为你仍然需要编写自己的业务逻辑等。

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.

第几種人 2024-09-02 07:48:35

它不是。一点也不。

它无法做出决策(if)或运行循环。它与其说是一种编程语言,不如说是一种有限状态机。至少密克罗尼西亚联邦可以做出决定。 UML 甚至没有状态。

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.

獨角戲 2024-09-02 07:48:35

简短的回答:就目前而言,您无法生成 100% 的代码。

您可能可以通过类图生成系统的类结构,并且可能通过交互图和/或状态图生成方法主体的一部分,但我认为仅此而已。

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.

嘿咻 2024-09-02 07:48:35

自从我受到他的评论影响以来,WeNeedAnswers 的一些链接:

这应该是一个开始。

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

That should be a start.

舂唻埖巳落 2024-09-02 07:48:35

UML 动作语义支持对象分配/处置、读/写属性和局部变量、调用操作、抛出和捕获异常、导航关系、块、循环和条件行为等等。

请参阅:

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

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

对于那些说“不”的人:朋友们,问题是关于UML,而不是“您使用的UML 工具”。 UML 是一种庞大的语言,工具实现了它的一个子集,该子集通常非常小。

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.

陌生 2024-09-02 07:48:35

UML2 只是代码生成器的数据。

代码生成器通过使用模型中的数据来概括代码
(就像 C++ 模板通过使用 C++ 结构作为模型来概括代码一样)。

像这样工作,您可以为任何给定模型生成完整的创建、替换、更新、删除 (CRUD) 和搜索应用程序。

该代码实现了挂钩、回调、继承或类似技术,允许通过手写代码扩展功能,而无需触及生成的代码(必须将其视为中间代码)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文