Skip to content

Design directions

Shachar Shemesh edited this page Jul 7, 2018 · 3 revisions

This page is written before any work has started on coding, implementing or writing code using the language. It will be very interesting to see how many of those objectives would be reachable.

Items marked with (?) are items I'm not sure about.

Compatibility to C

  • The syntax will be C like. Curly braces, semicolons, and white-space indifference.
  • Fix operator precedence bugs that invite errors in C. Same for confusing evaluation rules of C (like integer promotion of operations). Compiler warning if an expression would evaluate in its entirety differently between C and practical.

Example:

short func1(short a, short b) {
  return a+b; // No warning. C and practical would always return the same result
}

int func2(short a, short b) {
  return a+b; // Warning: C would promote to int, treating overflows differently than practical
}
  • No implicit narrowing conversions.
  • Rethink some C and C++ UBs.
    • Evaluation order in function calls
    • integer overflows(?)

Practical features

Default const

The default mode for new variables is const. Use the mutable keyword to indicate that a variable is, well, variable.

Default unsigned (?)

The default mode is unsigned.

Allow introducing explicit UBs

Exact mechanism TBD. For the time being, this will be phrased as an assert.

void func(int a, int b) {
  assert(a>5);
  // It is undefined what happens if a==4 at this point, even in release build
}

This can affect the C compatibility rule above:

int func(unsigned short a, unsigned short b) {
  assert(a<10);
  assert(b<20);
  return a+b; // No warning, as no short overflow could happen
}

Function attributes

I'm using the D notation here. Final syntax TBD.

Clone this wiki locally