{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/832","repository_url":"https://api.github.com/repos/dotnet/csharplang","labels_url":"https://api.github.com/repos/dotnet/csharplang/issues/832/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/csharplang/issues/832/comments","events_url":"https://api.github.com/repos/dotnet/csharplang/issues/832/events","html_url":"https://github.com/dotnet/csharplang/issues/832","id":251406276,"node_id":"MDU6SXNzdWUyNTE0MDYyNzY=","number":832,"title":"Discussion: static variables","user":{"login":"alrz","id":3105979,"node_id":"MDQ6VXNlcjMxMDU5Nzk=","avatar_url":"https://avatars2.githubusercontent.com/u/3105979?v=4","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"labels":[{"id":537024200,"node_id":"MDU6TGFiZWw1MzcwMjQyMDA=","url":"https://api.github.com/repos/dotnet/csharplang/labels/Discussion","name":"Discussion","color":"c2e0c6","default":false},{"id":545773793,"node_id":"MDU6TGFiZWw1NDU3NzM3OTM=","url":"https://api.github.com/repos/dotnet/csharplang/labels/Feature%20Request","name":"Feature Request","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":19,"created_at":"2017-08-19T07:00:32Z","updated_at":"2018-08-16T21:03:45Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Originally proposed at https://github.com/dotnet/roslyn/issues/49, as it exists in VB,\r\n```cs\r\nstring[] M(string str) {\r\n  static var dot = new [] { '.' };\r\n  return str.Split(dot);\r\n}\r\n```\r\n\r\n\r\n------------\r\n\r\nAlternatively we could use `static` keyword on the expression that we want to cache,\r\n```cs\r\nstring[] M(string str) {\r\n  return str.Split(static new[] { '.' });\r\n}\r\n```\r\n**Open question:** should this turn to a class-level initializer or it should be initialized lazily as in VB?\r\n**Open question:** would it make sense to generate a non-static field for a cached value?\r\n\r\nPossible translations for the following:\r\n```cs\r\nobject O => static new object();\r\n```\r\n->\r\n```cs\r\n// eager + static field\r\nstatic object o = new object();\r\nobject O => o;\r\n\r\n// eager + instance field\r\nobject o = new object();\r\nobject O => o;\r\n\r\n// lazy + static field (similar to VB except for thread-safety)\r\nstatic object o;\r\nobject O => o ?? (o = new object());\r\n\r\n// lazy + instance field\r\nobject o;\r\nobject O => o ?? (o = new object());\r\n```\r\nplus thread safe variants (note: for value types we should probably use a boolean for lazy initialization.)\r\n\r\n**Open question:** would it worth it to use different keywords to specify a particular translation?"},"comment":{"url":"https://api.github.com/repos/dotnet/csharplang/issues/comments/413684207","html_url":"https://github.com/dotnet/csharplang/issues/832#issuecomment-413684207","issue_url":"https://api.github.com/repos/dotnet/csharplang/issues/832","id":413684207,"node_id":"MDEyOklzc3VlQ29tbWVudDQxMzY4NDIwNw==","user":{"login":"CyrusNajmabadi","id":4564579,"node_id":"MDQ6VXNlcjQ1NjQ1Nzk=","avatar_url":"https://avatars3.githubusercontent.com/u/4564579?v=4","gravatar_id":"","url":"https://api.github.com/users/CyrusNajmabadi","html_url":"https://github.com/CyrusNajmabadi","followers_url":"https://api.github.com/users/CyrusNajmabadi/followers","following_url":"https://api.github.com/users/CyrusNajmabadi/following{/other_user}","gists_url":"https://api.github.com/users/CyrusNajmabadi/gists{/gist_id}","starred_url":"https://api.github.com/users/CyrusNajmabadi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyrusNajmabadi/subscriptions","organizations_url":"https://api.github.com/users/CyrusNajmabadi/orgs","repos_url":"https://api.github.com/users/CyrusNajmabadi/repos","events_url":"https://api.github.com/users/CyrusNajmabadi/events{/privacy}","received_events_url":"https://api.github.com/users/CyrusNajmabadi/received_events","type":"User","site_admin":false},"created_at":"2018-08-16T21:03:45Z","updated_at":"2018-08-16T21:03:45Z","author_association":"NONE","body":">  I would much rather have to type a few characters than create a class, or do some other really weird workarounds that I have to wrap my brain around.\r\n\r\nIt doesn't seem strange or weird, especially given the use case i was referring to.  When you have a collection of things that you want to group together, usign an existing language concept precisely created for that purpose seems natural and appropriate :)\r\n"}}
{"actor":{"display_login":"CyrusNajmabadi"}}