Nick Jensen wrote:

>  I agree that this should be an error. In javascript an empty array is
>  truthy, which is a constant source of errors and confusion.
> 
> ```javascript
> var arr = [];
> console.log(!!arr); // true
> arr = null;
> console.log(!!arr); // false
> ```

Yes, that's one of the things where Javascript/TypeScript is behaving
counter-intuitively.  Let's avoid that.

> I think a type error here would lead to better and more readable code.

As mentioned before, I had been trying to follow TypeScript.  But if we
are going to divert anyway, the question comes up if we should follow
TypeScript at all.

Assuming we require a condition to evaluate to a boolean, not a string,
list, etc., the question comes up what to do with "&&" and "||".  In
TypeScript it is useful to do something like:

        result = computed || 'empty'

If we go back to having "&&" and "||" resulting in true or false, then
we need something else for that.  A trinary condition is a bit long:

        result = computed ? computed : 'empty'

That can be shortened by introducing a new operator:

        result = computed ?: 'empty'

Which is actually better, since here we don't expect "computed" to be a
boolean.

There is less use for this with "&&", "this && that" would always result
in "false" or "that", where "false" could be either the falsy "this" or
the falsy "that", the difference is hardly ever useful.

-- 
The budget process was invented by an alien race of sadistic beings who
resemble large cats.
                                (Scott Adams - The Dilbert principle)

 /// 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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202009251101.08PB12EZ455463%40masaka.moolenaar.net.

Raspunde prin e-mail lui