ArticleslgStudy

science

Multitier programming

Multitier programming 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 Multitier programming rather than just read about it. In short: Multitier programming (or tierless programming) is a programming paradigm for distributed software, which typically follows a multitier architecture, physically separating different functional aspects of the software into different tiers (e.g., the client, the server and the database in a Web application). Multitier programming allows functionalities that span multiple of such tiers to be developed in a single compi…

Key takeaways

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

Reference excerpt

Multitier programming (or tierless programming) is a programming paradigm for distributed software, which typically follows a multitier architecture, physically separating different functional aspects of the software into different tiers (e.g., the client, the server and the database in a Web application). Multitier programming allows functionalities that span multiple of such tiers to be developed in a single compilation unit using a single programming language. Without multitier programming, tiers are developed using different languages, e.g., JavaScript for the Web client, PHP for the Web server and SQL for the database. Multitier programming is often integrated into general-purpose languages by extending them with support for distribution. Concepts from multitier programming were pioneered by the Hop and Links languages and have found industrial adoption in solutions such as Ocsigen, Opa, WebSharper, Meteor or GWT. Multitier programming provides a global view on the distributed system. This aspect has been shown similar to other programming paradigms such as choreographic programming, macroprogramming, and aggregate computing.

Context The code of the different tiers can be executed in a distributed manner on different networked computers. For instance, in a three-tier architecture, a system is divided into three main layers – typically the presentation, business, and data tiers. This approach has the benefit that by dividing a system into layers, the functionality implemented in one of the layers can be changed independently of the other layers. On the other hand, this architectural decision scatters a cross-cutting functionality belonging to several tiers over several compilation units. In multitier programming, the different tiers are implemented using a single programming language. Different compilation backends take into account the destination tier (e.g., Java for a server and JavaScript for a web browser). Consequently, a functionality that is spread over tiers can be implemented in a single compilation unit of a multitier program.

Example At their core, multitier languages allow developers to define for different pieces of code the tiers to which the code belongs. The language features that enable this definition are quite diverse between different multitier languages, ranging from staging to annotations to types. The following example shows an Echo client–server application that illustrates different approaches. In the example, the client sends a message to the server and the server returns the same message to the client, where it is appended to a list of received messages.

Echo application in Hop.js

Hop uses staging to embed code that is to be run on the client into a server-side program: Using the ~{…} notation, the code for the onload (Line 4) and onclick (Line 10) handlers is not immediately executed but the server generates the code for later execution on the client. On the other hand, the ${…} notation escapes one level of program generation. The expressions hop.port (Line 5), event.data (Line 6) and input (Line 9 and 10) are evaluated by the outer server program and the values to which they evaluate are injected into the generated client program. Hop supports full stage programming, i.e., ~{…} expressions can be arbitrarily nested such that not only server-side programs can generate client-side programs but also client-side programs are able to generate other client-side programs. HTML can be embedded directly in Hop code. HTML generated on the server (Line 2–14) is passed to the client. HTML generated on the client can be added to the page using the standard DOM API (Line 6). Hop supports bidirectional communication between a running server and a running client instance through its standard library. The client connects to the WebSocket server through the standard HTML5 API (Line 5) and sends the current input value (Line 10). The server opens a WebSocket server (Line 17) that returns the value back to the client (Line 20). So-called services, which are executed on the server and produce a value that is returned to the client that invoked the service. For example, the echo service (Line 1) produces the HTML page served to the web client of the Echo application. Thus, the code in a service block is executed on the server.

Echo application in Links

Links uses annotations on functions to specify whether they run on the client or on the server (Line 1 and 5). Upon request from the client, the server executes the main function (Line 18), which constructs the code that is sent to the client. Links allows embedding XML code (Line 7–15). XML attributes with the l: prefix are treated specially. The l:name attribute (Line 10) declares an identifier to which the value of the input field is bound. The identifier can be used elsewhere (Line 9). The code to be executed for the l:onsubmit handler (Line 9) is not immediately executed but compiled to JavaScript for client-side execution. Curly braces indicate Links code embedded into XML. The l:onsubmit handler sends the current input value item to the server by calling echo. The item is returned by the server and appended to the list of received items using standard DOM APIs. The call to the server (Line 9) does not block the client. Instead, the continuation on the client is invoked when the result of the call is available. Client–server interaction is based on resumption passing style: Using continuation passing style transformation and defunctionalization, remote calls are implemented by passing the name of a function for the continuation and the data needed to continue the computation.

Echo application in ScalaLoci

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Multitier programming

Start with the simplest possible case. Write down what Multitier programming 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 Multitier programming 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 Multitier programming 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 Multitier programming

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

How to study Multitier programming in 20 minutes

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

Frequently asked questions

What is Multitier programming in simple terms?

Multitier programming (or tierless programming) is a programming paradigm for distributed software, which typically follows a multitier architecture, physically separating different functional aspects of the software into different tiers (e.g., the client, the server and the database in a Web appli…

Why does Multitier programming 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 Multitier programming?

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 Multitier programming.

Tags

  • Programming paradigms

Keep exploring