[Python-ideas] Towards harmony with JavaScript?

Carl Smith carl.input at gmail.com
Fri Aug 11 18:31:27 EDT 2017


Python is not a good fit for the browser, in part, because of the syntax.
JavaScript has issues, but its syntax is better suited to creating GUIs in
the browser. For example, in browsers everything revolves around a single
threaded event loop, so you have a lot of callbacks and event handlers,
which makes function expressions really useful, but Python doesn't have
expressions that contain blocks, because of significant indentation. As a
result, ordinary JS, like this...

    $(function(){ $("spam").click(function(){ alert("spam clicked") }) });

...ends up looking like this...

    def on_ready():
        def click_handler(): alert("spam clicked")
        jQuery("spam").click(click_handler)
    jQuery(on_ready)

JS semantics means JS libraries, which have APIs that assume JS syntax.
Python library developers make heavy use of language specific features to
define elegant, Pythonic APIs, which is a big part of what makes the
language so nice to use.


-- Carl Smith
carl.input at gmail.com

On 11 August 2017 at 21:58, Chris Angelico <rosuav at gmail.com> wrote:

> On Sat, Aug 12, 2017 at 6:31 AM, Alberto Berti <alberto at metapensiero.it>
> wrote:
> > It's not really so confusing, most code I wrote with it it's perfectly
> > understandable Python code. For me, one thing is the language, one other
> > thing are the libraries or the builtin classes it's usually shipped
> > with.
> >
> > The tool reads valid Python and writes valid ES6 JavaScript. As the
> > documentation states, it allows you to retain most of Python language
> > semantics (like for example you can have a working
> > try...except...finally statement, instead of what vanilla JS gives you)
> > and some of the library semantics. nothing more, nothing less.
>
> Hold on. Make up your mind:
>
> > As of now, I do nothing. As I said, the goal of the tool is not to
> > shield you from JS, for this reason it's not meant for beginners (in
> > both JS or Python). You always manipulate JS objects, but allows you to
> > to be naive on all that plethora of JS idiosyncrasies (from a Python pow
> > at least) that you have to think about when you frequently switch from
> > python to js.
>
> Do you "retain most of Python language semantics", or do you "always
> manipulate JS objects"? As shown in a previous post, there are some
> subtle and very dangerous semantic differences between the languages.
> You can't have it both ways.
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170811/360b99e8/attachment-0001.html>


More information about the Python-ideas mailing list