📜 ⬆️ ⬇️

Visual programming in DRAGON

Visual and text programming


What is the driving force behind the program? What generates a useful result? Of course, the algorithm. The algorithm creates the effect for which the program is written. The algorithm does not work alone. It works in conjunction with data structures. But it is the algorithms that make up the largest part of the program.


Historically, the algorithms in programs are written in the form of source code. Almost no one questions that the text is the best means of representing algorithms. The algorithm is encoded inside functions in a programming language, such as C or JavaScript. For those who want to understand the algorithm from a bird's eye view, pseudocode is provided. However, there are serious problems with the text. The fact is that a person is not optimized for a solid text. The person is optimized for perception of graphics. The text is a relatively new invention, but organisms have been processing graphic information for millions of years.


Based on this, it would be logical to make the algorithms in graphical form. Look at the engineers. They use drawings everywhere. What is worse for programmers? They, too, could make drawings of algorithms. Some will object: visual programming is supposedly ineffective. UML is inconvenient, and it is easy to get confused in block diagrams. It is better to program in the traditional way - the text. In structured programming, there is at least a structure, and it provides order and uniformity. And besides, drawing charts is long and difficult. Typing is faster than drawing.


So, programmers are doomed all their life to work only with text?
Perhaps not everything is so bad. There are visual languages ​​for representing algorithms that also have order and structure, for example DRAGON, BPMN and LML Action Diagrams. Here we look at the dragon visual algorithmic language.


How to program in the language of DRAGON


DRAGON is not an independent programming language. He works in tandem with textual language, for example, with javascript, python or c ++. Together with the text language, DRAGON forms a hybrid language: DRAGON-JavaScript, DRAGON-Python or DRAGON-C ++.


Programming in a hybrid language is as follows:


  1. Draw a dragon diagram.
  2. Inside the icons we put small pieces of code in the appropriate programming language.
  3. The program-translator converts the DRAGON-scheme into a text file with the source code.
  4. This text file is included in the project in the usual way.
    The generation of code from diagrams is currently supported by several editors. The examples in this article are made in the DRAKON Editor.

Code generation from chart


In the diagram, DRAGON takes control of the flow of execution. Therefore, the pieces of the source code in the icons should not contain keywords such as if , else , switch , case , for , while , etc.


Inside the icons there should be only a simple unambiguous code: arithmetic expressions, assignment of values, function calls, comparisons. But the branching and cycles are implemented by constructions of the language DRAGON.


It is also not recommended to use logical expressions: and, or, not. They are also portrayed by means of DRAGON.


The code is generated as follows:



In fig. Figure 1 shows an example of a small diagram in the DRAGON-JavaScript hybrid language and the generated JavaScript code:


The rectangle with the text console.log (cat, dog) in fig. 1 is the action icon. How much code can be put into one “Action” icon? You should strive to ensure that one icon contained one thought. Sometimes this is one line of code, sometimes several.
The generated code is provided with comments, which contain the number of icons. While in the editor, you can quickly jump to any icon by pressing Ctrl + I.


image
Figure 1. The diagram on DRAGON-JavaScript and the code generated from it.

Icon "Question"


For branching, the Question and Choice icons are applied.


The Question icon (fig. 2) corresponds to the if-then-else construction .


Note that instead of the words true and false , the words Yes and No are used (you can switch to Yes and No ).


"Truth" and "false" - it sounds spectacular, as a scientist. However, the person closer familiar from early childhood, "yes" and "no."


The inscriptions Yes and No can be interchanged. The position of exits from the Question icon remains unchanged. One exit goes down, and the other - to the right. A branch in the DRAGON language is always directed to the right, therefore, the exit from the left side of the icon is prohibited. Such predictability makes it easier to read a diagram, since the reader knows in advance where to look for outputs.


Another feature of the language DRAGON is that for branching is not used a complete rhombus, and truncated. This saves space on the chart.


image
Figure 2. Question Icon

Visual logical formulas


