{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/136","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/136/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/136/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/136/events","html_url":"https://github.com/dotnet/roslyn/issues/136","id":55840386,"number":136,"title":"[Proposal] Better handling of multiple comparisons with the same variable (`a > min && a < max`)","user":{"login":"ashmind","id":166396,"avatar_url":"https://avatars.githubusercontent.com/u/166396?v=3","gravatar_id":"","url":"https://api.github.com/users/ashmind","html_url":"https://github.com/ashmind","followers_url":"https://api.github.com/users/ashmind/followers","following_url":"https://api.github.com/users/ashmind/following{/other_user}","gists_url":"https://api.github.com/users/ashmind/gists{/gist_id}","starred_url":"https://api.github.com/users/ashmind/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ashmind/subscriptions","organizations_url":"https://api.github.com/users/ashmind/orgs","repos_url":"https://api.github.com/users/ashmind/repos","events_url":"https://api.github.com/users/ashmind/events{/privacy}","received_events_url":"https://api.github.com/users/ashmind/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Feature%20Request","name":"Feature Request","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Language-C%23","name":"Language-C#","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":9,"created_at":"2015-01-29T00:57:34Z","updated_at":"2015-10-19T09:51:25Z","closed_at":null,"body":"#### Problem\r\nConsider these very common code patterns:\r\n```csharp\r\nif (a > min && a < max) ...\r\nif (value == Enum.Value1 || value === Enum.Value2) ...\r\n```\r\nI think it is worth considering how verbosity here can be reduced -- especially since it could also give a performance benefit for cases like\r\n```csharp\r\nif (Slow() > min && Slow() < max) ...\r\n```\r\n\r\n#### Potential solutions\r\n\r\n##### A. Ternary comparisons\r\nFor `<`, `>`, `>=`, and `<=` one solution can be Python-like `min < a < max`.\r\n\r\n###### Pros:\r\n1. Good readability\r\n2. Performance benefit since `a` can be evaluated exactly once\r\n\r\n###### Cons:\r\n1. Does not handle `a == x || a == y`.\r\n\r\n##### B. Range comparisons\r\nExample:\r\n```csharp\r\nif (a in (min...max)) ...\r\nif (value in (Enum.Value1, Enum.Value2)) ...\r\nif (x in (1,2,3..7)) ...\r\n```\r\n\r\n###### Pros:\r\n1. Alright readability\r\n2. Covers many scenarios\r\n3. Can be easily adapted for future `switch` (`case 1..3:`).\r\n\r\n###### Cons:\r\n1. Not clear whether the range is inclusive or exclusive\r\n2. Too much new syntax for a simple case?\r\n\r\n##### C. Quantum superpositions\r\nExample:\r\n```csharp\r\nif (value == any(Enum.Value1, Enum.Value2)) ...\r\n```\r\nThis is similar to Perl's [Quantum Superpositions](http://search.cpan.org/~lembark/Quantum-Superpositions-2.02/lib/Quantum/Superpositions.pm) and something that was already implemented in Microsoft Research's [Cω](http://research.microsoft.com/en-us/um/cambridge/projects/comega/).\r\n\r\n###### Pros:\r\n1. Good readability\r\n2. Can be adapted for future `switch`\r\n\r\n###### Cons:\r\n1. In practice only covers equality (`x > any(1,2)` is possible, but useless in most scenarios). Could be combined with solution A for a limited comparison support."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/149169630","html_url":"https://github.com/dotnet/roslyn/issues/136#issuecomment-149169630","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/136","id":149169630,"user":{"login":"AdamSpeight2008","id":900107,"avatar_url":"https://avatars.githubusercontent.com/u/900107?v=3","gravatar_id":"","url":"https://api.github.com/users/AdamSpeight2008","html_url":"https://github.com/AdamSpeight2008","followers_url":"https://api.github.com/users/AdamSpeight2008/followers","following_url":"https://api.github.com/users/AdamSpeight2008/following{/other_user}","gists_url":"https://api.github.com/users/AdamSpeight2008/gists{/gist_id}","starred_url":"https://api.github.com/users/AdamSpeight2008/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AdamSpeight2008/subscriptions","organizations_url":"https://api.github.com/users/AdamSpeight2008/orgs","repos_url":"https://api.github.com/users/AdamSpeight2008/repos","events_url":"https://api.github.com/users/AdamSpeight2008/events{/privacy}","received_events_url":"https://api.github.com/users/AdamSpeight2008/received_events","type":"User","site_admin":false},"created_at":"2015-10-19T09:51:25Z","updated_at":"2015-10-19T09:51:25Z","body":"@alrz using `or` wouldn't work well for vb.net. The extension methods work for both languages, see \r\n(Exts.*)[https://www.nuget.org/profiles/adamspeight2008?showAllPackages=True]\r\n"}}