nevalang / neva

🌊 Dataflow programming language with static types and implicit parallelism. Compiles to native code and Go
https://nevalang.org
MIT License
85 stars 7 forks source link

[Syntax]: get rid of `net` keyword #596

Closed emil14 closed 1 month ago

emil14 commented 1 month ago

Let there be nodes {} and everything else be network by default. So what's inside component {} is either nodes block or connection.

There probably should be only one nodes block but question is should that be enforced by analyzer or just linter.

Before

component Main(start) (stop) {
    nodes { Range, PrintLine, Match }
    net {
        :start -> [
            (1 -> range:from),
            (101 -> range:to)
        ]
        range.data -> printLine -> match:data
        100 -> match:case[0] -> :stop
    }
}

After

component Main(start) (stop) {
    nodes { Range, PrintLine, Match }
    :start -> [
        (1 -> range:from),
        (101 -> range:to)
    ]
    range.data -> printLine -> match:data
    100 -> match:case[0] -> :stop
}

Motivation

While being less explicit and also less consistent with the rest of the language this has some benefits

  1. Saves us about 2 lines of code and one nesting level
  2. Looks more like a function with var on top of it and list of instructions in a body

In other words it probably improves readability.

What about downsides? Well, let's discuss them.

It's less explicit

Yeah that's for sure. However, you can't program in Nevalang anyway without reading documentation. You learn it once and you read code thousands of times then. So what we should optimize here is the reading part.

It's less consistent.

Yeah but the thing is - who said that everything should always be consistent? Consistency is a nice to have thing but it's just of the things we need. Sometimes consistency has some downsides. What we need to achieve when we're talking about the syntax is "easy to read". Sometimes consistency contributes to that. Maybe this isn't that time?

emil14 commented 1 month ago

Done