New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer is# and is? instead of ==# and ==? #233
Comments
We can't change this for legacy Vim script, it would break existing scripts. |
Problem with
happily compares string and list without error. I mostly want to get an error here. And |
I like being able to compare Strings and Lists without getting an error. What I did in the ALE codebase is add uses of |
I like being able to compare Strings and Lists without getting an
error. What I did in the ALE codebase is add uses of `grep` to ask you
to replace `==` and friends with `is` and friends, and there have been
fewer bugs ever since.
There are arguments both for ignoring types and for strict type
checking. I don't plan to change this for legacy Vim script. In Vim9
the plan is to have reasonable strict type checking. Thus comparing a
number with a string will give an error. In most cases that's the right
thing to do. You can use "string(theNumber) == theString" if you want
to. Or use string() on both sides if you don't know what the type will
be.
…--
What do you get when you cross a joke with a rehtorical question?
/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
|
That sounds horrible, and I hope it doesn't catch on. |
When you compare expressions with String literals, Vint will tell you to use
==#
or==?
instead of==
, as==
changes depending on user configuration, and Vint will do the same withis
and strings, preferringis#
andis?
. I think Vint should go one step further and disallow==#
or==?
for String literal comparisons too, and preferis#
oris?
instead.If you compare
0
with any string which does not contain numbers using==#
or==?
, The comparison will return1
. This is because with something like0 ==# 'foo'
, Vim converts the RHS to a Number, and that conversion yields0
, so the result is1
. This is almost certainly not what you want. This has been a source of bugs for my project.I would argue that if you're making a comparison between any value and a String, what you want is for that comparison to be true only if both sides of a comparison are String values. I think there's pretty much no reason to ever use
==#
or==?
, and you should useis#
oris?
instead.The text was updated successfully, but these errors were encountered: