Implement -then -else for Ternary operator
See original GitHub issueConsidering the ternary operator was added using the syntax most friendly to c# developers and not general PowerShell users - i.e all your admin users,
I propose that the ternary operator should be further extended to also allow -then -else syntax
My reason for asking is simple - there are still many in the PowerShell community that want & prefer the verboseness of the language over other languages and find that the verboseness provides a much easier readability experience.
PowerShell is known for allowing users to pick syntax options that they are comfortable and giving -then -else
syntax would help bring the ternary operator to those users, that don’t come from the classical developer type roles.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Conditional (ternary) operator - JavaScript - MDN Web Docs
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark (?)
Read more >IF ELSE using ternary operator - javascript
Basically, I understand that a ternary operator takes three arguments. The first one (1st) is the condition, the second one (2nd) is executed...
Read more >How to Use the Ternary Operator in JavaScript
The ternary operator is a helpful feature in JavaScript that allows you to write concise and readable expressions that perform conditional ...
Read more >Rethinking the JavaScript ternary operator - James Sinclair
If someCondition evaluates as true then call the function takeAction with no arguments. Else, call the function someOtherAction with no ...
Read more >Make Your Code Cleaner with JavaScript Ternary Operator
This tutorial shows you how to use the JavaScript ternary operator as the shortcut of the if-else statement to make your code cleaner....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If you want a bit more verboseness what is wrong with just using the existing
if
statementif ($x) {$y} else {$z}
? I honestly don’t see much advantage of adding-then / -else
operators. It saves two chars:And only one char if your code style is:
Character count isn’t everything. Typing parentheses and braces is slightly awkward, and honestly it’s harder to read if/then/else on one line. Of course the ternary operator can be hard to read too, which is why my proposed syntax doesn’t seem universally hated.