question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement -then -else for Ternary operator

See original GitHub issue

Considering 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:open
  • Created 4 years ago
  • Reactions:8
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
rkeithhillcommented, Sep 22, 2019

If you want a bit more verboseness what is wrong with just using the existing if statement if ($x) {$y} else {$z}? I honestly don’t see much advantage of adding -then / -else operators. It saves two chars:

$x -then $y -else $z
if ($x) {$y} else {$z}

And only one char if your code style is:

$x -then $y -else $z
if($x) {$y} else {$z}
5reactions
lzybkrcommented, Sep 23, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found