The language DRAGON makes unnecessary the logical operators AND , OR, and NOT , as well as the "not equal" operator. The logical operations themselves are of course necessary. But instead of text operators, DRAGON introduces visual logical formulas.


To get a visual logical formula, you should combine several Question icons (as in Fig. 3).


Especially nice to get rid of denial. Denial is not intuitive, it brings errors and inconvenience. Negation (the logical NOT operator) is achieved in the language of DRAGON by permuting the Yes and No labels.


The textual record of logical expressions is definitely more compact. However, visual formulas are easier to read. Each of the possible combinations of operand values ​​can be traced with a finger.


image
Figure 3. Visual logical formulas
')

Loop with arrow


To indicate the usual order of execution in the language of the DRAGON arrows are not needed. The next icon is always below. An arrow is required only when the thread of execution must jump upwards in the diagram. Such a jump up means a cycle. Therefore, the arrow in the language of DRAGON is a sign of the cycle. With a cursory glance at the DRAGON-scheme, the arrows are immediately noticeable. So, immediately visible and cycles. This is a major advantage of DRAGON compared to other graphic languages. Cycles do not have to seek out.


So, if you connect the icon "Question" with an arrow, you get a cycle. This is an analogue of the while and do-while constructs. Figure 4 shows several types of cycles with arrows.
The Question icon in a loop with an arrow checks the exit condition of the loop. Of course, instead of one “Question” icon there can be several. Then the visual logic formula is responsible for exiting the loop.


image
Figure 4. Switch cycles

Icon "Choice"


The "Question" icon contains a logical expression, that is, it can take two values: Yes and No. A typical example is the comparison of two objects. If you need to compare a certain expression with several values, the “Select” icon is used (Fig. 5). This corresponds to the witch-case design.


The values ​​with which the expression in the “Select” icon will be compared are placed in the “Option” icons. If there is no text in the rightmost variant, it means “all other values”. Such an empty variant is similar to the default keyword inside a switch statement .
The rightmost option may end with an arrow that leads up. In this case, we again deal with the pointer cycle. In this cycle, the Choice icon and not the Question will answer for the exit condition.


image
Figure 5. Icon "Choice" and icons "Option"

Icon "Cycle FOR"


Instead of the for and foreach cycles in DRAGON-JavaScript, the “FOR loop” icon is used. The icon "Cycle FOR" (Fig. 6) can be of several types.


If there is one variable after the foreach keyword and before the semicolon, then code is generated for iterating over the array. The variable will contain the elements of the array (but not their indices).


If there are two variables after the foreach keyword, the DRAKON Editor will understand that it is necessary to iterate over the properties of an object (hash table entries). Only the own properties of the objects fall into the listing.


The third variant of the cycle implies the presence of three expressions separated by semicolons. This is a traditional for loop, characteristic of C and Java languages.


From the cycle under the control of the “Cycle FOR” icon, an early exit is possible with the help of the “Question” or “Select” icon. This output roughly corresponds to the keyword break .


image
Figure 6. Different types of the “FOR Cycle” icon in DRAGON-JavaScript

Only one cycle entry


In the language of DRAGON on the cycles imposed restrictions. Each cycle can have only one input. The purpose of this restriction is to ensure readability. This restriction holds DRAGON within the framework of structured programming, as Dijkstra described it.


Multiple exits from the loop are valid, but there should be only one input. In fig. 7 shows cycles that have two outputs. It is allowed. In fig. 8 shows examples of forbidden cycles. Prohibited because they can enter in different ways.
However, do not memorize the appearance of these forbidden cycles. DRAKON Editor will automatically detect such cycles and generate an error.


image
Figure 7. Allowed cycles, which have two outputs

image
Figure 8. Forbidden cycles that have two inputs

Differences from text structured programming


As you can see, the icons and macro-languages ​​of the DRAGON language have correspondence with the standard structures of text structured programming. However, there are differences. The text, even with indentation, is a one-dimensional object. And the diagram is two-dimensional. An additional degree of freedom appears in the diagram, which enhances expressiveness. Try, for example, in a text programming language without repetitions and goto to depict such an algorithm, as in Fig. 9.


