-
Notifications
You must be signed in to change notification settings - Fork 67
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
add existential 'operator' #42
Comments
This is implemented in rapydscript-ng |
FYI, still on the fence about this one. In your version, you changed the syntax for ternary conditional, so the choice of |
Yeah, I can see how it is a problem for you. I got rid of the JS variant of the ternary conditional since there was no need for it, and it frees up the |
Agree, I've gotten quite accustomed to using it in Swift. I think you replaced the ternary with Pythonic conditional (http://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator) rather than getting rid of it completely, is that not the case? I find myself using the ternary quite often to make the assignment more clear:
vs
What I don't like about Python's version of ternary, however, is that it flips |
Yes, I replaced it with python's ternary conditional operator. Since I write a lot of python code, python's ternary conditional has become quite natural for me :) Although, I agree, that it seemed awkward when I started using it. And I too use the ternary conditional a lot, in all languages I write. Also, given that most of RapydScript's syntax is pythonic, it made sense to use the python form. |
As this discussion is covering the Python ternary operator, I'd like to note that it would be really nice the Python syntax was supported. I was surprised it is still not supported. To have the same effect without it, and still have valid Python code, one needs to create a function for the branch logic, and because it is an expression that could appear anywhere ( Glad to see that rapydscript-ng supports this; I'll need to use that until if-exp support is added to the original project. |
@jayvdb ternary operator was supported from day 1, it's just the JS syntax, not the Python one. As mentioned in the README and other discussions, the goal of the project was never 100% Python compatibility. The goal was to balance clarity and consistency of Python with JavaScript (and yes, there are cases when JS syntax is actually more consistent/clear than Python). To me, the ternary syntax of JS seemed cleaner than that of Python because it doesn't flip the conditional and |
CoffeeScript has the concept of existential operator:
a?
, which compiles to the following:Until recently, RapydScript used
==
for equality and as a result the need for such check was somewhat rare. With===
equality that the compiler now uses, such operator would be useful. Already I find myself checking against both null and undefined more and more often, this annoyance would further aggravate those coming from Python background and unfamiliar with JS quirks. Here are a couple alternatives I was thinking about for handling such an operator:Pros:
concise, readable and doesn't introduce funky operators that may be unfamiliar with Python devs
perl already has the same function, used for the same purpose (but typically for testing hash keys)
Cons:
Python devs may not be aware of the need for
exists()
testPros:
already widely used in Python code, optimizer could then take care of this compilation for us
is
operator is currently useless, as it's identical to==
Cons:
there may be legitimate reasons for checking against null and not undefined, which this would break
in Python,
is
is more strict than==
, this check would actually be less strict than==
(however, JS===
is already more likeis
in Python rather than==
for object types)The text was updated successfully, but these errors were encountered: