Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should standard library service types be distinct #2398

Closed
shafreenAnfar opened this issue Nov 12, 2021 · 6 comments
Closed

Should standard library service types be distinct #2398

shafreenAnfar opened this issue Nov 12, 2021 · 6 comments
Labels
Team/PCM Protocol connector packages related issues Type/Question

Comments

@shafreenAnfar
Copy link
Contributor

At the moment all the standard library service type definitions looks as follows,

public type SomeService service object {};

which results in the below usages,

With service declaration

listener Listener l = new(); 
service /foo on l {
   // some resources
}

Without service declaration

public service class MyService {
   // some resources
}

public function main() returns error? {
    Listener l = check new;
    MyService myService = new;
    check l.attach(myService, "/foo");  
}

To ensure the structure of the service (MyService) complier plugin is engaged during the compile time.

However, if we make the service type definition distinct, the usage would be as follows.

public type SomeService distinct service object {};

With service declaration

listener Listener l = new(); 
service /foo on l {
   // some resource
}

No change in the usage.

Without service declaration

public service class MyService {
    *SomeService;
   // some resources
}

public function main() returns error? {
    Listener l = check new;
    MyService myService = new;
    check l.attach(myService, "/foo");  
}

To ensure the structure of the service (MyService) complier plugin is engaged during the compile time.

However, in this case,

  • Code becomes a bit more readable as we need to explicitly mention that MyService is a subtype of SomeService.
  • It allows us to distinguish one service from another during runtime using type-ids.
  • It becomes easier to write the complier plugin logic as we can easily distinguish MyService from the rest of the services in a given program.

Therefore, even though this is not a situation where we interop with a nominal type systems like Java or GraphQL, would it be a good idea to mark all the standard library services with distinct for SwanLake ?

@shafreenAnfar
Copy link
Contributor Author

@jclark we would like to get your suggestion on this.

@jclark
Copy link

jclark commented Nov 15, 2021

If your service object types are currently defined as empty (without any members), then I think adding distinct is a good idea.

@shafreenAnfar
Copy link
Contributor Author

Actually, there is a slight mistake in the original description. When a service type is marked as distinct, it actually impacts the service declaration. You have to explicitly mention the service type as below. Therefore, we decided not to make services distinct.

service MyService / on ll {
}

Without distinct

service / on ll {
}

@jclark
Copy link

jclark commented Nov 16, 2021

@shafreenAnfar I don't think that's a spec requirement (if it is, it shouldn't be).

@rdhananjaya
Copy link
Member

This is a spec deviation in inferring the static type of the service declaration.
Moving the issue to the ballerina-lang repo.

@rdhananjaya rdhananjaya transferred this issue from ballerina-platform/ballerina-library Nov 16, 2021
@rdhananjaya rdhananjaya self-assigned this Nov 16, 2021
@rdhananjaya rdhananjaya transferred this issue from ballerina-platform/ballerina-lang Nov 17, 2021
@shafreenAnfar shafreenAnfar added Type/Question Team/PCM Protocol connector packages related issues labels Nov 17, 2021
@rdhananjaya rdhananjaya removed their assignment Nov 17, 2021
@shafreenAnfar
Copy link
Contributor Author

As per the discussion we have update the standard library services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/PCM Protocol connector packages related issues Type/Question
Projects
None yet
Development

No branches or pull requests

3 participants