Despite the additional freedom compared to the text, the DRAGON still does not allow anarchy to strike. Its rules are harsh enough to prevent confusion. DRAGON provides a reasonable compromise between flexibility and rigor.


image
Figure 9. Algorithm that is difficult to portray only with text.

Benefits of graphic language


The language DRAGON has an interesting fate. Its basic principles were laid down by Dykstra itself. The current form of the dragon acquired in the depths of the Russian space industry. It is noteworthy that the rules of the language DRAGON did not arise by chance. They were first tested in focus groups, and then honed in real space projects.
So what exactly are the strengths of the DRAGON?


Let's start with the fact that DRAGON is a graphic language. And the graphic language has fundamental advantages over the text.


First, thoughts are not spread out randomly in lines, but enclosed within squares, or icons. One thought - one square. Different thoughts do not stick together in one mess.


Secondly, the path through the algorithm can be traced with a finger (or glance). After if you do not need to look elsewhere . Follow the line and get into the right box. You do not need to run your eyes on the source code in search of an answer to the question: what happened next?


And diagrams have one almost magical property. It happens that a person looks at a diagram, and suddenly some additional understanding comes. Previously invisible connections become apparent. With the text it happens rarely.


Special ergonomic rules


But DRAGON is not just diagrams, it’s carefully thought-out diagrams. DRAGON schemes are perceived more easily than conventional block diagrams. This is provided by special ergonomic techniques. Here are some of them.



The above rules have tremendous practical value. On the one hand, they are designed to curb the madness of the artist. Creating an intricate diagram with them is more difficult. On the other hand, they bring recognition to the charts. Charts are understandable not only to their authors.


The diagrams in fig. 10 and 11 demonstrate the ergonomic techniques of the language DRAGON with real examples.


image
Figure 10. Ergonomic techniques of the language DRAGON using an example

image
Figure 11. Another example of a dragon chart
In addition to ergonomic techniques, the language DRAGON has unique features that are not found anywhere else.

The more right, the worse


DRAGON has the facility to image the happy path , or royal road . The royal road is the most successful way through the algorithm. In some algorithms, the concepts of “successful / unsuccessful”, “good / bad” are not applicable. In them, the royal road shows the most expected path. The royal road runs vertically, located on the left side of the diagram. This vertical is called skewer. Less likely and less successful scenarios, as well as error handling, are placed on the right side of the diagram. And the worse the situation, the more right it should be located. A good style is to place a code that throws exceptions or returns an error code to the right of the diagram.


If the reader is not interested in reading the error handling code, all he needs to do is look through the skewer only.


Common fate


Sometimes it happens that on different paths through the algorithm it is necessary to carry out various, but somehow related actions. For example, put different values ​​in one variable. Common fate is when related actions sit on different vertical lines, but on the same horizontal.


Fig. 12 shows the skewer with the royal road, as well as the use of the “common fate” technique.


image
Figure 12. Tsar's road and common destiny

Silhouette


The silhouette is a real dragon diamond. Silhouette allows you to break the diagram into logical parts. In programming, this is usually done using decomposition using subroutines. Subroutines - effective method. But sometimes I would like to locate the subroutine visually close to the main program, as well as avoid fussing with passing parameters and returning values. For these purposes, a great silhouette. Another use of the silhouette is state machines. But we'll talk about this in another place.
It happens that the algorithm fails to expand on a plane so that there is no intersection of lines. In this case, depending on the situation, apply either decomposition using subroutines, or silhouette.


The silhouette consists of several small diagrams connected in one integral block. These small diagrams are called silhouette branches. At the top of each branch there is an icon "Branch Cap", below - an icon "Address". In the header of the branch put the name of this branch, and in the address indicate the name of the next branch. The names of the branches are located on the same horizontal line at the top of the diagram. Due to this, you can grasp the essence of the algorithm by running only on the caps of the branches. The silhouette answers three royal questions:


  1. What is the problem called?
  2. How many parts does it consist of?
  3. What are these parts called?

