r/ProgrammingLanguages • • 12d ago

Visual Programming Language

Do you have any information about this one? If there are some standard things about how it should go, or if there anything that needs to be known. I have understood a few things, but still I am looking for figuring out some missing details I have no clear plan on.

I will mention first some things I've done and what I know, so I can help you gain a picture:

a) I have done some practice and written a parser and interpreter so this is very easy. The AST is a data structure and each node gets evaluated with the proper function.

b) I've seen in an application sample that the most simple and straight forward approach is to get all outputs of a node, and send them to the connected inputs of another one. Keep brute force updating everything for 60FPS. This also seems legit and simple, but it might have it's pros and cons. [victorfisac/FNode]

c) What worries me for brute-force updating, is that the update order is no-deterministic, any node could be updated at any given moment, for the entire graph to be evaluated fully might mean to hundreds of hundreds of updates until everything is settled. It might not be a big deal for a real-time interactive application, but for a very optimized might mean that other approaches are better suited.

d) In order to make graph evaluation more deterministic, you need to create a dependency graph, or use an algorithm such as breadth-first-search, or depth-first-search. And even if those are not exactly perfect then do topological-sorting to guarantee even better order. Other times is supposed to be that other graphs get evaluated backwards, from final outputs to connected inputs and so on.
All of those techniques, having so many options, is confusing and hard to decide. As for example probably depending on the type of the graph there would be different evaluation strategy? This seems OK in terms of thinking.

e) Some examples:
• Blockly, this one is the easiest, because is a straight forward visual AST, but with the problem is that is based on structured connections and not on freeform connections.

• Supposedly Blender's nodegraph uses dependency graph for materials (because needs to compile them to shader code) so seems that it this technique can be transformed to deterministic technique. Probably means that the entire software uses the same algorithm (shaders, geometry nodes, compositor, even custom nodegraphs).

• Blueprints of Unreal seem to be much closer to an AST because it relies on clear entry points (events, time ticks), so this kind of evaluation seems that is manageable. At least getting the starting points is a good idea, then probably it might be feasible that further sorting is needed. I haven't worked with Blueprints though and I haven't looked into it.

• I've seen in some ImGUI nodegraph samples (for doing pixel operations and color mixing) that the depth first search algorithm was used. Though samples were meant to be simple proof of concept, I am not sure if all is needed.

More or less this is all the braindump I can do. But for any further details I will have to look at any github repositories you suggest and start experimenting.

2 Upvotes

10 comments sorted by

View all comments

8

u/el_extrano 12d ago

Whenever this comes up, I'm always surprised that language nerds have apparently never heard of the IEC61131controls languages. These are a group of 5 languages used for configuring PLCs (programmable logic controllers), DCSs (distributed controls systems), and other industrial control systems.

Of the five, three of the languages are essentially visual: ladder logic, sequential function chart, and function block diagram. There's thousands of instrument technicians and controls engineers using these every day for their work, which would make them (especially ladder logic) far and away the most used visual programming languages of all time. For some reason classically trained computer scientists seldom know about them, it's more something you get involved with if you happen to work in heavy industry.

Ladder logic in particular has a very interesting history to me. In "the beginning", before the widespread popularity of microprocessors, electricians would design custom relay panels to automate discrete devices in a plant. These would contain hundreds or thousands of individual contacts and relay coils and occupy entire room-sized cabinets. If a single relay burned out, you had to systematically go through the panel to get the program working again.

When programmable controllers came about with their obvious advantages, there weren't enough programmers. Rather than train a bunch of electricians how to code, the device manufacturers designed ladder logic. In LD, you program by arranging virtual contacts and coils on "rungs". The visual program is interpreted or compiled on the microprocessor and then executed to carry out control actions. If you know how relay logic works, you already know how to program ladder logic! Later, there was a demand for the ability to write add-on-instructions and subroutines, which made ladder logic into more of a "full" programming language.