2016-02-09 0:08 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> Takuya Fujiwara wrote:
>
>> On Mon, Feb 8, 2016 at 6:48 PM, Bram Moolenaar <[email protected]> wrote:
>> >
>> > [adjusted the subject, it was "Why is v:none needed"]
>> >
>> > Takuya Fujiwara wrote:
>> >
>> >> > [...]
>> >> >
>> >> > > >> let json = jsonencode({"key": v:none})
>> >> > > >> if json is v:none
>> >> > > >> echoerr 'error!'
>> >> > > >> return ...
>> >> > > >> endif
>> >> > > >
>> >> > > > Well, let's just return an empty string. Returning a different type
>> >> > > > often makes it more complicated.
>> >> > >
>> >> > > I agree.
>> >> > > However, I think "E706: Variable type mismatch" should be removed
>> >> > > becase it is not so useful for me...
>> >> >
>> >> > Where do you get that? Or do you mean that the sticky type checking
>> >> > isn't all that useful in general? I've been wondering whether we would
>> >> > be better off without it.
>> >>
>> >> I don't think it is useful in lightweight languages
>> >> (I don't think *only* a strict type checking is useful).
>> >> A strict type checking is useful for a language which has a strong type
>> >> system.
>> >> Because we can detect errors by different types, and so on.
>> >
>> > At the time it seemed like a good idea, to have some type checking to
>> > avoid mistakes. Over time I can't say this has uncovered a problem. I
>> > did run into the error when I didn't want it. Currently I think we
>> > might be better off without it.
>> >
>> > So, let's ask: who finds the sticky type checking useful?
>>
>> +1.
>>
>> I'll show a example here, why we might be better off a sticky type checking.
>
> Sorry, I'm confused. Do you +1 sticky type checking or the removal?
>
>> for i in ['foo', 'bar', {'key': 'baz'}]
>> echo string(i)
>> endfor
>>
>> Will output:
>>
>> 'foo'
>> 'bar'
>> E706: Variable type mismatch for: i
>>
>> We need 'unlet i'.
>> It is easy to miss it...
>
> Well, this is both an argument for and against. It's helpful if you
> wanted to be warned about mixed types, it's annoying if you
> intentionally have mixed types.
I tend to have mixed types more often then fixed (mostly this is the
case in “generic” functions like the recursive map suggested by you in
thread about v:none), and usually sticky type checking is a *source*
of the bugs in this case, should I forget about it.
In cases when sticky type checking failure indicates a bug some type
error usually occurs later in expression like `let s = str_set_to_list
. "another str"` and this bug will be noticed immediately whether or
not sticky type checking errorred out. Most of time it is not hard to
trace where did that value come from.
On the other side in cases with iterating over containers I remember
cases when I added possibility for the container to contain a value of
another type and got an error some time later because I modified code
to work with new values in one place, but forgot `:unlet`. This means
that whenever I think container may contain values of different types
*now or in the future* I use `:unlet` and sticky type checking loses
any sense.
>
>> for i in ['foo', 'bar', {'key': 'baz'}]
>> echo string(i)
>>
>> " If you :continue here, you need to :unlet in the condition, too...
>> if ...
>> unlet i
>> continue
>> endif
>>
>> " We need this always!
>> unlet i
>> endfor
>
> --
> hundred-and-one symptoms of being an internet addict:
> 184. You no longer ask prospective dates what their sign is, instead
> your line is "Hi, what's your URL?"
>
> /// Bram Moolenaar -- [email protected] -- 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 ///
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.