icerpc / slicec

The Slice compiler library
Apache License 2.0
13 stars 5 forks source link

Should we use Braces Instead of Parenthesis for Associated Fields? #665

Closed InsertCreativityHere closed 9 months ago

InsertCreativityHere commented 10 months ago

As of #664, the syntax for enumerators with associated fields looks like:

enum E {
    Foo(b: bool)
}

Should we switch to use braces instead:

enum E {
    Foo { b: bool }

    Bar {
        d: Dictionary<string, ::WellKnownTypes::SomeLongName>
        tag(12) bool?
        tag(13) ::MyApplication::MySliceType
    }
}

1) Braces are consistent with structs, classes, etc. You know, all the other things that contain fields. Whereas parenthesis are only used for operations. Since these are associated fields and not associated parameters, using braces would be slightly more logical I think.

2) It's consistent with Rust's syntax. There are 2 syntaxes for enumerators: tuple-like syntax and struct-like syntax. -Tuple like syntax doesn't use identifiers, it's a tuple of types: (bool, string, Foo). -Struct like syntax does use identifiers, and is written like a struct: { b: bool, s: string, f: Foo } Note that Swift uses parenthesis, although from my (not extensive) googling, tuple syntax seems much more common in Swift than it does in Rust.

3) It's more common to put spaces around braces; usually you don't put spaces around parenthesis. I think the extra space improves readability.

bernardnormier commented 9 months ago

I prefer the parenthesis - operation-like - syntax.