6
1
One of the annoying bits about PowerShell, which helps amplify its disadvantage against other languages in code-golf, is that there are no symbolic comparison or logical operators.
A comparison that could be as short as this:
$x<10&&$x>5
Has to be:
$x-lt10-and$x-gt5
This bloats the code for even the simplest of comparisons by about 50% compared to many other regular scripting and programming languages, never mind any golfing languages. Even an Excel formula for a similar comparison comes up shorter by one character!
=AND(A1<10,A1>5)
Another one that really bugs me:
$x==$k&&$i>9&&$i%10!=0
Has to be:
$x-eq$k-and$i-gt9-and$i%10-ne0
Interestingly, this one's exactly as long as the comparable formula for Excel, but that's mainly due to Excel's lack of a symbolic modulus operator.
=AND(A1=B1,C1>9,MOD(C1,10)<>0)
Is there a way this can be shortened at all, or is this strictly a limitation of the language? Are there any particular scenarios to keep in mind where shortcuts can be used for joining multiple comparisons?
1"Use GNU/Linux's bash instead!" - flag as offensive. ;) (those symbols are file IO redirection and PowerShell designers didn't want to overload them anymore. It also makes all the comparators take the same format -comparator instead of having a mix like
< > == -contains -in -match
) – TessellatingHeckler – 2015-12-18T02:38:09.5602Use GNU/Linux's [tag:bash] instead! :
(( 5 < x && x < 10))
;-) – F. Hauri – 2013-11-27T21:15:02.763