{"action":"created","issue":{"url":"https://api.github.com/repos/jolie/jolie/issues/27","labels_url":"https://api.github.com/repos/jolie/jolie/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/jolie/jolie/issues/27/comments","events_url":"https://api.github.com/repos/jolie/jolie/issues/27/events","html_url":"https://github.com/jolie/jolie/issues/27","id":67428757,"number":27,"title":"Internal services","user":{"login":"fmontesi","id":2077129,"avatar_url":"https://avatars.githubusercontent.com/u/2077129?v=3","gravatar_id":"","url":"https://api.github.com/users/fmontesi","html_url":"https://github.com/fmontesi","followers_url":"https://api.github.com/users/fmontesi/followers","following_url":"https://api.github.com/users/fmontesi/following{/other_user}","gists_url":"https://api.github.com/users/fmontesi/gists{/gist_id}","starred_url":"https://api.github.com/users/fmontesi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmontesi/subscriptions","organizations_url":"https://api.github.com/users/fmontesi/orgs","repos_url":"https://api.github.com/users/fmontesi/repos","events_url":"https://api.github.com/users/fmontesi/events{/privacy}","received_events_url":"https://api.github.com/users/fmontesi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jolie/jolie/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/jolie/jolie/labels/help%20wanted","name":"help wanted","color":"159818"}],"state":"closed","locked":false,"assignee":{"login":"mawolf","id":1853858,"avatar_url":"https://avatars.githubusercontent.com/u/1853858?v=3","gravatar_id":"","url":"https://api.github.com/users/mawolf","html_url":"https://github.com/mawolf","followers_url":"https://api.github.com/users/mawolf/followers","following_url":"https://api.github.com/users/mawolf/following{/other_user}","gists_url":"https://api.github.com/users/mawolf/gists{/gist_id}","starred_url":"https://api.github.com/users/mawolf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mawolf/subscriptions","organizations_url":"https://api.github.com/users/mawolf/orgs","repos_url":"https://api.github.com/users/mawolf/repos","events_url":"https://api.github.com/users/mawolf/events{/privacy}","received_events_url":"https://api.github.com/users/mawolf/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/jolie/jolie/milestones/3","html_url":"https://github.com/jolie/jolie/milestones/v1.4","labels_url":"https://api.github.com/repos/jolie/jolie/milestones/3/labels","id":1089134,"number":3,"title":"v1.4","description":"Jolie v1.4","creator":{"login":"fmontesi","id":2077129,"avatar_url":"https://avatars.githubusercontent.com/u/2077129?v=3","gravatar_id":"","url":"https://api.github.com/users/fmontesi","html_url":"https://github.com/fmontesi","followers_url":"https://api.github.com/users/fmontesi/followers","following_url":"https://api.github.com/users/fmontesi/following{/other_user}","gists_url":"https://api.github.com/users/fmontesi/gists{/gist_id}","starred_url":"https://api.github.com/users/fmontesi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmontesi/subscriptions","organizations_url":"https://api.github.com/users/fmontesi/orgs","repos_url":"https://api.github.com/users/fmontesi/repos","events_url":"https://api.github.com/users/fmontesi/events{/privacy}","received_events_url":"https://api.github.com/users/fmontesi/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":3,"state":"open","created_at":"2015-04-29T12:17:39Z","updated_at":"2015-06-01T10:50:49Z","due_on":null,"closed_at":null},"comments":25,"created_at":"2015-04-09T18:59:34Z","updated_at":"2015-06-01T10:50:49Z","closed_at":"2015-06-01T10:50:49Z","body":"Hi all,\r\n\r\nI'm reposting this from my original e-mail to the mailing list for Jolie 1.2. I've postponed this feature due to lack of discussion, so I'd like to rekindle that here.\r\n\r\n# Motivation\r\n\r\nRight now doing procedural programming in Jolie is a pain, as we do not support local variables in defined procedures. This is *intentionally* painful, as using procedures too much can make it hard to switch to a distributed implementation based on communications later on.\r\n\r\nA procedure basically acts as a request-response invocation: we call it, and then we wait until it's done. Therefore we usually implement recursive algorithms by having a service call itself on one of its operations (e.g., [see here](http://thesave.github.io/jolie/microservices/tutorials/2015/02/03/Implementing%20QuickSort-as-a-MicroService.html)). This is a bit cumbersome sometimes and promotes bad design (algorithms should be implemented in a separate service most of the time, but creating separate services is a bother sometimes). So we need syntax sugar! All the elements are basically there, we only need to find a nice syntax and do some plumbing in the interpreter to make it work by using the mechanisms we already have. So what I would really like to have is the possibility of defining lightweight \"internal\" services inside of a Jolie program.\r\n\r\n# Requirements\r\n\r\n* Internal services should be easy to code, as in quicker than coding a fully-fledged Jolie service. We want syntax sugar. The whole reason for introducing them is to avoid the bother of defining a separate Jolie file to embed, with its interface and ports everything.\r\n* We should also be able to have many internal services with different names, so that the programmer is left free to split operations as she sees fit.\r\n* Finally, internal services should have the same lifecycle as a normal embedded service.\r\n\r\n# Initial Proposal\r\n\r\nWe introduce a keyword, e.g., \"service\", to define internal services that works like this:\r\n\r\n<pre>\r\ninterface SrvIface {\r\nOneWay: op(void)\r\nRequestResponse: op2(T)(T2)\r\n}\r\n\r\nservice Srv {\r\nInterfaces: SrvIface\r\nCode: {\r\n    [ op1() ] { ... }\r\n    [ op2(x)(y) { ... } ]\r\n}\r\n}\r\n</pre>\r\n\r\nSrv would work as an embedded service, so this would get compiled to:\r\n\r\n<pre>\r\noutputPort Srv {\r\nInterfaces: SrvIface\r\n}\r\n\r\nembedded {\r\nJolie: *internal reference to the code of the Srv* in Srv\r\n}\r\n</pre>\r\n\r\nSo that now we can use Srv inside of our Jolie program:\r\n\r\n<pre>\r\nmain {\r\n    op2@Srv( x )( y )\r\n}\r\n</pre>\r\n\r\n# Discussion points\r\n\r\n* Should Srv inherit anything from the enclosing service? Some examples follow.\r\n* Can Srv use the output ports of the main service?\r\n* Which state should the processes created by Srv access? Should they start with a clean state (no variables instantiated), a copy of the state of the init procedure from the main service (as do all processes started in the main service), or a copy of the state of the caller process from the main service that invokes the operation in Srv?\r\n* Syntax: here's an alternative below. You may have other ideas, please share.\r\n\r\n<pre>\r\nservice Srv implements SrvIface {\r\n    [ op1() ] { ... }\r\n    [ op2(x)(y) { ... } ]\r\n}\r\n</pre>\r\n\r\nAbout the first three points, if we want to stay on the safe side we may start by using a clean slate (no variables instantiated at all, the internal service is completely independent), which is what I like best for now. We may also actually want internal services to have an init procedure like regular services:\r\n\r\n<pre>\r\nservice Srv {\r\nInterfaces: SrvIface\r\ninit {\r\n    ...\r\n}\r\nmain {\r\n    [ op1() ] { ... }\r\n    [ op2(x)(y) { ... } ]\r\n}\r\n}\r\n</pre>"},"comment":{"url":"https://api.github.com/repos/jolie/jolie/issues/comments/107398044","html_url":"https://github.com/jolie/jolie/issues/27#issuecomment-107398044","issue_url":"https://api.github.com/repos/jolie/jolie/issues/27","id":107398044,"user":{"login":"fmontesi","id":2077129,"avatar_url":"https://avatars.githubusercontent.com/u/2077129?v=3","gravatar_id":"","url":"https://api.github.com/users/fmontesi","html_url":"https://github.com/fmontesi","followers_url":"https://api.github.com/users/fmontesi/followers","following_url":"https://api.github.com/users/fmontesi/following{/other_user}","gists_url":"https://api.github.com/users/fmontesi/gists{/gist_id}","starred_url":"https://api.github.com/users/fmontesi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fmontesi/subscriptions","organizations_url":"https://api.github.com/users/fmontesi/orgs","repos_url":"https://api.github.com/users/fmontesi/repos","events_url":"https://api.github.com/users/fmontesi/events{/privacy}","received_events_url":"https://api.github.com/users/fmontesi/received_events","type":"User","site_admin":false},"created_at":"2015-06-01T10:50:49Z","updated_at":"2015-06-01T10:50:49Z","body":"Cool, I'm closing this for now then. Let's re-open it if we find other issues."}}