Programming and the Web

Declarative and Imperative Programming

TL;DR: Declarative programming describes what should happen (HTML, CSS, SQL), while imperative programming defines how it happens (JavaScript, Python). Declarative code is like ordering a pizza—just say what you want. Imperative code is like making the pizza—following a recipe step by step.

Software development follows different paradigms, two of the most fundamental being declarative programming and imperative programming. These approaches shape how developers write code, structure logic, and solve problems. While declarative programming focuses on what should happen, imperative programming is concerned with how it happens.

Declarative programming is all about specifying the desired outcome without worrying about the exact steps needed to achieve it. Common examples include HTML, CSS, and SQL, where the developer provides high-level instructions that another system interprets. For instance, writing <h1>Hello</h1> in HTML tells the browser to display a heading, but the underlying details of rendering it are abstracted away. Similarly, a SQL query like SELECT * FROM users retrieves data without specifying how the database should process the request.

Imperative programming, on the other hand, requires step-by-step instructions to achieve a result. Languages like JavaScript and Python follow this paradigm, executing sequenced instructions (algorithms) and using mutable data (variables) that change over time. Unlike declarative programming, imperative code includes logic and decision-making within its instructions, explicitly defining how a task is performed.

A restaurant analogy helps illustrate the difference. When ordering a pizza, a customer simply states what they want—the desired outcome—without specifying the steps required to make it. This represents declarative programming, where users are shielded from implementation details. However, in the kitchen, the chef must follow a detailed recipe, adding ingredients in a specific order to achieve the final dish. This step-by-step process mirrors imperative programming, where the focus is on how the result is produced.

Both paradigms play essential roles in software development. Declarative programming simplifies code by focusing on outcomes, while imperative programming provides full control over execution. Most modern applications blend both approaches, leveraging their strengths depending on the task at hand.

HTML and the birth of the world wide web

HTML, the Hypertext Markup Language, revolutionized information sharing. Its roots trace back to the General Markup Language (GML), developed in the 1960s to structure machine-readable documents. Later standardised as SGML, it introduced headings, paragraphs, and tables—but lacked hypertext.

In the late 1980s, physicists at CERN needed a way to organize and share research. Tim Berners-Lee, a CERN researcher, proposed a system where documents could be interconnected via clickable links rather than static downloads. This idea, inspired by hypertext, led him to develop HTTP (Hypertext Transfer Protocol) and HTML, based on SGML but with added hyperlink capabilities.

Berners-Lee also built the first web browser and web server, enabling researchers to access linked documents across a global network. Encouraging others to expand on his ideas, HTML rapidly evolved, leading to the explosive growth of the World Wide Web within just five years.