We are struggling with whether or not to make a change in our comparison operators and would like feedback from the community.
Here is the documentation about comparision operators:
All comparison operators are case-insensitive by default. To make a comparison operator
case-sensitive, precede the operator name with a “c”. For example, the case-sensitive
version of “-eq” is “-ceq”. To make the case-insensitivity explicit, precede the operator
with an “i”, for example, the explicitly case-insensitive version of “-eq” is “ieq”.
Here are examples of the current -EQ semantics:
PS> “a” -eq “A”
True
PS> [char]’a’ -eq ‘a’
True
PS> 2 -eq 2
True
Notice that -EQ works with Strings, Chars, and INTs (and lots of other things).
Now for the headache:
PS> [char]’a’ -eq ‘A’
False
PS> [char]’a’ -ieq ‘A’
False
<Update: Notice that you get FALSE whether you use -eq (EQUALS) or -ieq (CASE INSENSITIVE EQUALS) >
What is happening here is that CHARs are being treated like INTs and not like STRINGs. In our bug triage, we the feeling was that this was clearly a bug and should be fixed but someone pointed out that this if a script made use of these semantics, fixing the bug would break that script. There are 2 things to say about that:
- Whenever you fix a bug, you run the risk of breaking a script.
- We are committed to making V2 useful and compatible with V1.
So you see the rub. We’d like your help and input on this decision. I’m fine getting feedback on the “general principles” of the issue – understanding how you think about these issues is very helpful to us. That said, I’m also keenly interested in comments about the specifics of this problem. If we make THIS change, do you think it will break scripts? If so, should we fix this anyway or not?
We struggled with this decision and had lots of back and forth on this and could go either way. In the end, we decided that a key stackholder wasn’t in the room: YOU.
Please opine.
<UPDATE: BTW 10,000 apologizes for this situation in the first place. I should have started with that.>
Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx
0 comments