sphinx.addnodesdocument)}( rawsourcechildren]docutils.nodessection)}(hhh](h title)}(hCThe philosophy behind Transcrypt and its impact on design decisionsh]h TextCThe philosophy behind Transcrypt and its impact on design decisions}(hhparenthhhsourceNlineNuba attributes}(ids]classes]names]dupnames]backrefs]utagnamehhh hhh^/home/jac/active/geatec/transcrypt/Transcrypt/transcrypt/docs/sphinx/philosophy_directions.rsthKubh )}(hhh](h)}(h$Transcrypt's primary target audienceh]h&Transcrypt’s primary target audience}(hh1hh/hhhNhNubah}(h ]h"]h$]h&]h(]uh*hhh,hhhh+hKubh paragraph)}(h2Transcrypt is written for internet developers who:h]h2Transcrypt is written for internet developers who:}(hhAhh?hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhh,hhubh bullet_list)}(hhh](h list_item)}(hxPrefer Python over JavaScript for the development of complex, yet maintainable web software with minimal lifecycle costsh]h>)}(hhVh]hxPrefer Python over JavaScript for the development of complex, yet maintainable web software with minimal lifecycle costs}(hhVhhXubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhTubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubhS)}(h]Need their software to be every bit as fast and compact as the native JavaScript counterpartsh]h>)}(hhmh]h]Need their software to be every bit as fast and compact as the native JavaScript counterparts}(hhmhhoubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhkubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubhS)}(h)}(h;Want unrestricted use of any JavaScript library or platformh]h;Want unrestricted use of any JavaScript library or platform}(hhhhubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hhubah}(h ]h"]h$]h&]h(]uh*hRhhOhhhh+hNubeh}(h ]h"]h$]h&]h(]bullet-uh*hMhh+hK hh,hhubh>)}(hrIn this primary target audience there are at least two groups to be distinguished and a third group on the border.h]hrIn this primary target audience there are at least two groups to be distinguished and a third group on the border.}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK hh,hhubh )}(hhh](h)}(hSeasoned Python developersh]hSeasoned Python developers}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhhhhhh+hKubh>)}(hXThey may be using Python on the server-side (e.g. Django) or in developing computational applications (NumPy, SciPy), or in fact in any area of computing. These 'pythonistas' value what they've got: A clean, concise, powerful language, able to tackle any IT problem, especially in combination with C++. When faced with JavaScript in the browser, they experience a frustrating loss of productivity, being bogged down in an organically grown mix of HTML, CSS and JavaScript.h]hXThey may be using Python on the server-side (e.g. Django) or in developing computational applications (NumPy, SciPy), or in fact in any area of computing. These ‘pythonistas’ value what they’ve got: A clean, concise, powerful language, able to tackle any IT problem, especially in combination with C++. When faced with JavaScript in the browser, they experience a frustrating loss of productivity, being bogged down in an organically grown mix of HTML, CSS and JavaScript.}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhhhhubh>)}(h8For them the news is that they have more viable options:h]h8For them the news is that they have more viable options:}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhhhhubh>)}(hX$Is HTML ok? They can use it. Do they find it restrictive? They can manipulate the underlying object model directly in Python. Is CSS ok for them? No need to change then. Do they find it utterly confusing, inconsequent, repetitive and static? They can access the underlying style attributes dynamically in Python. Is JavaScript ok for them? If it ain't broke, don't fix it. Did they already experience that for larger applications the overall structure tends to become messy? They can switch to Python, keeping full access to any JavaScript library.h]hX(Is HTML ok? They can use it. Do they find it restrictive? They can manipulate the underlying object model directly in Python. Is CSS ok for them? No need to change then. Do they find it utterly confusing, inconsequent, repetitive and static? They can access the underlying style attributes dynamically in Python. Is JavaScript ok for them? If it ain’t broke, don’t fix it. Did they already experience that for larger applications the overall structure tends to become messy? They can switch to Python, keeping full access to any JavaScript library.}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhhhhubh>)}(hXaRecently legitimate worries have surfaced about the JavaScript world becoming more an more fragmented. Transcrypt is not about fragmentation but about unification. It doesn't introduce a new language. It makes a mainstream server side language available for development of client side code, without sacrificing performance, compactness or compatibility.h]hXcRecently legitimate worries have surfaced about the JavaScript world becoming more an more fragmented. Transcrypt is not about fragmentation but about unification. It doesn’t introduce a new language. It makes a mainstream server side language available for development of client side code, without sacrificing performance, compactness or compatibility.}(hhhhhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKhhhhubeh}(h ]seasoned-python-developersah"]h$]seasoned python developersah&]h(]uh*h hh,hhhh+hKubh )}(hhh](h)}(hSeasoned JavaScript developersh]hSeasoned JavaScript developers}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjhhhh+hKubh>)}(hX>They may have been using JavaScript for a long time and have accepted its quirks as a fact of life. If it's their first language they will probably not perceive any of its drawbacks as restrictive. But even in that case a part of them will eventually explore other languages, look back and clearly see its limitations.h]hX@They may have been using JavaScript for a long time and have accepted its quirks as a fact of life. If it’s their first language they will probably not perceive any of its drawbacks as restrictive. But even in that case a part of them will eventually explore other languages, look back and clearly see its limitations.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK!hjhhubh>)}(hXAll the talk of speed in JavaScript suddenly becomes irrelevant in the light of using C++ for computation-intensive algorithms. And all the talk about prototypes in fact being superior to class based object orientation suddenly seems to lack substance when real, non-textbook programming experience is gained in a truly class based language rather than one eventually acquiring the keyword 'class' to cover its prototyping guts.h]hXAll the talk of speed in JavaScript suddenly becomes irrelevant in the light of using C++ for computation-intensive algorithms. And all the talk about prototypes in fact being superior to class based object orientation suddenly seems to lack substance when real, non-textbook programming experience is gained in a truly class based language rather than one eventually acquiring the keyword ‘class’ to cover its prototyping guts.}(hj"hj hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK#hjhhubh>)}(hXIf these developers are confronted with the need to develop a new, large, complex web application, they may think about software lifecycle costs and decide that it would be best to develop the client side in Python, provided that execution- and page-load performance is fully maintained.h]hXIf these developers are confronted with the need to develop a new, large, complex web application, they may think about software lifecycle costs and decide that it would be best to develop the client side in Python, provided that execution- and page-load performance is fully maintained.}(hj0hj.hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK%hjhhubeh}(h ]seasoned-javascript-developersah"]h$]seasoned javascript developersah&]h(]uh*h hh,hhhh+hKubh )}(hhh](h)}(hOther developersh]hOther developers}(hjIhjGhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjDhhhh+hK(ubh>)}(hIn this group will be experienced developers who are familiar with C++, C, C#, Java or any other language. But it also includes students of any kind, being serious about a professional IT carreer, but not yet there.h]hIn this group will be experienced developers who are familiar with C++, C, C#, Java or any other language. But it also includes students of any kind, being serious about a professional IT carreer, but not yet there.}(hjWhjUhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK*hjDhhubh>)}(hX-Programming for the web may be new to them, and rather than following the lowest common denominator, they may just as well enter this new world the proper way, respecting the constitution of software design: modularity and thin interfaces, learning to balance loose coupling against internal cohesion.h]hX-Programming for the web may be new to them, and rather than following the lowest common denominator, they may just as well enter this new world the proper way, respecting the constitution of software design: modularity and thin interfaces, learning to balance loose coupling against internal cohesion.}(hjehjchhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK,hjDhhubh>)}(hX<The fact that it took so long to introduce something simple like a decent module mechanism into JavaScript is a telltale sign of severe underdevelopment in this area. In the vast pool of JavaScript developers there are many that are highly skilled and resourceful, and they have successfully circumvented this restriction by using functions as modules, keeping their local variables and functions alive artificially. But a language having modularisation so low on its priority list, is a less than ideal starting point for acquiring good manners in web application design.h]hX<The fact that it took so long to introduce something simple like a decent module mechanism into JavaScript is a telltale sign of severe underdevelopment in this area. In the vast pool of JavaScript developers there are many that are highly skilled and resourceful, and they have successfully circumvented this restriction by using functions as modules, keeping their local variables and functions alive artificially. But a language having modularisation so low on its priority list, is a less than ideal starting point for acquiring good manners in web application design.}(hjshjqhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK.hjDhhubeh}(h ]other-developersah"]h$]other developersah&]h(]uh*h hh,hhhh+hK(ubeh}(h ]$transcrypt-s-primary-target-audienceah"]h$]$transcrypt's primary target audienceah&]h(]uh*h hh hhhh+hKubh )}(hhh](h)}(h&How to best serve this target audienceh]h&How to best serve this target audience}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjhhhh+hK2ubh>)}(hXThe main point, as with any design, is the willingness to let go of dogmaticism in favor of a good balance. Starting out from the fact that Transcypt should be 100% CPython compatible would be very clear and unambigous, and in that sense attractive. However with current technology it's also completely off-limits for any viable real world development, directly competing with JavaScript in the area of speed and compactness. Users of web applications don't care about technology. If they have to wait for more than two seconds for a page to load, many of them zap. If the rest have to wait for more that half a minute, they conclude its time for a browser restart, a modem reset, or a new access provider.h]hXThe main point, as with any design, is the willingness to let go of dogmaticism in favor of a good balance. Starting out from the fact that Transcypt should be 100% CPython compatible would be very clear and unambigous, and in that sense attractive. However with current technology it’s also completely off-limits for any viable real world development, directly competing with JavaScript in the area of speed and compactness. Users of web applications don’t care about technology. If they have to wait for more than two seconds for a page to load, many of them zap. If the rest have to wait for more that half a minute, they conclude its time for a browser restart, a modem reset, or a new access provider.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK4hjhhubh>)}(hXAnd developers don't care about purism. They cannot afford to paint themselves into a corner but need direct access to the full spectrum of JavaScript libraries and frameworks. Application development is hard enough without extra restrictions posed by your development tools.h]hXAnd developers don’t care about purism. They cannot afford to paint themselves into a corner but need direct access to the full spectrum of JavaScript libraries and frameworks. Application development is hard enough without extra restrictions posed by your development tools.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK;hjhhubh>)}(hIt's completely agreed that having native CPython in the browser would be great. But having JavaScript in between, even as asm.js, unfortunately makes it impractical.h]hIt’s completely agreed that having native CPython in the browser would be great. But having JavaScript in between, even as asm.js, unfortunately makes it impractical.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK=hjhhubh>)}(hX[It's completely agreed that many Python developers would like all of their familiar libraries to be avaible. But the fact that most of them are written in C, makes it equally impractical, since they would load at snail speed in a browser. Apart from that, for viable web development, unimpeded access to JavaScript libraries is far more important.h]hX]It’s completely agreed that many Python developers would like all of their familiar libraries to be avaible. But the fact that most of them are written in C, makes it equally impractical, since they would load at snail speed in a browser. Apart from that, for viable web development, unimpeded access to JavaScript libraries is far more important.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK@hjhhubh>)}(hXhOne alternative is to wait from the browser manufacturers to support descents to pure, true assembler, or at least C or C++. Given the fact that Java was kicked out because of security concerns, it is unlikely that a language without array boundary checks would be allowed in. And if such checks were added it would be rather slow, though not unuseable per se.h]hXhOne alternative is to wait from the browser manufacturers to support descents to pure, true assembler, or at least C or C++. Given the fact that Java was kicked out because of security concerns, it is unlikely that a language without array boundary checks would be allowed in. And if such checks were added it would be rather slow, though not unuseable per se.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKDhjhhubh>)}(hXIf ever a fast, compact, browser-native CPython implementation gets developed, with seamless access to the huge investment represented by existing JavaScript libraries, converting from Transcrypt to it will be a snap compared to conversion from JavaScript. So actually Transcrypt, because of its proximity to CPython, is very future-proof, whereas all types of 'better JavaScript' or propietary languages are not. What matters to Transcrypt developers is not Transcrypt's future, but Python's future, which is bright without restriction.h]hX!If ever a fast, compact, browser-native CPython implementation gets developed, with seamless access to the huge investment represented by existing JavaScript libraries, converting from Transcrypt to it will be a snap compared to conversion from JavaScript. So actually Transcrypt, because of its proximity to CPython, is very future-proof, whereas all types of ‘better JavaScript’ or propietary languages are not. What matters to Transcrypt developers is not Transcrypt’s future, but Python’s future, which is bright without restriction.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKHhjhhubh>)}(hXGTranscrypt strikes a careful balance between completely implementing CPython including this last 10% which will cause 90% of the bloat on one hand, and being too much restricted by JavaScript's shortcomings without necessity on the other. This balance e.g. means that Python's 'eval' and 'exec' (not to be confused with JavaScript's) are out, and multiple inheritance and selective operator overloading are in. It means that Transcrypt's and JavaScript's type system are unified, compact, fast and interoperable, rather than stricktly separated, bulky, slow and requiring conversion.h]hXYTranscrypt strikes a careful balance between completely implementing CPython including this last 10% which will cause 90% of the bloat on one hand, and being too much restricted by JavaScript’s shortcomings without necessity on the other. This balance e.g. means that Python’s ‘eval’ and ‘exec’ (not to be confused with JavaScript’s) are out, and multiple inheritance and selective operator overloading are in. It means that Transcrypt’s and JavaScript’s type system are unified, compact, fast and interoperable, rather than stricktly separated, bulky, slow and requiring conversion.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKJhjhhubh>)}(hX **In short: Transcrypt serves its target audience by allowing them to develop fast, compact, future-proof web applications on clients and servers in one stable, well-established language, running on any platform, minimizing lifecycle costs. Not as a promise, but now.**h]h strong)}(hjh]hX In short: Transcrypt serves its target audience by allowing them to develop fast, compact, future-proof web applications on clients and servers in one stable, well-established language, running on any platform, minimizing lifecycle costs. Not as a promise, but now.}(hhhjubah}(h ]h"]h$]h&]h(]uh*jhjubah}(h ]h"]h$]h&]h(]uh*h=hh+hKMhjhhubeh}(h ]&how-to-best-serve-this-target-audienceah"]h$]&how to best serve this target audienceah&]h(]uh*h hh hhhh+hK2ubh )}(hhh](h)}(hKSpecific design choices made for Transcrypt and their underlying motivationh]hKSpecific design choices made for Transcrypt and their underlying motivation}(hj(hj&hhhNhNubah}(h ]h"]h$]h&]h(]uh*hhj#hhhh+hKPubh )}(hhh](h)}(h9Why is Transcrypt written in Python and not in JavaScripth]h9Why is Transcrypt written in Python and not in JavaScript}(hj9hj7hhhNhNubah}(h ]h"]h$]h&]h(]uh*hhj4hhhh+hKSubh>)}(hXTranscrypt departs from the Python side of things. It is not JavaScript approaching the Python world, but Python approaching the JavaScript world. What enabled this approach, is that the notion of compiling on the fly in the browser was rejected from the start. While this would have enabled things like 'exec' and 'eval' and would have made the compilation process fully transparent, compiling a piece of interpreted code on the fly will always stand in the way of performance. And any compromise with regard to performance was judged to be lethal for accepting Transcrypt as a serious win-win alternative for JavaScript in a world where download size and page-load speed are crucial factors.h]hXTranscrypt departs from the Python side of things. It is not JavaScript approaching the Python world, but Python approaching the JavaScript world. What enabled this approach, is that the notion of compiling on the fly in the browser was rejected from the start. While this would have enabled things like ‘exec’ and ‘eval’ and would have made the compilation process fully transparent, compiling a piece of interpreted code on the fly will always stand in the way of performance. And any compromise with regard to performance was judged to be lethal for accepting Transcrypt as a serious win-win alternative for JavaScript in a world where download size and page-load speed are crucial factors.}(hjGhjEhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKUhj4hhubh>)}(hXMSyntactically speaking, Python isn't as simple as it may seem. Using indentation to indicate blocks has a profoundly positive effect upon the readability of the language, but also creates parsing anomalies. The flexibility with regard to formal and actual function parameters makes parsing even more complex. Developing Transcrypt in Python makes available the original, rock-solid Python parser to do the job fast and concise. And since Transcrypt and Python use the same parser, Python can never syntactically develop into a direction that Transcrypt couldn't follow. To JavaScript developers having '__new__ ()' instead of 'new' may well indeed be new, to Python developers it's just another function call. Given the turmoil created by getting rid of Python's 'print' statement in favour of 'print ()' it wouldn't be wise to introduce another unnecessary syntactic anomaly. Even a __pragma__ syntactically (but not semantically) is just another function call. This approach also facilitates reuse of the existing concise documentation on Python's syntax. Transcrypt syntax == Python syntax. Period.h]hXiSyntactically speaking, Python isn’t as simple as it may seem. Using indentation to indicate blocks has a profoundly positive effect upon the readability of the language, but also creates parsing anomalies. The flexibility with regard to formal and actual function parameters makes parsing even more complex. Developing Transcrypt in Python makes available the original, rock-solid Python parser to do the job fast and concise. And since Transcrypt and Python use the same parser, Python can never syntactically develop into a direction that Transcrypt couldn’t follow. To JavaScript developers having ‘__new__ ()’ instead of ‘new’ may well indeed be new, to Python developers it’s just another function call. Given the turmoil created by getting rid of Python’s ‘print’ statement in favour of ‘print ()’ it wouldn’t be wise to introduce another unnecessary syntactic anomaly. Even a __pragma__ syntactically (but not semantically) is just another function call. This approach also facilitates reuse of the existing concise documentation on Python’s syntax. Transcrypt syntax == Python syntax. Period.}(hjUhjShhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKWhj4hhubh>)}(hXAnd then there's the matter of distribution. Transcrypt is just another Python application, available from PyPi like any other, requiring Python like any other. And its library modules can be distributed via PyPi or any of its successors. It is very well possible to write 'pure Python modules' that run both under CPython and Transcrypt. But the importance of this is, apart from some fundamental modules, limited. For use in the browser, the enormous amount of 'actually existing' JavaScript libraries are far more interesting. And they can be loaded the JavaScript way, either on the fly from a content distribution network, or via 'require'.h]hXAnd then there’s the matter of distribution. Transcrypt is just another Python application, available from PyPi like any other, requiring Python like any other. And its library modules can be distributed via PyPi or any of its successors. It is very well possible to write ‘pure Python modules’ that run both under CPython and Transcrypt. But the importance of this is, apart from some fundamental modules, limited. For use in the browser, the enormous amount of ‘actually existing’ JavaScript libraries are far more interesting. And they can be loaded the JavaScript way, either on the fly from a content distribution network, or via ‘require’.}(hjchjahhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKYhj4hhubh>)}(hFinally there's the efficiency of development of Transcypt itself. Transcrypt was written because programming in Python was very much preferred over programming in JavaScript. So why on earth then would JavaScript be preferred over Python in writing it...h]hXFinally there’s the efficiency of development of Transcypt itself. Transcrypt was written because programming in Python was very much preferred over programming in JavaScript. So why on earth then would JavaScript be preferred over Python in writing it…}(hjqhjohhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK[hj4hhubeh}(h ]9why-is-transcrypt-written-in-python-and-not-in-javascriptah"]h$]9why is transcrypt written in python and not in javascriptah&]h(]uh*h hj#hhhh+hKSubh )}(hhh](h)}(hDWhy does Transcrypt blend Python datatypes with JavaScript datatypesh]hDWhy does Transcrypt blend Python datatypes with JavaScript datatypes}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjhhhh+hK^ubh>)}(hXPThe answer can be short: Compactness, speed and interoperability on the library front. Being able e.g. to interpret {'color': 'red', 'size': 'medium'} both as a JavaScript object and as a Python dictionary save lots of conversions, library encapsulation layers and counterintuitive restrictions. It minize code size and maximizes speed of data exchange between JavaScript and Python. Crucial to making it work is the identifier aliasing mechanism. It facilitates carefree use of Python keywords and identifiers, solving any name clashes with their JavaScript counterparts, now and in the future. It doesn't matter that both Python and JavaScript have a 'strip' method for strings that do different things. Using 'strip' in Python will translate to 'py_strip' and JavaScript's native 'strip' method can be used from Python under the name 'js_strip'.h]hXxThe answer can be short: Compactness, speed and interoperability on the library front. Being able e.g. to interpret {‘color’: ‘red’, ‘size’: ‘medium’} both as a JavaScript object and as a Python dictionary save lots of conversions, library encapsulation layers and counterintuitive restrictions. It minize code size and maximizes speed of data exchange between JavaScript and Python. Crucial to making it work is the identifier aliasing mechanism. It facilitates carefree use of Python keywords and identifiers, solving any name clashes with their JavaScript counterparts, now and in the future. It doesn’t matter that both Python and JavaScript have a ‘strip’ method for strings that do different things. Using ‘strip’ in Python will translate to ‘py_strip’ and JavaScript’s native ‘strip’ method can be used from Python under the name ‘js_strip’.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hK`hjhhubeh}(h ]Dwhy-does-transcrypt-blend-python-datatypes-with-javascript-datatypesah"]h$]Dwhy does transcrypt blend python datatypes with javascript datatypesah&]h(]uh*h hj#hhhh+hK^ubh )}(hhh](h)}(hcWhy are certain Python constructions supported as a local (or global) option rather than by defaulth]hcWhy are certain Python constructions supported as a local (or global) option rather than by default}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjhhhh+hKcubh>)}(hXEfficiency is the reason. While it seems very sophisticated to globally support operator overloading by default, replacing x = 2 * (3 + 4) by x = __mul__ (__add__ (3, 4)) in a program full of such expressions, possibly in inner loops, would have a disastrous impact on both performance and readability of the generated JavaScript code. And readability of the generated code is a must. Transcrypt should not be a magical toolbox, close your eyes, trust us and here's the rabbit. The way it works should be fully transparent, including quality and correctness of the generated JavaScript code. On the other hand, who would like to write v4 = add (multiply (add (v1, v2)), v3) rather than v4 = M (v1 + v2) + v3 in a program consisting of many lines of vector math.h]hXEfficiency is the reason. While it seems very sophisticated to globally support operator overloading by default, replacing x = 2 * (3 + 4) by x = __mul__ (__add__ (3, 4)) in a program full of such expressions, possibly in inner loops, would have a disastrous impact on both performance and readability of the generated JavaScript code. And readability of the generated code is a must. Transcrypt should not be a magical toolbox, close your eyes, trust us and here’s the rabbit. The way it works should be fully transparent, including quality and correctness of the generated JavaScript code. On the other hand, who would like to write v4 = add (multiply (add (v1, v2)), v3) rather than v4 = M (v1 + v2) + v3 in a program consisting of many lines of vector math.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKehjhhubh>)}(hX In general compiler facilities that may have a negative impact on performance if applied in the wrong places can be switched on and off locally. The reason they sometimes also are available as a global option is educational use. If straightforward pythonic code matters more than performance, which is the case in an educational situation, setting all switches to maximize CPython compliance may be a good idea, especially if the generated JavaScript code is taken for granted as are assembly instructions with a C compiler.h]hX In general compiler facilities that may have a negative impact on performance if applied in the wrong places can be switched on and off locally. The reason they sometimes also are available as a global option is educational use. If straightforward pythonic code matters more than performance, which is the case in an educational situation, setting all switches to maximize CPython compliance may be a good idea, especially if the generated JavaScript code is taken for granted as are assembly instructions with a C compiler.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKghjhhubh>)}(hrThe following benchmark results give an indication of the performance of Transcrypt'ed code with default settings:h]htThe following benchmark results give an indication of the performance of Transcrypt’ed code with default settings:}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKihjhhubh figure)}(hhh]h image)}(ha.. figure:: ../images/benchmark.png :alt: Relative performance measured by Pystone benchmark h]h}(h ]h"]h$]h&]h(]alt2Relative performance measured by Pystone benchmarkuri../images/benchmark.png candidates}*jsuh*jhjhh+hNubah}(h ]h"]h$]h&]h(]uh*jhjhhhh+hNubh>)}(hX\Note that Transcrypt avoids constructs that cannot be made to perform in the browser. This means that Transcrypt and CPython are playing in different leagues. Transcrypt makes it possible for Python programmers to take a lot of their skills to the browser, but it is in no way a replacement for CPython. The two should be regarded as complementary.h]hX\Note that Transcrypt avoids constructs that cannot be made to perform in the browser. This means that Transcrypt and CPython are playing in different leagues. Transcrypt makes it possible for Python programmers to take a lot of their skills to the browser, but it is in no way a replacement for CPython. The two should be regarded as complementary.}(hjhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKnhjhhubeh}(h ]awhy-are-certain-python-constructions-supported-as-a-local-or-global-option-rather-than-by-defaultah"]h$]cwhy are certain python constructions supported as a local (or global) option rather than by defaultah&]h(]uh*h hj#hhhh+hKcubh )}(hhh](h)}(h#Why were the \_\_pragma\_\_'s addedh]h%Why were the __pragma__’s added}(h#Why were the \_\_pragma\_\_'s addedhjhhhNhNubah}(h ]h"]h$]h&]h(]uh*hhjhhhh+hKqubh>)}(hXSeveral special facilities were needed that don't play a role in CPython: local compilation options, setting identifier aliases, e.g. replacing jq or S by $ to be able to bridge the gap with JQuery, conditional compilation of code fragments like imports, who, by nature of compilation rather than interpretation, are done compile time rather than runtime hence won't obey normal 'if' statements, etc.. For all those special facilities special keywords could have been devised. It would make such special facilities hard to recognize and keyword-hungry. Using \_\_pragma\_\_ in these cases provides a simple clue to what's going on, both for developers and for the compiler. In the C/C++ world pragma's serve a comparable purpose. They are, as the word suggest, pragmatic solutions to practical problems. Pragmatism is good. But it should be insulated and carefully managed. A special keyword helps with that.h]hXSeveral special facilities were needed that don’t play a role in CPython: local compilation options, setting identifier aliases, e.g. replacing jq or S by $ to be able to bridge the gap with JQuery, conditional compilation of code fragments like imports, who, by nature of compilation rather than interpretation, are done compile time rather than runtime hence won’t obey normal ‘if’ statements, etc.. For all those special facilities special keywords could have been devised. It would make such special facilities hard to recognize and keyword-hungry. Using __pragma__ in these cases provides a simple clue to what’s going on, both for developers and for the compiler. In the C/C++ world pragma’s serve a comparable purpose. They are, as the word suggest, pragmatic solutions to practical problems. Pragmatism is good. But it should be insulated and carefully managed. A special keyword helps with that.}(hXSeveral special facilities were needed that don't play a role in CPython: local compilation options, setting identifier aliases, e.g. replacing jq or S by $ to be able to bridge the gap with JQuery, conditional compilation of code fragments like imports, who, by nature of compilation rather than interpretation, are done compile time rather than runtime hence won't obey normal 'if' statements, etc.. For all those special facilities special keywords could have been devised. It would make such special facilities hard to recognize and keyword-hungry. Using \_\_pragma\_\_ in these cases provides a simple clue to what's going on, both for developers and for the compiler. In the C/C++ world pragma's serve a comparable purpose. They are, as the word suggest, pragmatic solutions to practical problems. Pragmatism is good. But it should be insulated and carefully managed. A special keyword helps with that.hj-hhhNhNubah}(h ]h"]h$]h&]h(]uh*h=hh+hKshjhhubeh}(h ]why-were-the-pragma-s-addedah"]h$]why were the __pragma__'s addedah&]h(]uh*h hj#hhhh+hKqubeh}(h ]Kspecific-design-choices-made-for-transcrypt-and-their-underlying-motivationah"]h$]Kspecific design choices made for transcrypt and their underlying motivationah&]h(]uh*h hh hhhh+hKPubeh}(h ]Cthe-philosophy-behind-transcrypt-and-its-impact-on-design-decisionsah"]h$]Cthe philosophy behind transcrypt and its impact on design decisionsah&]h(]uh*h hhhhhh+hKubah}(h ]h"]h$]h&]h(]sourceh+uh*hcurrent_sourceN current_lineNsettingsdocutils.frontendValues)}(hN generatorN datestampN source_linkN source_urlN toc_backlinksentryfootnote_backlinksK sectnum_xformKstrip_commentsNstrip_elements_with_classesN strip_classesN report_levelK halt_levelKexit_status_levelKdebugNwarning_streamN tracebackinput_encoding utf-8-siginput_encoding_error_handlerstrictoutput_encodingutf-8output_encoding_error_handlerjwerror_encodingutf-8error_encoding_error_handlerbackslashreplace language_codeenrecord_dependenciesNconfigN id_prefixhauto_id_prefixid dump_settingsNdump_internalsNdump_transformsNdump_pseudo_xmlNexpose_internalsNstrict_visitorN_disable_configN_sourceh+ _destinationN _config_files]pep_referencesN pep_base_url https://www.python.org/dev/peps/pep_file_url_templatepep-%04drfc_referencesN rfc_base_urlhttps://tools.ietf.org/html/ tab_widthKtrim_footnote_reference_spacefile_insertion_enabled raw_enabledKsyntax_highlightlong smart_quotessmartquotes_locales]character_level_inline_markupdoctitle_xform docinfo_xformKsectsubtitle_xformembed_stylesheetcloak_email_addressesenvNubreporterNindirect_targets]substitution_defs}substitution_names}refnames}refids}nameids}(jQjNjjhhjAj>jjj jjIjFjjjjjjjAj>u nametypes}(jQNjNhNjANjNj NjINjNjNjNjANuh }(jNh jh,hhj>jjjDjjjFj#jj4jjjjj>ju footnote_refs} citation_refs} autofootnotes]autofootnote_refs]symbol_footnotes]symbol_footnote_refs] footnotes] citations]autofootnote_startKsymbol_footnote_startK id_counter collectionsCounter}Rparse_messages]transform_messages] transformerN decorationNhhub.