Code Monkey home page Code Monkey logo

Comments (8)

atsepkov avatar atsepkov commented on July 20, 2024 1

@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 if block. The ng version of the project attempts to stay more pure to the Python syntax (including objects/arrays) at the expense of some performance. You're more than welcome to use that, if it's more suitable to your needs.

from rapydscript.

kovidgoyal avatar kovidgoyal commented on July 20, 2024

This is implemented in rapydscript-ng

from rapydscript.

kovidgoyal avatar kovidgoyal commented on July 20, 2024

kovidgoyal/rapydscript-ng@9c508b2

from rapydscript.

atsepkov avatar atsepkov commented on July 20, 2024

FYI, still on the fence about this one. In your version, you changed the syntax for ternary conditional, so the choice of ? makes sense. In my version, like in CoffeeScript, the whitespace before that ? would completely change its meaning, which I don't like.

from rapydscript.

kovidgoyal avatar kovidgoyal commented on July 20, 2024

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 ? operator for this purpose. Given the prevalanece of undefined and null throughout the JS ecosystem, I for one find an existential operator very useful.

from rapydscript.

atsepkov avatar atsepkov commented on July 20, 2024

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:

a = condition ? then : else

vs

if condition:
    a = then
else:
    a = else

What I don't like about Python's version of ternary, however, is that it flips then and condition.

from rapydscript.

kovidgoyal avatar kovidgoyal commented on July 20, 2024

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.

from rapydscript.

jayvdb avatar jayvdb commented on July 20, 2024

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 (print(1 if 1 else 2)), that function needs to be injected into the scope of the expression, before the expression.

Glad to see that rapydscript-ng supports this; I'll need to use that until if-exp support is added to the original project.

from rapydscript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.