ArticleslgStudy

science

Porting

Porting is a 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 Porting rather than just read about it. In short: In software development, porting is the process of adapting software to run in a different context. Often it involves modifying source code so that a program can run on a different platform (i.e. on a different CPU or operating system) or in a different environment (i.e. with a different library or framework).

Porting — main illustration
Porting — illustration

Key takeaways

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

Reference excerpt

In software development, porting is the process of adapting software to run in a different context. Often it involves modifying source code so that a program can run on a different platform (i.e. on a different CPU or operating system) or in a different environment (i.e. with a different library or framework). It also describes adapting a change or feature from one codebase to another – even between different versions of the same software. Software is classified as portable if it can be hosted in a different context with no change to the source code. It might be considered portable if the cost of adapting it to a context is significantly less than the cost of writing it from scratch. The lower the cost of porting relative to the cost to re-write, the more portable it is said to be. The effort depends on several factors including the extent to which the original context differs from the new context, the skill of the programmers, and the portability of the codebase.

Etymology The term "port" is derived from the Latin portāre, meaning "to carry". When code is not compatible with a particular operating system or architecture, the code must be "carried" to the new system.

History The number of significantly different CPUs and operating systems used on the desktop today is much smaller than in the past. The dominance of the x86 architecture means that most desktop software is never ported to a different CPU. In that same market, the choice of operating systems has effectively been reduced to three: Microsoft Windows, macOS, and Linux. In the embedded systems and mobile markets, however, portability remains a significant issue, with the ARM being a widely used alternative. International standards, such as those promulgated by the ISO, greatly facilitate porting by specifying details of the computing environment in a way that helps reduce differences between different standards-conforming platforms. Writing software that stays within the bounds specified by these standards represents a practical although nontrivial effort. Porting such a program between two standards-compliant platforms (such as POSIX.1) can be just a matter of loading the source code and recompiling it on the new platform, but practitioners often find that various minor corrections are required, due to subtle platform differences. Most standards suffer from "gray areas" where differences in interpretation of standards lead to small variations from platform to platform. There also exists an ever-increasing number of tools to facilitate porting, such as the GNU Compiler Collection, which provides consistent programming languages on different platforms, and Autotools, which automates the detection of minor variations in the environment and adapts the software accordingly before compilation. The compilers for some high-level programming languages (e.g. Eiffel, Esterel) gain portability by outputting source code in another high level intermediate language (such as C) for which compilers for many platforms are generally available.

Porting compilers Instead of translating directly into machine code, modern compilers translate to a machine independent intermediate code in order to enhance portability of the compiler and minimize design efforts. The intermediate language defines a virtual machine that can execute all programs written in the intermediate language (a machine is defined by its language and vice versa). The intermediate code instructions are translated into equivalent machine code sequences by a code generator to create executable code. It is also possible to skip the generation of machine code by actually implementing an interpreter or JIT for the virtual machine. The use of intermediate code enhances portability of the compiler, because only the machine dependent code (the interpreter or the code generator) of the compiler itself needs to be ported to the target machine. The remainder of the compiler can be imported as intermediate code and then further processed by the ported code generator or interpreter, thus producing the compiler software or directly executing the intermediate code on the interpreter. The machine independent part can be developed and tested on another machine (the host machine). This greatly reduces design efforts, because the machine independent part needs to be developed only once to create portable intermediate code. An interpreter is less complex and therefore easier to port than a code generator, because it is not able to do code optimizations due to its limited view of the program code (it only sees one instruction at a time, and users need a sequence to do optimization). Some interpreters are extremely easy to port, because they only make minimal assumptions about the instruction set of the underlying hardware. As a result, the virtual machine is even simpler than the target CPU. Writing the compiler sources entirely in the programming language the compiler is supposed to translate, makes the following approach, better known as compiler bootstrapping, feasible on the target machine:

Port the interpreter. This needs to be coded in assembly code, using an already present assembler on the target. Adapt the source of the code generator to the new machine. Execute the adapted source using the interpreter with the code generator source as input. This will generate the machine code for the code generator. The difficult part of coding the optimization routines is done using the high-level language instead of the assembly language of the target. According to the designers of the BCPL language, interpreted code (in the BCPL case) is more compact than machine code, typically by a factor of two to one. Interpreted code however runs about ten times slower than compiled code on the same machine. The designers of the Java programming language try to take advantage of the compactness of interpreted code, because a Java program may need to be transmitted over the Internet before execution can start on the target's Java virtual machine (JVM).

Porting of video games

… excerpt ends here. Continue reading the full article.

Illustrations

Porting illustration
Porting illustration
Porting illustration
Porting illustration
Porting illustration

Worked examples

Example 1 — a first encounter with Porting

Start with the simplest possible case. Write down what Porting claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In 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 Porting 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 Porting 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 Porting

In research
Porting appears in 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 Porting 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
Porting is common in secondary-school and first-year university syllabi. It links to neighbouring topics Interoperability, Source code, so understanding it makes those chapters shorter.
In everyday life
Look for Porting 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.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Porting in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Porting 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 Porting out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Porting in simple terms?

In software development, porting is the process of adapting software to run in a different context. Often it involves modifying source code so that a program can run on a different platform (i.e. on a different CPU or operating system) or in a different environment (i.e. with a different library or…

Why does Porting matter?

Because it connects several 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 Porting?

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 Porting.

Tags

  • Interoperability
  • Source code

Keep exploring