icerpc / slicec

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

Preferred formatting for `:` #573

Closed bernardnormier closed 1 year ago

bernardnormier commented 1 year ago

In Slice, we use : between a name and a type in parameters, return elements and fields. In this case, there is no space after the name, for example:

name: string

We also use : for inheritance: interface inheritance, class inheritance and to specify an enum underlying (backing?) type. In this case, there is a space before the :, for example

enum Fruit : uint8 { Apple }

interface Rectangle : Shape { ... }

class Car : Vehicle { ... }
InsertCreativityHere commented 1 year ago

I'm fine with this new style, but just for context, we do already have a preferred formatting: The leading space should always be omitted, and the trailing space should always be present. For data members and inheritance and anywhere a single colon is used.

This style is: 1) More consistent (since it's the same everywhere) 2) What Rust does (see: https://doc.rust-lang.org/rust-by-example/trait/supertraits.html)

I understand the proposed format is common in C#, but since we've moved the syntax of Slice away from C# and towards Rust, following the Rust style made more sense. But again, Slice is it's own language and can use whatever syntax, just wanted to explain the reasoning behind the current style and make sure everyone knew it wasn't an arbitrary choice.

InsertCreativityHere commented 1 year ago

This was implemented in #607 and https://github.com/icerpc/icerpc-csharp/pull/3324