kjsphinx.addnodesdocument)}( rawsourcechildren]docutils.nodessection)}(hhh](h title)}(hTranscrypt: what and whyh]h TextTranscrypt: what and why}(hhparenthhhsourceNlineNuba attributes}(ids]classes]names]dupnames]backrefs]utagnamehhh hhhQ/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/docs/sphinx/what_why.rsthKubh )}(hhh](h)}(hWhat is Transcrypth]hWhat is Transcrypt}(hh1hh/hhhNhNubah}(h ]h"]h$]h&]h(]uh*hhh,hhhh+hKubh paragraph)}(hTranscrypt is a tool to compile a fairly extensive subset of Python into compact, readable JavaScript. It has the following characteristics:h]hTranscrypt is a tool to compile a fairly extensive subset of Python into compact, readable JavaScript. It has the following characteristics:}(hhAhh?hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhh,hhubh enumerated_list)}(hhh](h list_item)}(hxIt's lightweight, in accordance Pareto’s rule adapted for IT: 99% of the result can be achieved with 1% of the effort.h]h>)}(hhVh]hzIt’s lightweight, in accordance Pareto’s rule adapted for IT: 99% of the result can be achieved with 1% of the effort.}(hhVhhXubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhTubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubhS)}(hdIt offers the semantic essence of Python along with the clean syntax that the language is famous forh]h>)}(hhmh]hdIt offers the semantic essence of Python along with the clean syntax that the language is famous for}(hhmhhoubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhkubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubhS)}(hOIt cooperates flawlessly with the JavaScript universe of web-oriented librariesh]h>)}(hhh]hOIt cooperates flawlessly with the JavaScript universe of web-oriented libraries}(hhhhubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubhS)}(hDIt translates Python into highly readable, easy to debug JavaScript h]h>)}(hCIt translates Python into highly readable, easy to debug JavaScripth]hCIt translates Python into highly readable, easy to debug JavaScript}(hhhhubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubeh}(h ]h"]h$]h&]h(]enumtypearabicprefixhsuffix.uh*hMhh,hhhh+hK ubh>)}(h%In two words: it's *lean* and *mean*.h](hIn two words: it’s }(hIn two words: it's hhhhhNhNubh emphasis)}(h*lean*h]hlean}(hhhhubah}(h ]h"]h$]h&]h(]uh*hhhubh and }(h and hhhhhNhNubh)}(h*mean*h]hmean}(hhhhubah}(h ]h"]h$]h&]h(]uh*hhhubh.}(hhhhhhhNhNubeh}(h ]h"]h$]h&]h(]uh*h=hh+hKhh,hhubeh}(h ]what-is-transcryptah"]h$]what is transcryptah&]h(]uh*h hh hhhh+hKubh )}(hhh](h)}(h*Language preferences, a subjective accounth]h*Language preferences, a subjective account}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhhhhhh+hKubh>)}(hX~Language preferences are largely subjective. For some developers, JavaScript is the language of choice. They are right. For others it's Python. They're equally right. It just fits the way of thinking of many. The word 'pythonic' says it all: Programming in Python can be a joy. And, apart from being its own reward, taking joy in one's work enhances quality like no other incentive.h]hXLanguage preferences are largely subjective. For some developers, JavaScript is the language of choice. They are right. For others it’s Python. They’re equally right. It just fits the way of thinking of many. The word ‘pythonic’ says it all: Programming in Python can be a joy. And, apart from being its own reward, taking joy in one’s work enhances quality like no other incentive.}(hj hj hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhhhhubh>)}(h)}(hj.h]h Python syntax}(hj.hj0ubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhj,ubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hSmall downloadsh]h>)}(hjEh]hSmall downloads}(hjEhjGubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjCubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(h3No barriers to the DOM or to any JavaScript libraryh]h>)}(hj\h]h3No barriers to the DOM or to any JavaScript library}(hj\hj^ubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjZubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hDynamic typingh]h>)}(hjsh]hDynamic typing}(hjshjuubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjqubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hMultiple inheritanceh]h>)}(hjh]hMultiple inheritance}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hStatic transpilationh]h>)}(hjh]hStatic transpilation}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(h Lambda’sh]h>)}(hjh]h Lambda’s}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hNamed and default parametersh]h>)}(hjh]hNamed and default parameters}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hLists, dicts and setsh]h>)}(hjh]hLists, dicts and sets}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hList and other comprehensionsh]h>)}(hjh]hList and other comprehensions}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hNested tuple assignmenth]h>)}(hjh]hNested tuple assignment}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hK!hjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hAssignment of bound functionsh]h>)}(hj+h]hAssignment of bound functions}(hj+hj-ubah}(h ]h"]h$]h&]h(]uh*h=hh+hK"hj)ubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(h'Locally controlled operator overloadingh]h>)}(hjBh]h'Locally controlled operator overloading}(hjBhjDubah}(h ]h"]h$]h&]h(]uh*h=hh+hK#hj@ubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(h Async / awaith]h>)}(hjYh]h Async / await}(hjYhj[ubah}(h ]h"]h$]h&]h(]uh*h=hh+hK$hjWubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(h Metaclassesh]h>)}(hjph]h Metaclasses}(hjphjrubah}(h ]h"]h$]h&]h(]uh*h=hh+hK%hjnubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(h1Modules, compilation units and a component loaderh]h>)}(hjh]h1Modules, compilation units and a component loader}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hK&hjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hOptional static typecheckingh]h>)}(hjh]hOptional static typechecking}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hK'hjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(h Source mapsh]h>)}(hjh]h Source maps}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hK(hjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubhS)}(hBuilt-in minification h]h>)}(hBuilt-in minificationh]hBuilt-in minification}(hjhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hK)hjubah}(h ]h"]h$]h&]h(]uh*hRhj)hhhh+hNubeh}(h ]h"]h$]h&]h(]bullet-uh*j'hh+hKhhhhubh>)}(hX'At the advent of Transcrypt there were many Python to JavaScript transpiler projects around, some of them quite mature. Neither of them fitted the above shopping list. Either the downloads were too large, or some of must have features were missing. To some, the shopping list may seem weird. Multiple inheritance? The whole Java world is doing without it. Exactly. And that's one of the reasons why a large category of developers shunned Java from the start. To them multiple inheritance has proven a powerful tool ever since it was introduced in C++.h]hX)At the advent of Transcrypt there were many Python to JavaScript transpiler projects around, some of them quite mature. Neither of them fitted the above shopping list. Either the downloads were too large, or some of must have features were missing. To some, the shopping list may seem weird. Multiple inheritance? The whole Java world is doing without it. Exactly. And that’s one of the reasons why a large category of developers shunned Java from the start. To them multiple inheritance has proven a powerful tool ever since it was introduced in C++.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK+hhhhubh>)}(hXFSo if it's all that subjective, why should *you* use it?. Well, *only if and when you like it*. That's all. In IT everything grows until it becomes unusable. One of the main goals of Transcrypt is to keep things simple, preventing it from disolution into an ocean of feature creep and conflicting demands. At its core it will stay lean and mean. For the rest: it's open. There's a hierarchical module system included right from the start, featuring Java-esque URL based unique package names. So, once the core of Transcrypt has stabilized, you're invited to help its ecosystem grow.h](h-So if it’s all that subjective, why should }(h+So if it's all that subjective, why should hjhhhNhNubh)}(h*you*h]hyou}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjubh use it?. Well, }(h use it?. Well, hjhhhNhNubh)}(h*only if and when you like it*h]honly if and when you like it}(hhhjubah}(h ]h"]h$]h&]h(]uh*hhjubhX. That’s all. In IT everything grows until it becomes unusable. One of the main goals of Transcrypt is to keep things simple, preventing it from disolution into an ocean of feature creep and conflicting demands. At its core it will stay lean and mean. For the rest: it’s open. There’s a hierarchical module system included right from the start, featuring Java-esque URL based unique package names. So, once the core of Transcrypt has stabilized, you’re invited to help its ecosystem grow.}(hX. That's all. In IT everything grows until it becomes unusable. One of the main goals of Transcrypt is to keep things simple, preventing it from disolution into an ocean of feature creep and conflicting demands. At its core it will stay lean and mean. For the rest: it's open. There's a hierarchical module system included right from the start, featuring Java-esque URL based unique package names. So, once the core of Transcrypt has stabilized, you're invited to help its ecosystem grow.hjhhhNhNubeh}(h ]h"]h$]h&]h(]uh*h=hh+hK-hhhhubeh}(h ])language-preferences-a-subjective-accountah"]h$]*language preferences, a subjective accountah&]h(]uh*h hh hhhh+hKubh )}(hhh](h)}(h"The ecosystem: different batteriesh]h"The ecosystem: different batteries}(hj:hj8hhhNhNubah}(h ]h"]h$]h&]h(]uh*hhj5hhhh+hK0ubh>)}(hX-To be effective, a programming language needs libraries. Python is famous for its 'batteries included' claim: Almost any library you can think of has been written for Python, and is available from a central location: https://pypi.python.org . But Python's batteries are desktop c.q. server batteries. And Transcrypt is for the web client world. So it needs different batteries. There's a virtually unlimited supply of free high quality JavaScript libraries for web applications. The web is dominated by designers and while programmers may loathe their way of thinking, they sure have created beautiful things. The set of available JQuery components alone beats almost anything available for the desktop from an aesthetic point of view. Rather than attempting to set up a parallel universe for Transcrypt, the only sensible thing to do is to embrace the JavaScript ecosystem to the max. There may be thin 'pythonic' wrappers around JavaScript libraries, but even this is not needed. JavaScript libraries can be used from Transcrypt without restrictions or complications.h](hTo be effective, a programming language needs libraries. Python is famous for its ‘batteries included’ claim: Almost any library you can think of has been written for Python, and is available from a central location: }(hTo be effective, a programming language needs libraries. Python is famous for its 'batteries included' claim: Almost any library you can think of has been written for Python, and is available from a central location: hjFhhhNhNubh reference)}(hhttps://pypi.python.orgh]hhttps://pypi.python.org}(hhhjQubah}(h ]h"]h$]h&]h(]refurijSuh*jOhjFubhXE . But Python’s batteries are desktop c.q. server batteries. And Transcrypt is for the web client world. So it needs different batteries. There’s a virtually unlimited supply of free high quality JavaScript libraries for web applications. The web is dominated by designers and while programmers may loathe their way of thinking, they sure have created beautiful things. The set of available JQuery components alone beats almost anything available for the desktop from an aesthetic point of view. Rather than attempting to set up a parallel universe for Transcrypt, the only sensible thing to do is to embrace the JavaScript ecosystem to the max. There may be thin ‘pythonic’ wrappers around JavaScript libraries, but even this is not needed. JavaScript libraries can be used from Transcrypt without restrictions or complications.}(hX= . But Python's batteries are desktop c.q. server batteries. And Transcrypt is for the web client world. So it needs different batteries. There's a virtually unlimited supply of free high quality JavaScript libraries for web applications. The web is dominated by designers and while programmers may loathe their way of thinking, they sure have created beautiful things. The set of available JQuery components alone beats almost anything available for the desktop from an aesthetic point of view. Rather than attempting to set up a parallel universe for Transcrypt, the only sensible thing to do is to embrace the JavaScript ecosystem to the max. There may be thin 'pythonic' wrappers around JavaScript libraries, but even this is not needed. JavaScript libraries can be used from Transcrypt without restrictions or complications.hjFhhhNhNubeh}(h ]h"]h$]h&]h(]uh*h=hh+hK2hj5hhubh>)}(hXThere's a category of libraries c.q. applications that are probably developed easier in Transcrypt than in JavaScript. Transcrypt's niche are non-trivial web applications where, apart from looks, things like structure, overview, simplicity, explicitness and regularity start to count. This is where Python shines and Transcrypt with it. The preferred way to make Transcrypt libraries and applications avaible to the world is PyPi, Transcrypt being a Python flavour.h]hXThere’s a category of libraries c.q. applications that are probably developed easier in Transcrypt than in JavaScript. Transcrypt’s niche are non-trivial web applications where, apart from looks, things like structure, overview, simplicity, explicitness and regularity start to count. This is where Python shines and Transcrypt with it. The preferred way to make Transcrypt libraries and applications avaible to the world is PyPi, Transcrypt being a Python flavour.}(hjmhjkhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK4hj5hhubeh}(h ]!the-ecosystem-different-batteriesah"]h$]"the ecosystem: different batteriesah&]h(]uh*h hh hhhh+hK0ubh )}(hhh](h)}(hCode structureh]hCode structure}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjhhhh+hK7ubh>)}(hXIn the JavaScript world, components are gathered from everywhere on the web during a page load, and small fragments of code may be anywhere in a web page. Transcrypt takes a different approach. The concept of a static webpage is secundary and may even be absent. Typically there's one and only one Transcrypt application attachted to a certain URL or page. This application has its own namespace and may feature many entrypoints or callbacks attached to DOM components. Although traditional web pages can be made without restrictions using Transcrypt, the focus is on complex stateful web applications rather than on static pages interspersed with code fragments. Typically such a web application will rely on the server to store and retrieve data and program state. Although at some point 'pythonic' libraries may come into existence to facilitate this, direct use of JavaScript AJAX or e.g. of a JQuery AJAX wrapper, will do the job fine.h]hXIn the JavaScript world, components are gathered from everywhere on the web during a page load, and small fragments of code may be anywhere in a web page. Transcrypt takes a different approach. The concept of a static webpage is secundary and may even be absent. Typically there’s one and only one Transcrypt application attachted to a certain URL or page. This application has its own namespace and may feature many entrypoints or callbacks attached to DOM components. Although traditional web pages can be made without restrictions using Transcrypt, the focus is on complex stateful web applications rather than on static pages interspersed with code fragments. Typically such a web application will rely on the server to store and retrieve data and program state. Although at some point ‘pythonic’ libraries may come into existence to facilitate this, direct use of JavaScript AJAX or e.g. of a JQuery AJAX wrapper, will do the job fine.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK9hjhhubeh}(h ]code-structureah"]h$]code structureah&]h(]uh*h hh hhhh+hK7ubh )}(hhh](h)}(h Debuggabilityh]h Debuggability}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjhhhh+hK)}(hX>In order to debug a transpiled web app, multi-level sourcemaps as supported by Transcrypt are a great asset. Apart from that it helps a lot if there's a simple correspondence between the Python source code and the generated JavaScript. In Transcrypt this is the case, as is illustrated by the following code fragments:h]hX@In order to debug a transpiled web app, multi-level sourcemaps as supported by Transcrypt are a great asset. Apart from that it helps a lot if there’s a simple correspondence between the Python source code and the generated JavaScript. In Transcrypt this is the case, as is illustrated by the following code fragments:}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK>hjhhubh table)}(hhh]h tgroup)}(hhh](h colspec)}(hhh]h}(h ]h"]h$]h&]h(]colwidthK,uh*jhjubj)}(hhh]h}(h ]h"]h$]h&]h(]colwidthK,uh*jhjubh tbody)}(hhh]h row)}(hhh](h entry)}(hhh]h container)}(hhh](h caption)}(h classes.pyh]h classes.py}(hjhjubah}(h ]h"]h$]h&]h(]uh*jhh+hKAhjubh literal_block)}(hXclass A: def __init__ (self, x): self.x = x def show (self, label): print ('A.show', label, self.x) class B: def __init__ (self, y): alert ('In B constructor') self.y = y def show (self, label): print ('B.show', label, self.y) class C (A, B): def __init__ (self, x, y): alert ('In C constructor') A.__init__ (self, x) B.__init__ (self, y) self.show ('constructor') def show (self, label): B.show (self, label) print ('C.show', label, self.x, self.y) a = A (1001) a.show ('america') b = B (2002) b.show ('russia') c = C (3003, 4004) c.show ('netherlands') show2 = c.show show2 ('copy') h]hXclass A: def __init__ (self, x): self.x = x def show (self, label): print ('A.show', label, self.x) class B: def __init__ (self, y): alert ('In B constructor') self.y = y def show (self, label): print ('B.show', label, self.y) class C (A, B): def __init__ (self, x, y): alert ('In C constructor') A.__init__ (self, x) B.__init__ (self, y) self.show ('constructor') def show (self, label): B.show (self, label) print ('C.show', label, self.x, self.y) a = A (1001) a.show ('america') b = B (2002) b.show ('russia') c = C (3003, 4004) c.show ('netherlands') show2 = c.show show2 ('copy') }(hhhj ubah}(h ]h"]h$]h&]h(]sourceM/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/docs/code/classes.py xml:spacepreserveforcehighlight_args} linenostartKsuh*j hh+hKAhjubeh}(h ]id1ah"]literal-block-wrapperah$]h&]h(] literal_blockuh*jhjubah}(h ]h"]h$]h&]h(]uh*jhjubj)}(hhh]j)}(hhh](j)}(h classes.jsh]h classes.js}(hj:hj8ubah}(h ]h"]h$]h&]h(]uh*jhh+hKAhj5ubj )}(hXAvar A = __class__ ('A', [object], { get __init__ () {return __get__ (this, function (self, x) { self.x = x; });}, get show () {return __get__ (this, function (self, label) { print ('A.show', label, self.x); });} }); var B = __class__ ('B', [object], { get __init__ () {return __get__ (this, function (self, y) { alert ('In B constructor'); self.y = y; });}, get show () {return __get__ (this, function (self, label) { print ('B.show', label, self.y); });} }); var C = __class__ ('C', [A, B], { get __init__ () {return __get__ (this, function (self, x, y) { alert ('In C constructor'); A.__init__ (self, x); B.__init__ (self, y); self.show ('constructor'); });}, get show () {return __get__ (this, function (self, label) { B.show (self, label); print ('C.show', label, self.x, self.y); });} }); var a = A (1001); a.show ('america'); var b = B (2002); b.show ('russia'); var c = C (3003, 4004); c.show ('netherlands'); var show2 = c.show; show2 ('copy'); h]hXAvar A = __class__ ('A', [object], { get __init__ () {return __get__ (this, function (self, x) { self.x = x; });}, get show () {return __get__ (this, function (self, label) { print ('A.show', label, self.x); });} }); var B = __class__ ('B', [object], { get __init__ () {return __get__ (this, function (self, y) { alert ('In B constructor'); self.y = y; });}, get show () {return __get__ (this, function (self, label) { print ('B.show', label, self.y); });} }); var C = __class__ ('C', [A, B], { get __init__ () {return __get__ (this, function (self, x, y) { alert ('In C constructor'); A.__init__ (self, x); B.__init__ (self, y); self.show ('constructor'); });}, get show () {return __get__ (this, function (self, label) { B.show (self, label); print ('C.show', label, self.x, self.y); });} }); var a = A (1001); a.show ('america'); var b = B (2002); b.show ('russia'); var c = C (3003, 4004); c.show ('netherlands'); var show2 = c.show; show2 ('copy'); }(hhhjFubah}(h ]h"]h$]h&]h(]sourceM/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/docs/code/classes.jsjjjj }j"Ksuh*j hh+hKAhj5ubeh}(h ]id2ah"]j'ah$]h&]h(] literal_blockuh*jhj2ubah}(h ]h"]h$]h&]h(]uh*jhjubeh}(h ]h"]h$]h&]h(]uh*jhjubah}(h ]h"]h$]h&]h(]uh*jhjubeh}(h ]h"]h$]h&]h(]colsKuh*jhjubah}(h ]h"]h$]h&]h(]uh*jhjhhhNhNubeh}(h ] debuggabilityah"]h$] debuggabilityah&]h(]uh*h hh hhhh+hK