file What kind of diagrams, besides classes, do you need to do to generate code?

8 months 4 days ago - 8 months 4 days ago #6521 by Robert Hairgrove
Well, the UML was always about object-oriented programming from the very beginning. If you are doing strictly functional programming, I would use maybe something like flow charts for design only and then write the code directly. I think it would be much more precise and efficient, than to (mis)use a UML diagram and try to let it generate the code for you.

Here are a few considerations:
In order to generate code, the complete model is what is needed. Diagrams are merely "windows" into different perspectives of the model as a whole. You can choose to show only certain elements in a diagram and hide others. However, if you want to generate working code, the model must be at least as detailed and correct as the code you wish to build. And to make a model like that is at least as much work as writing the code to begin with.

The generated code will never be perfect, except perhaps for very small toy programs. The big reason for this is that the UML language is still not 100% exactly specified, and it tries to be suitable for a wide range of programming languages. I think that doing code generation would perhaps be good for a rough starting point, but you will still have to write a lot of the actual code yourself to get it to work. I am using UML strictly for documentation purposes, as it is.

Some implementations have only recently begun to support the UML 2 specification, and I don't know if any tools out there are really up-to-date. Then there is the problem with the programming languages which are also evolving. How many UML tools support forward and reverse engineering of C++20 code, or even C++17?

For C++, UML doesn't handle some things -- like pointers and references -- very well, unless you use a special profile for that language. And even then, only the programmer might know whether to pass an argument by const reference or as an object to a function. Then there is the question of data types: UML has built-in "string" data type, for example, but in C++ you would need to tell the implementation what kind of string class to generate in the code, because C++ has no built-in string type. There is std::string, but maybe you really want some different kind of string. If you are using the Qt framework, for example, you might want to use QString instead. Some libraries, like Xerces-C++, have their own "XMLChar" type, for example. How do you convert between the two?

You could try to write some code, or use some existing code, and try to let Modelio or some other tool try to generate a model from it. Then see what it does. Then take the model, perhaps make some tweaks, and let it generate code and see how close it comes to the original input. I think you might be surprised.

What programming language are you targeting, BTW?
The following user(s) said Thank You: plo

Please Log in or Create an account to join the conversation.

8 months 3 days ago #6522 by plo
I am learning Python. I have already learned OOP. But at the same time, I still don't know him perfectly. I will probably study Java in the future, but I will probably study Javascript and PHP first. I started studying development environments with these languages, and Modelio studied because I learned UML from video tutorials in my national language, where simulation was shown in this program.

Please Log in or Create an account to join the conversation.

8 months 3 days ago #6523 by Robert Hairgrove
That's very interesting -- always good to know as many languages as possible!

I don't know if Modelio provides support for Python or not. There are some modules listed on the Modelio main website for C++ (commercial) and Java (both opensource and commercial). I suppose you will have to search on the internet for other tools if you want to generate Python code?

Good luck with your studies!

Please Log in or Create an account to join the conversation.

8 months 3 days ago #6524 by plo
Yes, I found 2 programs for Python with UML. Bouml and Umbrella UML (for Linux, for Windows the Umbrella - no good). But Modelio seems to me also interesting for other programming languages that it supports. And with these other programs, I have not yet figured out if I can do something in them or if I have to abandon them.

Please Log in or Create an account to join the conversation.

Moderators: tma
Time to create page: 0.043 seconds
^ Back to Top