ArticleslgStudy

computer science

Write once, compile anywhere

Write once, compile anywhere 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 Write once, compile anywhere rather than just read about it. In short: Write once, compile anywhere (WOCA) is a design goal of a software technology where source code can be compiled on multiple platforms – without requiring platform-specific modifications to compile and behave correctly. The technology typically consists of a programming language plus compilers and software libraries or software framework ported to multiple environments that together provide cross-platform support.

Key takeaways

  • Write once, compile anywhere 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 Write once, compile anywhere to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Write once, compile anywhere from memory before moving on to harder problems.

Reference excerpt

Write once, compile anywhere (WOCA) is a design goal of a software technology where source code can be compiled on multiple platforms – without requiring platform-specific modifications to compile and behave correctly. The technology typically consists of a programming language plus compilers and software libraries or software framework ported to multiple environments that together provide cross-platform support. WOCA differs from write once, run anywhere (WORA), a stated goal of the Java, in which cross-platform support relies on and is at the bytecode level. Other technologies such as .NET also use bytecode to achieve the same goal.

Introduction There are many languages that aim to allow developers to follow the WOCA philosophy, such as C++, Pascal (see Free Pascal), Ada, Cobol, or C, on condition that they don't use functions beyond those provided by the standard library. Languages like Go go even further in as far that no system specific things are used, it should just work, and for system-specific elements a system of platform-specific files is used. A computer program may also use cross-platform libraries, which provide an abstraction layer hiding the differences between various platforms, for things like sockets and GUI, ensuring the portability of the written source code. This is, for example, supported by Qt (C++) or the Lazarus (Pascal) IDE via its LCL and corresponding widgetsets. Present-day computers often have applications such as word processing, Database management, and spreadsheets, that allow people with no programming experience to, sort, extract, and manipulate their data. These applications can create documents (such as PDF files) showing their now organized information, or printing it out. Before 2000, some of these were not available, and prior to 1980, almost none of them were. From the start of computer automation in the early 1960s, if you wanted a report from data you had, or needed to print up invoices, payroll checks, purchase orders, and other paperwork businesses, schools and governments generated, you typed them up on a physical typewriter, possibly using pre-printed forms. Otherwise, if you did have information stored in a computer, and wanted it sorted, manipulated, or printed, it required someone to write a program to do so. In some cases, the person needed information that professional programmers either could not understand how to provide a program to do what they wanted; the available programmers could not produce something in a reasonable amount of time; or there weren't any programmers they could use, caused some non-programming professionals to learn some programming skills, at least to know how to manipulate and print out information they needed from their data. Whether the work was done by a professional programmer, or an end-user writing a program to provide them information for their own use, the means to do this in either case is the same. Write a program, submit it to a compiler (another program that converts written programs into instructions the computer can understand), fix any errors, then repeat until the program worked. While this helped fix part of the problem, it created a new one. People who wrote programs, or hired someone to write them (purchasing software was not a thing until the 1970s or 1980s), discovered when their employer or school bought a new computer, their programs no longer worked.

Development of high-level programming languages To combat these problems, various high-level languages were developed that were usable for general purpose application program development, but could be used to provide reports and information for people with specialized requirements. These include:

BASIC, a simplified programming language which could be used to build "real world" complex applications, as well as simple programs to solve a problem, and was very accessible for amateur programmers. Its ease of use made BASIC well suited as an introductory computer programming class in many colleges. C, a general-purpose programming language often suitable for writing programs which would otherwise require assembly language. Cobol, a general-purpose programming language which tended to be used for developing business applications. Fortran, a general-purpose programming language which is well suited for scientific and engineering problems. Pascal, a general-purpose programming language, which tended to be targeted toward use in schools as an introductory class to teach programming as an alternative to BASIC. Pascal became commonly used for hobbyist programmers in the 1970s and 1980s due to them being part of an integrated development environment allowing a person to edit, compile, and run their programs, providing immediate results. Programs such as UCSD Pascal and Turbo Pascal opened up the world of programming to millions of people, RPG, a domain-specific programming language designed to take the contents of data files, manipulate data and do calculations, then produce printed reports, similar to the way a person can use a spreadsheet to organize data and create PDF files today. While compilers and interpreters of all of these languages, and dozens of others, were available for different machines and different vendors, often each manufacturer would develop proprietary enhancements which made programing on that machine easier, but again, made programs difficult to port (move the program to a different type of computer or a different vendor's computers), and increased vendor lock in. Something had to change.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Write once, compile anywhere

Start with the simplest possible case. Write down what Write once, compile anywhere 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 Write once, compile anywhere 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 Write once, compile anywhere 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 Write once, compile anywhere

In research
Write once, compile anywhere 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 Write once, compile anywhere 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
Write once, compile anywhere is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer programming folklore, Interoperability, Programming language folklore, so understanding it makes those chapters shorter.
In everyday life
Look for Write once, compile anywhere 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 “Write once, compile anywhere” →

Affiliate

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

How to study Write once, compile anywhere in 20 minutes

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

Frequently asked questions

What is Write once, compile anywhere in simple terms?

Write once, compile anywhere (WOCA) is a design goal of a software technology where source code can be compiled on multiple platforms – without requiring platform-specific modifications to compile and behave correctly. The technology typically consists of a programming language plus compilers and s…

Why does Write once, compile anywhere 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 Write once, compile anywhere?

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 Write once, compile anywhere.

Tags

  • Computer programming folklore
  • Interoperability
  • Programming language folklore
  • Software development philosophies
  • Software engineering folklore

Keep exploring