Consider the example in fig. 13. Here are the answers to the royal questions:


  1. What is the problem called? Sort the linked list.
  2. How many parts does it consist of? Of the four.
  3. What are these parts called? Build a matrix of relationships. Check for cycles. Go through the matrix of connections. To complete.

image
Figure 13. DRAGON-scheme "silhouette"


Silhouette cycle


Branches of the silhouette should be ordered from left to right. In some cases, it is necessary to perform some kind of branch or group of branches several times. This design is called the silhouette cycle. If the “Address” icon points to its own branch, or to a branch that is located to the left, it should be marked with a special label. The same label should be put on the corresponding icon “Branch of the branch” (see fig. 14). The purpose of the label is to make the silhouette cycle visible.


image
Figure 14. Silhouette cycle and labels

The connection of the branches of the silhouette is prohibited


Joints of two branches of the silhouette (as in Fig. 15) are prohibited. Each branch inside the silhouette should be independent.


image
Figure 15. The connection of the branches of the silhouette is prohibited.

Chart size


During programming in DRAGON, the question arises: how big should the diagrams be? The answer is: less is better. The fewer objects in the visual scene, the clearer. In text programming, there is such a guide: well, if the entire function fits entirely on the screen. Similar advice can be given for DRAGON-schemes. Avoid huge charts. When the entire algorithm is fully visible, it is much easier to understand.
For programming on DRAGON it is better to have a large monitor. At least 1080 points in height. Then you will not have to artificially shorten the DRAGON-schemes.


DRAGON-scheme silhouette should be placed on the screen in height, but not necessarily in width. Silhouette diagrams can be quite wide, much wider than 2000 pixels. This is normal. It is not necessary to see all branches of the silhouette at the same time. The main thing is that the branch with which you are currently working was fully visible on the screen.


Criticism of programming on DRAGON


Consider the main directions of criticism of programming on DRAGON and try to give an answer to them.



Dragon language overview


Figure 16 presents an overview of the language DRAGON.


image
Figure 16. Overview of the DRAGON

Tools for working with the dragon language


The very first implementation of the language DRAGON was the GRAFIT-FLOX system (Fig. 17). GRAPHITE-FLOX was created in 1986-1996. specialists of FSUE NPTs AP them. Pilugin under the direction of V.D. Parondzhanov. This environment was intended for the design of control systems for launch vehicles and spacecraft.


GRAPHITE-FLOX is a closed development, so relatively little is known about it. The list of spacecraft created using GRAPHITE-FLOX can be found here .


In the early 1990s, another dragon editor was created. The development was carried out at the Institute of Applied Mathematics. Keldysh under the leadership of L.K. Aysymont. Eisymont's editor (fig. 18) can be downloaded and launched, but it is no longer supported. The editor is written under MS DOS, so DOSBox may be required to run on modern computers.


In 2008, the editor of the IP Dragon from Gennady Tyshov saw the light (Fig. 19). IP Dragon is actively maintained and developed. In the Dragon IP, the generation of program code from diagrams is implemented. One of the interesting features of Dragon IP is the ability to place in one icon a code in a programming language and a description in a natural language. The absolute dignity of IP Dragon - the so-called "calculus of icons." Icon calculus is an editing method that helps the user draw a diagram and ensures that the diagram does not violate the rules of the DRAGON language. Among the drawbacks of the Dragon IP system are a non-standard user interface and some inconveniences when generating code. IP Dragon is a commercial product.


