existential operator (I want your feedback)

22 views
Skip to first unread message

Alexander Tsepkov

unread,
Mar 29, 2015, 6:15:23 PM3/29/15
to RapydScript
Hey guys, now that RapydScript uses strict equality (=== vs ==) I find myself needing to check both null and undefined more and more and this is a problem for two reasons:

- it's a PITA even for devs who're aware of this and makes it easier to write buggy code
- devs unfamiliar with JS are likely to just do a check against None (null) and call it a day

I want to address this, so I would love your feedback either in this thread or in the issue tracker, where I have opened an issue against this already: https://github.com/atsepkov/RapydScript/issues/42

CoffeeScript already handles this via a? operator, I don't want to introduce extra operators that reduce the readability of code, so that's out.

Basically, my proposed solution boils down to either adding exists() function that gets converted to the following at compile time:

typeof a !== "undefined" && a !== null
Or converting "is not None" check to that instead. The drawback for the first solution is that Python code may need a bit more massaging to work in JS, the drawback of the second is that sometimes one may want to compare against null (None) but not undefined, although I can technically allow them to do that via '!= None', which wouldn't kick in the conversion.

If you've written significant amount of RapydScript to form an opinion, I'd love to hear you feedback, either here or in the issue itself.

Alexander Tsepkov

unread,
Mar 29, 2015, 6:21:44 PM3/29/15
to RapydScript
Also, I want to add that currently, RapydScript compiles `is` and `==` to identical `===` operation, just like `is not` and `!=` both compile to `!==`. In a sense, `is` operator is currently useless. Using it to give the compiler a green light to be more aggressive with it's null checks may indeed be a good use case for it (even if a bit unpythonic, since in Python the point of it is to do identity check (which is already forced on non-primitive objects using ==/=== in JS) vs equality).
Reply all
Reply to author
Forward
0 new messages