icerpc / slicec

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

Slice: switch from C-style to Pascal-style #28

Closed bernardnormier closed 2 years ago

bernardnormier commented 3 years ago

The Slice language is currently a C-style language, with:

This is a proposal to switch to a Pascal / Rust / Swift -like syntax:

For example:

// existing Slice
interface Greeter
{
    string greet(string message);
}

becomes:

interface Greeter
{
    rpc greet(message: string) -> string;
}

There are two advantages to switching:

The only C-style language we want to support with IceRPC is C#.

Note that Protobuf is an unusual mix of both styles: message definitions use C-style while rpc definitions use Pascal style.

externl commented 3 years ago

Sounds good to me.

  1. I prefer , for data member separators.
  2. I don't think we need the rpc keyword. Not all languages do this. For instance, Go goes not use func in interface definitions.

Another benefit of this style is that it's not longer ambiguous if operation attributes are attached to the operation or the return value.

InsertCreativityHere commented 3 years ago

return values would move to the right handside after an arrow as in rpc op() -> int

I'm in favor of adopting the arrow syntax. I think it's clear what is attached to the function and what is attached to the return type this way (and it's easier to parse!), but I don't think the rpc is necessary here. Only operations can appear in an interface, so there's no ambiguity here that we'd need a keyword to fix.

TBD use comma or semicolon for data member separators?

I think I also prefer ,. Structs are closer to things like tuples and parameters, which already use ,.

Otherwise, I agree! I think this syntax is an improvement over our current Slice syntax.

pepone commented 3 years ago

I like this new syntax but I agree with Austin that rpc keyword seems unnecessary.

I think we should also use comma for struct/class/exception fields separator and allow a trailing comma

struct Foo {
   x: int,
   y: int, // Trailing comma should be accepted
}
InsertCreativityHere commented 2 years ago

The style was changed in #71 and https://github.com/zeroc-ice/icerpc-csharp/pull/709