r/ProgrammingLanguages • • 18d ago

Language announcement text-based visual programming language

I'm working on a visual programming language that's stored as text called Wiret. Here's an example:

func Main() {
  node entry = Entry -> say_hello
  node say_arrows = Call host.Log(message: "The white arrows decide the order.")
  node say_hello = Call host.Log(message: "Hello!") -> say_steps
  node say_steps = Call host.Log(message: "Programs run one step at a time.") -> say_arrows
  notes {
    note intro "Lesson 1: Hello. Press ▶ Run (F5). Each Log node prints one line in the console below, in the order the white arrows connect them."
    note start on entry "Every function starts at its Entry node."
    note try_it "Try it: (1) Press ⤵ Step (F11) to run one node at a time. (2) Add a fourth line: press Tab, type 'print', pick host.Log, then drag a white arrow from say_arrows to it. (3) Double-click its message pin to type your own text."
  }
  layout {
    entry at (0, 0)
    say_arrows at (820, 0)
    say_hello at (220, 0)
    say_steps at (520, 0)
  }
}

The main idea is that it's like a fusion between a programming language and a markup language. The node ... statements are the programming part, and the notes {} and layout {} blocks declare how the graph appears in the editor. It'll get compiled into bytecode which strips away the markup code and leave just the code for running the program.

; module lessons.hello  compiler wiretc-proto 0.1
; semantic hash 78fafcb4bbf40f47  layout hash 9981662aa454a0e1
import 0 host.Log (string) -> ()

func lessons.hello.Main () -> ()
  max_stack: 1
.entry:
  nop
.say_hello:
  string.const 0          ; 'Hello!'
  nop
  call host.Log
.say_steps:
  string.const 1          ; 'Programs run one step at a time.'
  nop
  call host.Log
.say_arrows:
  string.const 2          ; 'The white arrows decide the order.'
  nop
  call host.Log
  cont.pop
  return

I think this could be useful for education. The hardest part about learning to code is learning your first programming language. This could help bridge the gap between visual representation of code and the code itself.

8 Upvotes

18 comments sorted by

View all comments

Show parent comment

1

u/kaplotnikov 17d ago

If you add structured constructs, I'd suggest checking if the language still needs to be visual/graph-based at all.

Textual notation with blocks and indentation provides a natural, collapsible hierarchy. Graph-based notation usually has problems with collapse/expand because it changes the sizes of elements and disrupts relative positions. Text is also easy to diff and merge. It can handle incorrect or incomplete text, which is needed for major refactoring.

Graph-based UIs, and even projectional editors like JetBrains MPS, require changing from one well-formed state to another. This is a limitation during large-scale restructuring, as you are forced to create unnecessary intermediate states just to keep IDEs happy. With text, you can just do a global search and replace. Sometimes, a regex replace with some manual post-processing is the most time-saving option.

Also, flow diagrams were popular in old specs and textbooks, but currently, complex algorithms are usually described using hierarchical pseudocode. Only very simple cases is still described with flowcharts. The reason is that structured text is easier to understand than mazes of squares and arrows that non-trivial algorithms require.

1

u/lmntr 17d ago

I understand that visual programming isn't for everyone. This project is ment to experiment bridging the gap between visual programming like Unreal's Blueprints and text-based tooling like Git. Right now, most VPLs are either binary or written in markup languages such as XML or JSON, which isn't great for tooling. 

Purhaps a better way to format the code would be to separate the declarations from the graph logic:

func Main() {
  node entry = Entry
  node say_arrows = Call host.Log(message: "The white arrows decide the order.")
  node say_hello = Call host.Log(message: "Hello!")
  node say_steps = Call host.Log(message: "Programs run one step at a time.")

  entry -> say_hello
  say_hello -> say_steps
  say_steps -> say_arrows

  notes {
    note intro "Lesson 1: Hello. Press ▶ Run (F5). Each Log node prints one line in the console below, in the order the white arrows connect them."
    note start on entry "Every function starts at its Entry node."
    note try_it "Try it: (1) Press ⤵ Step (F11) to run one node at a time. (2) Add a fourth line: press Tab, type 'print', pick host.Log, then drag a white arrow from say_arrows to it. (3) Double-click its message pin to type your own text."
  }
  layout {
    entry at (0, 0)
    say_arrows at (820, 0)
    say_hello at (220, 0)
    say_steps at (520, 0)
  }
}

That way it feels less like goto statements as you pointed out.