Multitier programming explained
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[1]). 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.[2] Multitier programming is often integrated into general-purpose languages by extending them with support for distribution.[3]
Concepts from multitier programming were pioneered by the Hop[4] and Links[5] languagesand have found industrial adoption in solutions such as Ocsigen,[6] Opa,[7] WebSharper,[8] Meteor[9] or GWT.[10]
Multitier programming provides a global view on the distributed system. This aspect has been shown similar to other programming paradigms such as choreographic programming,[11] macroprogramming,[12] and aggregate computing.[13] [14]
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
service echo
var wss = new WebSocketServer("ws")wss.onconnection = function(event)
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
fun echo(item) server
fun main server
main
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
@multitier object Application
ScalaLoci is a language that targets generic distributed systems rather than the Web only, i.e., it is not restricted to a client–server architecture. To this end, ScalaLoci supports peer types to encode the different tiers at the type level. Placement types are used to assign locations to data and computations. ScalaLoci supports multitier reactives – language abstractions for reactive programming that are placed on specific locations – for composing data flows cross different peers.
The application first defines an input field (Line 11) using the ScalaTags library.[15] The value of this field is used in the click event handler of a button (Line 15) to fire the message event with the current value of the input field. The value is then propagated to the server (Line 6) and back to the client (Line 9). On the client, the value of the event are accumulated using the list function and mapped to an HTML list (Line 10). This list is then used in the HTML (Line 16) to display the previous inputs.
List of multitier programming languages
Notes and References
- Hull. Richard. Thiemann. Peter. Wadler. Philip. 2007. 07051 Working Group Outcomes – Programming Paradigms for the Web: Web Programming and Web Services. Programming Paradigms for the Web: Web Programming and Web Services. Dagstuhl Seminar Proceedings. Dagstuhl, Germany. Internationales Begegnungs- und Forschungszentrum für Informatik (IBFI). 07051.
- Weisenburger. Pascal. Wirth. Johannes. Salvaneschi. Guido. A Survey of Multitier Programming. ACM Comput. Surv.. 2020. 53. 4. 81:1–81:35. 10.1145/3397495. 218517772 .
- Book: Caldwell. Sam . Miller. Heather. Programming Models for Distributed Computing. 2016. General Purpose Languages Extended for Distribution. http://dist-prog-book.com/chapter/5/langs-extended-for-dist.html.
- Serrano. Manuel. 2012. Multitier programming in Hop.. Commun. ACM. 55. 8. 53–59. 10.1145/2240236.2240253. 2152326.
- Book: Cooper, Ezra. Formal Methods for Components and Objects . Links: Web Programming Without Tiers . 2006. Lecture Notes in Computer Science. 4709. 266–296. 10.1007/978-3-540-74792-5_12. 20.500.11820/ef5f100a-0366-4b85-8ef1-622fd7fbb53a . 978-3-540-74791-8. 16397220 .
- Balat. Vincent. 2006. Ocsigen: typing web interaction with objective Caml.. 84–94. 10.1145/1159876.1159889. 6131454.
- Rajchenbach-Teller, D., & Sinot, Franois-Régis. (2010). Opa: Language support for a sane, safe and secure web. Proceedings of the OWASP AppSec Research, 2010(1).
- Book: Bjornson. Joel. Tayanovskyy. Anton. Granicz. Adam. Implementation and Application of Functional Languages . Composing Reactive GUIs in F# Using WebSharper . 2010. Lecture Notes in Computer Science . 6647 . 49. Berlin, Heidelberg. Springer-Verlag. 10.1007/978-3-642-24276-2_13. 978-3-642-24275-5 .
- Book: Strack, Isaac. Getting started with Meteor JavaScript framework. January 2012. 978-1-78216-083-0. Birmingham. 823718999.
- Book: Kereki, Federico, 1960-. Essential GWT: building for the web with Google Web toolkit 2. 2011. Addison-Wesley. 978-0-321-70563-1. Upper Saddle River, NJ. 606556208.
- Giallorenzo . Saverio . Montesi . Fabrizio . Peressotti . Marco . Richter . David . Salvaneschi . Guido . Weisenburger . Pascal . 2021 . Møller . Anders . Sridharan . Manu . Multiparty Languages: The Choreographic and Multitier Cases . 35th European Conference on Object-Oriented Programming (ECOOP 2021) . Leibniz International Proceedings in Informatics (LIPIcs) . Dagstuhl, Germany . Schloss Dagstuhl – Leibniz-Zentrum für Informatik . 194 . 22:1–22:27 . 10.4230/LIPIcs.ECOOP.2021.22 . free . 978-3-95977-190-0. 235748561 .
- Casadei . Roberto . Macroprogramming: Concepts, State of the Art, and Opportunities of Macroscopic Behaviour Modelling . ACM Computing Surveys . Association for Computing Machinery (ACM) . 2023-01-11 . 55 . 13s . 1–37 . 0360-0300 . 10.1145/3579353 . 245837830 . free . 2201.03473 .
- Beal . Jacob . Pianini . Danilo . Viroli . Mirko . Aggregate Programming for the Internet of Things . Computer . Institute of Electrical and Electronics Engineers (IEEE) . 48 . 9 . 2015 . 0018-9162 . 10.1109/mc.2015.261 . 22–30. 11585/520779 . 26413 . free .
- Audrito . Giorgio . Casadei . Roberto . Damiani . Ferruccio . Salvaneschi . Guido . Viroli . Mirko . 2022 . Ali . Karim . Vitek . Jan . Functional Programming for Distributed Systems with XC . 36th European Conference on Object-Oriented Programming (ECOOP 2022) . Leibniz International Proceedings in Informatics (LIPIcs) . Dagstuhl, Germany . Schloss Dagstuhl – Leibniz-Zentrum für Informatik . 222 . 20:1–20:28 . 10.4230/LIPIcs.ECOOP.2022.20 . free . 978-3-95977-225-9. 249961384 .
- Web site: ScalaTags. www.lihaoyi.com. 2021-10-11.
- Serrano. Manuel. 2012. Multitier programming in Hop.. Commun. ACM. 55. 8. 53–59. 10.1145/2240236.2240253. 2152326.
- Serrano. Manuel. 2006. Hop: a language for programming the web 2.0.. 975–985. 10.1145/1176617.1176756. 14306230.
- Book: Serrano, Manuel. Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming . A glimpse of Hopjs . 2016. 180–192. 10.1145/2951913.2951916. 9781450342193. 18393160 .
- Book: Cooper, Ezra. Formal Methods for Components and Objects . Links: Web Programming Without Tiers . 2006. Lecture Notes in Computer Science. 4709. 266–296. 10.1007/978-3-540-74792-5_12. 20.500.11820/ef5f100a-0366-4b85-8ef1-622fd7fbb53a . 978-3-540-74791-8. 16397220 .
- Fowler. Simon. 2019. Exceptional asynchronous session types: session types without tiers.. Proc. ACM Program. Lang.. 3. POPL. 28:1–28:29. 10.1145/3290341. 57757469. free. 1808/27512. free.
- Chlipala. Adam. 2015. Ur/Web: A Simple Model for Programming the Web.. 153–165. 10.1145/2676726.2677004. 9440677.
- Balat. Vincent. 2006. Ocsigen: typing web interaction with objective Caml.. 84–94. 10.1145/1159876.1159889. 6131454.
- Book: Radanne, Gabriel. Companion of the Web Conference 2018 on the Web Conference 2018 - WWW '18 . Tierless Web Programming in the Large . 2018. 681–689. 10.1145/3184558.3185953. 9781450356404. 3304415.
- Weisenburger. Pascal. 2018. Distributed system development with ScalaLoci.. Proc. ACM Program. Lang.. 2. OOPSLA. 129:1–129:30. 10.1145/3276499. 53090153. free.
- Book: Philips, Laure. Proceedings of the 2014 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming & Software . Towards Tierless Web Development without Tierless Languages . 2014. 69–81. 10.1145/2661136.2661146. 9781450332101. 15774367.
- Philips. Laure. 2018. Search-based Tier Assignment for Optimising Offline Availability in Multi-tier Web Applications.. Programming Journal. 2. 2. 3. 10.22152/programming-journal.org/2018/2/3. 11256561. free. 1712.01161.
- Book: Reynders, Bob. Proceedings of the 2014 ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming & Software . Multi-Tier Functional Reactive Programming for the Web . 2014. 55–68. 10.1145/2661136.2661140. 9781450332101. 16761616.
- Rajchenbach-Teller, D., & Sinot, Franois-Régis. (2010). Opa: Language support for a sane, safe and secure web. Proceedings of the OWASP AppSec Research, 2010(1).
- Book: Carreton, Andoni Lombide. Objects, Models, Components, Patterns . Loosely-Coupled Distributed Reactive Programming in Mobile Ad Hoc Networks . 2010. Lecture Notes in Computer Science. 6141. 41–60. 10.1007/978-3-642-13953-6_3. 978-3-642-13952-9.
- Book: Dedecker, Jessie. 2006. Ambient-Oriented Programming in AmbientTalk.. Ambient-Oriented Programming in Ambient Talk. Lecture Notes in Computer Science. 4067. https://dblp.org/rec/conf/ecoop/DedeckerCMDM06.html. 230–254. 10.1007/11785477_16. 978-3-540-35726-1.
- Book: VII, Tom Murphy. Trustworthy Global Computing . Type-Safe Distributed Programming with ML5 . 2007. Lecture Notes in Computer Science. 4912. 108–123. 10.1007/978-3-540-78663-4_9. 978-3-540-78662-7. 12534714 .
- Book: Bjornson. Joel. Tayanovskyy. Anton. Granicz. Adam. Implementation and Application of Functional Languages . Composing Reactive GUIs in F# Using WebSharper . 2010. Lecture Notes in Computer Science . 6647 . 49. Berlin, Heidelberg. Springer-Verlag. 10.1007/978-3-642-24276-2_13. 978-3-642-24275-5 .
- Ekblad. Anton. Claessen. Koen. 2015-05-11. A seamless, client-centric programming model for type safe web applications. ACM SIGPLAN Notices. 49. 12. 79–89. 10.1145/2775050.2633367. 0362-1340.
- Web site: Fun (a programming language for the realtime web). marcuswest.in. 2020-05-04.
- Leijen. Daan. 2014. Koka: Programming with Row Polymorphic Effect Types.. Electronic Proceedings in Theoretical Computer Science. 153. 100–126. 10.4204/EPTCS.153.8. 1406.2061. 14902937.
- Book: Neubauer, Matthias. Proceedings of the 32nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages . From sequential programs to multi-tier applications by program transformation . 2005. 221–232. 10.1145/1040305.1040324. 158113830X. 10338936.
- ChongStephen. LiuJed. C. MyersAndrew. QiXin. VikramK. ZhengLantian. ZhengXin. 2007-10-14. Secure web applications via automatic partitioning. ACM SIGOPS Operating Systems Review. 41. 6. 31–44. EN. 10.1145/1323293.1294265. 1813/5769 . free.
- Manolescu. Dragos. 2008. Volta: Developing Distributed Applications by Recompiling.. IEEE Software. 25. 5. 53–59. 10.1109/MS.2008.131. 24360031.
- Book: Kereki, Federico, 1960-. Essential GWT: building for the web with Google Web toolkit 2. 2011. Addison-Wesley. 978-0-321-70563-1. Upper Saddle River, NJ. 606556208.
- Book: Strack, Isaac. Getting started with Meteor JavaScript framework. January 2012. 978-1-78216-083-0. Birmingham. 823718999.
- Book: Tilevich, Eli. ECOOP 2002 — Object-Oriented Programming . J-Orchestra: Automatic Java Application Partitioning . 2002. Lecture Notes in Computer Science. 2374. 178–204. 10.1007/3-540-47993-7_8. 1853/6531 . 978-3-540-43759-8.
- Book: Berry. Gérard. Nicolas. Cyprien. Serrano. Manuel. Proceedings of the 1st ACM SIGPLAN international workshop on Programming language and systems technologies for internet clients . Hiphop . 2011. http://dx.doi.org/10.1145/2093328.2093337. 49. New York, New York, USA. ACM Press. 10.1145/2093328.2093337. 978-1-4503-1171-7. 1280230.
- Thywissen. John A.. 2016. Implicitly Distributing Pervasively Concurrent Programs: Extended abstract.. 1. 10.1145/2957319.2957370. 6124391.
- Zdancewic. Steve. 2002. Secure program partitioning.. ACM Trans. Comput. Syst.. 20. 3. 283–328. 10.1145/566340.566343. 1776939.
- Guha. Arjun. Jeannin. Jean-Baptiste. Nigam. Rachit. Tangen. Jane. Shambaugh. Rian. 2017. Lerner. Benjamin S.. Bodík. Rastislav. Krishnamurthi. Shriram. Fission: Secure Dynamic Code-Splitting for JavaScript. 2nd Summit on Advances in Programming Languages (SNAPL 2017). Leibniz International Proceedings in Informatics (LIPIcs). Dagstuhl, Germany. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik. 71. 5:1–5:13. 10.4230/LIPIcs.SNAPL.2017.5. free . 978-3-95977-032-3.
- Chong. Stephen. 2007. SIF: Enforcing Confidentiality and Integrity in Web Applications..
- Groenewegen. Danny M.. 2008. WebDSL: a domain-specific language for dynamic web applications.. 779–780. 10.1145/1449814.1449858. 8073129.
- Sewell. Peter. 2005. Acute: high-level programming language design for distributed computation.. 15–26. 10.1145/1086365.1086370. 1308126.
- Book: Hemel, Zef. Proceedings of the 2011 ACM international conference on Object oriented programming systems languages and applications . Declaratively programming the mobile web with Mobl . 2011. 695–712. 10.1145/2048066.2048121. 9781450309400. 10480906.
- Book: Richard-Foy, Julien. Proceedings of the 12th international conference on Generative programming: Concepts & experiences . Efficient high-level abstractions for web programming . 2013. 53–60. 10.1145/2517208.2517227. 9781450323734. 14305623.