I find the syntax of Motoko a little confusing. See the annotated code below for an illustration of my concern. It isn’t a showstopper by any means, but seeing as Motoko is still an alpha product I feel like I may as well share my thoughts.
My thoughts
I think the shared use of {…} for both objects and blocks is a little confusing, given the similarity of their inner syntax. I know the use of curly braces is motivated by retaining a similarity to JavaScript, but I have a hunch that using a different syntax for blocks (square brackets? Python-esque syntax?) would remove some of the cognitive burden here.
That’s my two cents. What does everyone else think?
Code
(Note: the code window is scrollable)
// This is a basic object literal.
let a : {x : Int; y : Int} = {
x = 0;
y = 0;
};
// Once you add the "object" keyword, you need to start
// using "let", and you need to explicitly mark public fields.
let b : {x : Int; y : Int} = object {
public let x = 0;
public let y = 0;
};
// If we drop the "object" and "public" keywords we now
// have a block with type Nat. A bit confusing!
let c : Nat = {
let x = 0;
let y = 0;
};
// This is also a block!
let d : Nat = {
var x = 0;
let y = 0;
};
// If we drop the second declaration we now have an object again!
let e : {var x : Nat} = {
var x = 0;
//let y = 0;
};