New programming language automatically coordinates interactions between web page components

Credit: iStock / MIT

A web page today is the result of a number of interactive components, such as cascading style sheets, XML code, ad hoc database queries, and JavaScript functions. For all but the most rudimentary sites, keeping track of how these different elements interact, relate to each other, and pass data to each other can be a tedious chore.

In an article presented at the Association for Computing Machinery Symposium on Principles of Programming Languages, Adam Chlipala, Douglas Ross Career Development Professor of Software Technology, describes a new programming language, called Ur / Web, that enables developers to write web applications as -contained programs. The language compiler, the program that transforms high-level instructions into machine-executable code, then automatically generates the corresponding XML code and stylesheet specifications and integrates the JavaScript and database code in the right places.

Besides making web applications easier to write, Ur / Web also makes them more secure. “Let’s say you want to have a calendar widget on your webpage, and you are going to use a library that provides the calendar widget, and on the same page there is also an advertisement box based on the code provided by the ad network, ”says Chlipala. “What you don’t want is for the ad network to be able to alter how the calendar works, or for the author of the calendar code to be able to interfere with the serving of the ads.” Ur / Web automatically prohibits this type of unauthorized access between the elements of the page.

Entry, framing

Ur / Web’s ability to provide security protection and coordinate disparate web technologies stems from two properties that it shares with most full-fledged programming languages, like C ++ or Java. One is that it is “strongly typed”. This means that any new variable defined by a programmer in Ur / Web is limited to a particular data type. Likewise, any specification of a new function must include the type of data on which the function acts and the type of data it returns.

When calculating the value to return, the function may need to create new variables. (A function that returns an average of values ​​in a database, for example, should first calculate their sum.) But these variables are inaccessible to the rest of the program. This is the second property, known as “variable scope” because it limits the scope – the extent of accessibility – of variables defined in functions.

“You might want to write a library that contains inside as private state the database table that stores usernames and passwords,” says Chlipala. “You don’t want another part of your application to be able to just read and override passwords. Most web frameworks do not support this style. They assume that every part of your program has full access to the database. “

Typing also contributes to safety. Many web development frameworks generate database queries in such a way that a person conspicuously logging into a website can type code into the username field which in effect overwrites database data. data. With Ur / Web, usernames would be their own data type, which would be treated very differently from database queries.

Meeting expectations

Typing is also what enables coordination between web technologies. Suppose a piece of JavaScript code is supposed to act on data pulled from a database, and the result is supposed to be displayed on a web page at a location determined by XML code. If an Ur / Web programmer wrote a database query that extracted data of a type that JavaScript did not expect, or if JavaScript generated output of a type that the XML page did not expect, the compiler would save away and would report the code as containing an error.

Often, code that is not explicitly typed still has implicit consistency rules. For example, if you write a query in the database language SQL that requests the average numeric value of a group of text fields, the database server will tell you that it cannot process your query. To enable Ur / Web to coordinate the flow of data between web technologies, Chlipala had to create libraries of new data types for SQL, XML, and Cascading Style Sheets (CSS) that embody these rules.

Although the Ur / Web compiler generates XML, JavaScript, and SQL code in its current version, it does not automatically produce stylesheets. But, says Chlipala, “One thing the compiler can do is parse your entire program and say, ‘Here is a comprehensive list of all the CSS classes that could be mentioned, and here is a description of the context in which each class could. be used, which tells you which properties might be worth setting. ‘ So, for example, a particular class might never be used in a position where the properties of the table would have meaning, so you don’t have to worry about setting them. ”

New programming language adapts to multiple languages ​​in the same program

More information:
Paper: “Ur / Web: A Simple Template for Programming the Web

Provided by the Massachusetts Institute of Technology

Quote: New programming language automatically coordinates interactions between web page components (December 23, 2014, retrieved September 17, 2021 from web-page.html

This document is subject to copyright. Other than fair use for private study or research purposes, no part may be reproduced without written permission. The content is provided for information only.

Source link

Comments are closed.