Skip to content
/ bait Public
forked from bait-lang/bait

Latest commit

 

History

History
64 lines (48 loc) · 2.01 KB

syntax.md

File metadata and controls

64 lines (48 loc) · 2.01 KB

Syntax design

Why is the syntax the way it is?

No Block Comments

Bait does not support block comments:

  • Complicates lexing and parsing, especially nested block comments
  • Hard to format, especially inline comments (a built-in formatter is planned)

Using a decent editor with line wrapping and shortcuts, you can achieve almost the same level of convenience!

For details, I recommend reading https://futhark-lang.org/blog/2017-10-10-block-comments-are-a-bad-idea.html.

Casting: val as Type

Benefits

  • Natural logic flow
    • Flow from left to right, mirroring natural language
    • Consistent with general design "value before type", e.g. function parameters
  • No ambiguity: Use of the designated keyword as
  • Efficient parsing

Alternatives considered

  • Type(val)
    • Confusable with function calls: Type(val) vs func(param)
    • Problematic parsing without unlimited lookahead, e.g.
      • References &u8
      • (nested) Arrays [][]f64
    • Harder to type as code has to be inserted before and after the casted value

References

Static Variables

Benefits

  • No name collision with symbols in other packages
  • Clear scope and explicit usage

Alternatives considered

  • Global variables
    • Hard to trace where a variable and value changes come from
    • Unintended coupling of independent code parts

References

Function Types

Parameter names of function types must be named, e.g.

type Fetch := fun (method string, url string) []u8

Benefits

  • Improved Readability:
    • Purpose of each argument is easier to understand
    • Reduced chance of parameter mix-ups
  • Better tooling support and documentation

Alternatives considered

  • type Fetch := fun (string, string) []u8