9. The main differences with CPython¶
9.1. Differences due to the compiled, rather than interpreted nature of Transcrypt¶
C++ style conditional compilation is supported through pragmas.
Conditional import of modules is done by using conditional compilation rather than conditional statements.
Source level debugging in the browser is available through the use of sourcemaps.
Running a compiled Transcrypt program doesn’t require a Python or Transcrypt interpreter. It only requires the runtime, which is about 40 kB.
9.2. Differences due to the ‘lean and mean’ design goal¶
Facilities like operator overloading, automatic truth value conversion and named parameters can be switched on and off locally using pragmas, to keep the generated code small.
Interpreting negative indices as offsets from the end of a list or string requires operator overloading to be switched on.
String formatting is done through the format method or through f-strings, as this is considered most flexible. Using % for formatting isn’t supported.
Some methods of container types like list, set and dict, that duplicate functionality of other methods, have been left out of the core libraries. If needed they can be supplied in separate libraries.
Metaclasses only support overloading the __new__ method, covering 90% of the use cases.
Currently the *, /, //, +, -, @, , (), ==, !=, <, <=, >, >=, **, << and >> operators can be overloaded, both forward and reverse where appropriate, covering almost all usecases.
The ‘with’ statement can currently only be used for file-like objects.
The print function can be used to print to a DOM element or to the browser console.
The name type cannot be used as an ordinary identifier.
9.4. Differences due to running Transcrypt applications in the browser, rather than on the desktop¶
Transcrypt doesn’t directly support the use of libraries written in C or C++ since, without special measures like compiling to asm.js, C and C++ don’t run in the browser.