[Python-ideas] Towards harmony with JavaScript?

Alberto Berti alberto at metapensiero.it
Fri Aug 11 19:46:50 EDT 2017


>>>>> "Carl" == Carl Smith <carl.input at gmail.com> writes:

    Carl> Python is not a good fit for the browser, in part, because of the syntax.
    Carl> JavaScript has issues, but its syntax is better suited to creating GUIs in
    Carl> the browser.

Just so?

    Carl> For example, in browsers everything revolves around a single
    Carl> threaded event loop, so you have a lot of callbacks and event
    Carl> handlers,

You can write applications full of callbacks using libraries like
Twisted or even asyncio and you can build entire applications involving
ajax and such without callbacks as JS got async/await too in ES8 

event handlers are written more or less the same in Pyhton or
Javascript

    Carl> which makes function expressions really useful, but Python doesn't have
    Carl> expressions that contain blocks, because of significant
    Carl> indentation.

yes, i agree that the difference between lambda an anonymous function is
very significant on the way you may think to write your code.
    
    Carl> As a result, ordinary JS, like this...

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

I don't think you mean this is real JS application code :-)

    Carl> ...ends up looking like this...

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

or just

   jQuery(lambda: jQuery("spam").click(lambda: alert("spam clicked")))
    

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

language specific features... like?




More information about the Python-ideas mailing list