ArticleslgStudy

computer science

Shed Skin

Shed Skin is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Shed Skin rather than just read about it. In short: Shed Skin is an experimental restricted-Python (3.8+) to C++ programming language compiler. It can translate pure, but implicitly statically typed Python programs into optimized C++.

Key takeaways

  • Shed Skin belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Shed Skin to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Shed Skin from memory before moving on to harder problems.

Reference excerpt

Shed Skin is an experimental restricted-Python (3.8+) to C++ programming language compiler. It can translate pure, but implicitly statically typed Python programs into optimized C++. It can generate stand-alone programs or extension modules that can be imported and used in larger Python programs. Shed Skin is an open source project with contributions from many people, however the main author is Mark Dufour. Work has been going into Shed Skin since 2005.

Features Besides the typing restriction, programs cannot freely use the Python standard library, although about 20 common modules, such as random, itertools and re (regular expressions), are supported as of 2011. Also, not all Python features, such as nested functions and variable numbers of arguments, are supported. Many introspective dynamic parts of the language are unsupported. For example, functions like getattr, and hasattr are unsupported. As of May 2011, Unicode is not supported. As of June 2016 for a set of 75 non-trivial test programs (at over 25,000 lines of code in total), measurements show a typical speedup of 2-20 times over Psyco, and 2-200 times over CPython. Shed Skin is still in an early stage of development, so many other programs will not compile unmodified. Shed Skin can be used to generate standalone executables which need only the C++ runtime libraries. It can also be used to generate CPython modules. This allows compiling parts of larger programs with Shed Skin, while running the other parts using regular CPython. Another use has been to wrap C++ classes using Shed Skin to allow C++ classes to be used as Python classes. The license of the Shed Skin source code is under two parts. The main compiler code is under the GNU General Public License (GPL). The supporting code that it uses as a run time library is under a BSD or MIT license depending on the module. This allows compiling both GPL and non-GPL programs.

Type inference Shed Skin combines Ole Agesen's Cartesian Product Algorithm (CPA) with the data-polymorphic part of John Plevyak's Iterative Flow Analysis (IFA). Version 0.6 introduced scalability improvements which repeatedly analyze larger versions of a program (in addition to the mentioned techniques), until it is fully analyzed. This allows Shed Skin to do type inference on larger programs than previously. It starts with an empty callgraph, essentially, and slowly adds to it, until the whole call graph has been added. A graph has been published by the author, showing analysis times for 50 example programs, at a total of around 15,000 lines.

Modules For version 0.9 the following 25 modules are largely supported. Several of these, such as os.path, were compiled to C++ using Shed Skin.

array binascii bisect collections (defaultdict, deque) ConfigParser (no SafeConfigParser) copy colorsys csv (no Dialect, Sniffer) datetime fnmatch getopt glob heapq itertools (no starmap) math mmap os os.path random re socket string struct (no Struct, pack_into, unpack_from) sys time Note that any other module, such as pygame, pyqt or pickle, may be used in combination with a Shed Skin generated extension module. For examples of this, see the Shed Skin examples.

See also Cython PyPy

References

External links Official website Shed Skin Blog shedskin source code repository

Worked examples

Example 1 — a first encounter with Shed Skin

Start with the simplest possible case. Write down what Shed Skin claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Shed Skin before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Shed Skin ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Shed Skin

In research
Shed Skin appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Shed Skin in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Shed Skin is common in secondary-school and first-year university syllabi. It links to neighbouring topics 2005 software, C++ compilers, Source-to-source compilers, so understanding it makes those chapters shorter.
In everyday life
Look for Shed Skin outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Shed Skin” →

How to study Shed Skin in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Shed Skin means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Shed Skin out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Shed Skin in simple terms?

Shed Skin is an experimental restricted-Python (3.8+) to C++ programming language compiler. It can translate pure, but implicitly statically typed Python programs into optimized C++.

Why does Shed Skin matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Shed Skin?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Shed Skin.

Tags

  • 2005 software
  • C++ compilers
  • Source-to-source compilers

Keep exploring