DRAKON Editor - another modern dragon editor (Fig. 20). DRAKON Editor was developed by a group of enthusiasts under the leadership of Stepan Mitkin. DRAKON Editor does not support the calculation of icons. This means that DRAGON-schemes are assembled in it manually from primitives, as in vector graphics editors. But the user interface in the DRAKON Editor is as simple as possible. It is built on a more familiar pattern than the Dragon IP. The main advantage of the DRAKON Editor environment is the ease of programming and code generation. DRAKON Editor supports several programming languages, including C, C ++, C #, Java, Processing, JavaScript, Lua, Erlang, Python, Tcl, Verilog, AutoHotkey, D, and Go. For some languages, it is possible to generate state machines. The rules for nools expert system are supported. Implemented a subset of the language Utopiste E. Tyugu. DRAKON Editor is open source.


Oleg Garipov invented an interesting use for the language DRAGON in his project Integrator CodeView. CodeView allows you to visualize existing code as an interlocking set of DRAGON-schemes. The feature of Integrator CodeView is that it is not the individual methods that are visualized, but the entire project, including the call graph, stack, etc. The Integrator CodeView is unique in that it clearly shows not only algorithms, but also data. The data visualization engine in the Integrator system works in conjunction with DRAGON.


DRAKON Editor Web is a commercial cloud solution based on the DRAKON language. DRAKON Web Editor is designed for technical tasks, business procedures and checklists. DRAKON Editor Web is not affiliated with the DRAKON Editor in any way and does not support code generation from diagrams. Among the advantages of DRAKON Editor Web should be noted a convenient editor, collaboration and support for mobile devices.


image
Figure 17. DRAGON-diagram in the GRAFIT-FLOX system.

image
Figure 18. DRAGON-editor of Eisymont.

image
Figure 19. Program with explanations in the Dragon IC.

image
Figure 20. DRAKON Editor

findings


Let's sum up.DRAGON is a practical language tempered in space. He introduced structure, order and uniformity into the flowcharts. Predictability and tidiness of DRAGON-schemes lead to the fact that visual programming works .


: . , , . — . , - , ( ). . , , .


. -, , . -, , .


Bibliography


,
  1. Dahl, OJ Dijkstra, EW Hoare, CAR (1972). Structured programming. Academic Press Ltd: London.
  2. Parondzhanov, V.D. Learn to write, read and understand algorithms. - Moscow, DMK Press, 2012.
  3. Kaufman, V.Sh. Programming languages. Concepts and principles. - Moscow, DMK Press, 2011.
  4. Parondzhanov, V.D. Why do doctors kill and mutilate patients or why a doctor needs flowcharts of algorithms? .. - Moscow, DMK Press, 2017.
  5. Lifecycle Modeling Language (LML) specification. 2015. http://www.lifecyclemodeling.org/specification/
  6. Business Process Model and Notation specification, 2011. http://www.omg.org/spec/BPMN/2.0/About-BPMN/
  7. . https://drakon-editor.com/docs/examples
  8. Mitkin, S. DRAKON. The Human Revolution in Understanding Programs, 2011. https://drakon-editor.com/files/DRAKON.pdf
  9. Mitkin, S. Visual functional programming with DRAKON-Erlang- Erlang User Conference 2015. https://www.youtube.com/watch?v=yZLedcnFA94
  10. Mitkin, S. DRAKON-Erlang: Visual Functional Programming, 2012. http://drakon-editor.sourceforge.net/drakon-erlang/intro.html
  11. C programming with DRAKON Editor. http://drakon-editor.sourceforge.net/cpp/c.html
  12. Lua programming with DRAKON Editor. http://drakon-editor.sourceforge.net/lua/lua.html
  13. -. http://drakon.su/grafit-floks-sistema
  14. - http://forum.drakon.su/viewtopic.php?p=43805#p43805
  15. - . http://drakon.su/instrumenty/eysymont
  16. . http://drakon.su/programma_is_drakon
  17. Integrator CodeView http://integratorsoft.com/?mo=69503271058&vi=2838242471&w=69503271097
  18. DRAKON Editor http://drakon-editor.sourceforge.net/
  19. http://drakon.su/
  20. http://forum.drakon.su/

Source: https://habr.com/ru/post/345320/


All Articles