{"action":"created","issue":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/3239","repository_url":"https://api.github.com/repos/PowerShell/PowerShell","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/3239/labels{/name}","comments_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/3239/comments","events_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/3239/events","html_url":"https://github.com/PowerShell/PowerShell/issues/3239","id":211502211,"number":3239,"title":"Suggestion: implement ternary conditionals","user":{"login":"mklement0","id":588825,"avatar_url":"https://avatars2.githubusercontent.com/u/588825?v=4","gravatar_id":"","url":"https://api.github.com/users/mklement0","html_url":"https://github.com/mklement0","followers_url":"https://api.github.com/users/mklement0/followers","following_url":"https://api.github.com/users/mklement0/following{/other_user}","gists_url":"https://api.github.com/users/mklement0/gists{/gist_id}","starred_url":"https://api.github.com/users/mklement0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mklement0/subscriptions","organizations_url":"https://api.github.com/users/mklement0/orgs","repos_url":"https://api.github.com/users/mklement0/repos","events_url":"https://api.github.com/users/mklement0/events{/privacy}","received_events_url":"https://api.github.com/users/mklement0/received_events","type":"User","site_admin":false},"labels":[{"id":401720878,"url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Area-Language","name":"Area-Language","color":"5319e7","default":false},{"id":311043050,"url":"https://api.github.com/repos/PowerShell/PowerShell/labels/Issue-Enhancement","name":"Issue-Enhancement","color":"fc2929","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/PowerShell/PowerShell/milestones/26","html_url":"https://github.com/PowerShell/PowerShell/milestone/26","labels_url":"https://api.github.com/repos/PowerShell/PowerShell/milestones/26/labels","id":2357762,"number":26,"title":"6.1.0-Consider","description":"Issues under consideration for 6.1.0 release.  As plans formalize, issues will be moved to a more specific milestone.\r\n\r\nTargeting Developers/DevOps: Classes improvements, Debugging improvements, Parallel/Async, Troubleshooting at scale (e.g. error experience), replace ps1xml with DSLs.  Interactive Console Improvements: Invest in PSReadline, Curses support, console rendering of markdown, native markdown support for HelpSystem. Cmdlet coverage: Systems management on non-Windows","creator":{"login":"SteveL-MSFT","id":11859881,"avatar_url":"https://avatars1.githubusercontent.com/u/11859881?v=4","gravatar_id":"","url":"https://api.github.com/users/SteveL-MSFT","html_url":"https://github.com/SteveL-MSFT","followers_url":"https://api.github.com/users/SteveL-MSFT/followers","following_url":"https://api.github.com/users/SteveL-MSFT/following{/other_user}","gists_url":"https://api.github.com/users/SteveL-MSFT/gists{/gist_id}","starred_url":"https://api.github.com/users/SteveL-MSFT/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SteveL-MSFT/subscriptions","organizations_url":"https://api.github.com/users/SteveL-MSFT/orgs","repos_url":"https://api.github.com/users/SteveL-MSFT/repos","events_url":"https://api.github.com/users/SteveL-MSFT/events{/privacy}","received_events_url":"https://api.github.com/users/SteveL-MSFT/received_events","type":"User","site_admin":false},"open_issues":175,"closed_issues":58,"state":"open","created_at":"2017-03-02T00:56:08Z","updated_at":"2018-04-23T17:29:37Z","due_on":"2018-06-30T07:00:00Z","closed_at":null},"comments":12,"created_at":"2017-03-02T20:06:34Z","updated_at":"2018-04-24T02:47:23Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"C-style ternary conditionals would be a handy addition to the language.\r\n\r\nFor instance, instead of writing:\r\n\r\n```powershell\r\nif ((get-date).tostring(\"ss\") % 2) { 'odd'  } else  { 'even' }\r\n```\r\n\r\none could write:\r\n\r\n```powershell\r\n(get-date).tostring(\"ss\") % 2   ?   'odd'   :    'even'\r\n```\r\n\r\nIt would also relieve a long-standing disappointment:\r\n\r\n> At Microsoft, “to ship is to choose”.  One of the things we were very disappointed in not being able to ship in V1.0 is a ternary operator.\r\n\r\nFrom a [PowerShell Team blog post](https://blogs.msdn.microsoft.com/powershell/2006/12/29/diy-ternary-operator/) dated 29 December 2006.\r\n\r\n---\r\n\r\nRelated: [implement null-coalescence and null-soaking](https://github.com/PowerShell/PowerShell/issues/3240)"},"comment":{"url":"https://api.github.com/repos/PowerShell/PowerShell/issues/comments/383785954","html_url":"https://github.com/PowerShell/PowerShell/issues/3239#issuecomment-383785954","issue_url":"https://api.github.com/repos/PowerShell/PowerShell/issues/3239","id":383785954,"user":{"login":"rkeithhill","id":5177512,"avatar_url":"https://avatars1.githubusercontent.com/u/5177512?v=4","gravatar_id":"","url":"https://api.github.com/users/rkeithhill","html_url":"https://github.com/rkeithhill","followers_url":"https://api.github.com/users/rkeithhill/followers","following_url":"https://api.github.com/users/rkeithhill/following{/other_user}","gists_url":"https://api.github.com/users/rkeithhill/gists{/gist_id}","starred_url":"https://api.github.com/users/rkeithhill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkeithhill/subscriptions","organizations_url":"https://api.github.com/users/rkeithhill/orgs","repos_url":"https://api.github.com/users/rkeithhill/repos","events_url":"https://api.github.com/users/rkeithhill/events{/privacy}","received_events_url":"https://api.github.com/users/rkeithhill/received_events","type":"User","site_admin":false},"created_at":"2018-04-24T02:47:23Z","updated_at":"2018-04-24T02:47:23Z","author_association":"CONTRIBUTOR","body":"Maybe it's just me but I find this:\r\n```\r\nget-content ((test-path foo.txt) ? \"foo.txt\" : \"bar.txt\")\r\n```\r\n**way easier** to visually scan/parse than this:\r\n```\r\nget-content $(if (test-path foo.txt) {\"foo.txt\"} else {\"bar.txt\"})\r\n```\r\nMy only compliant about this issue is that if you're going to do ternary `?:` then you should also do null-coalescing `??`:\r\n```\r\n$logDir = $env:LogDir ?? \"$PSScriptRoot\\Log\"\r\n```\r\nI've seen a number of Invoke-Ternary and Invoke-NullCoalescing implementations in the wild (e.g. https://github.com/dahlbyk/posh-git/blob/master/src/Utils.ps1#L12).  That kind of indicates there is a general desire for such a feature baked into the language."}}
{"actor":{"display_login":"rkeithhill"}}