Mar 19, 2013

Hello "Web Languages", Where's the "Web"?

I just have to get this off my chest.

How come the leading "web languages" are all languages that don't have a single web-specific feature?

Before flames start coming out of your eyes, let me explain what I mean.

Every major "web language", including PHP, JavaScript, Ruby and Python, has APIs and frameworks that make them useful for web-development. But all of those languages actually belong to various families of classical programming languages, and haven't actually added anything to the languages over time, that make them more suitable for web-development as such.

As a web-developer, and given how web-development is practically synonymous with software-development in this day and age, I find it disappointing that so little effort has been put into making the languages themselves more web-friendly.

I should preface by saying that this is not intended to be a language comparison - I'm only looking at the aspects that relate directly to web-development.

Let's take a look at some of the most popular "web" features of the leading most popular "web language", namely PHP:

  • Inlining code fragments in documents: this is commonly thought of as one of the things that make PHP a "web" language - that you can embed pieces of code between HTML/XML tags. But in actuality, everything outside of the <?php ?> tags is just seen as implicit echo statements. Markup is merely text to the PHP interpreter. Hence, this has nothing to do with any web-technology as such.
  • $_GET, $_POST, $_SERVER: these are merely global variables - other languages have their own APIs providing access to query fragments, post-data and server-variables, this just happen to be exposed as superglobals in PHP.
  • XML, XSL, DOM, JSON, etc. - these web-technologies are simply integrated into the language as run-times, exposed to you via APIs. They weren't even implemented in the language itself, but in C - so we rely on a language that is by most people's definition explicitly not a "web language" for the real underlying support for web-technologies. In other words, the web-related APIs are not a feature of the language, but of the external run-time libraries that are available for the language.
  • OpenSSL, stream-wrappers, HTTP, FTP, etc. - most other languages have support for streams in some form or other - some languages had streams before there was Internet. And again, these are features that ship as part of the platform - they're not language features.
  • Multi-tenancy: because PHP processes aren't static, we can host hundreds of sites on the same server. Scripts only take up resources for an instant while processing a request - each site/app does not occupy memory or threads while waiting for a request. This appears to be a big reason why more hosting companies like to host PHP more than, say, Ruby or Node - because they execute as a static process. In actuality though, Apache (not PHP) is responsible for the multi-tenancy, which also applies to (for example) PERL scripts. It could be implemented in other languages, by starting with an HTTP server that is designed for multi-tenancy, e.g. sandboxing modules for security. So this is another platform feature, and not a language feature.

The bottom line, is that the world's most popular web-languages do not in fact have any web-features.

Note that I'm only using PHP as a case example here - you can apply the same arguments to Ruby, Python or JavaScript. I'm not trying to knock on PHP, or claim that PHP (or any other language) is "unsuitable" for web-applications - that would be ridiculous, especially given that I build web-applications (primarily) with PHP for a living, and I might not go as far as to say that I love it, but as languages go, I really like PHP a lot.

But I'm informed enough to know that PHP, like most other mainstream languages, merely borrows concepts from classical, general-purpose programming languages - and as such, by definition, the language should be considered a general-purpose language.

Let's contrast that with a language that was designed specifically for web-applications - here's a summary of some of the language-features of a fairly new language called Opa:

  • JavaScript: Since JavaScript is the most prevalent client-side language technology, Opa can transparently cross-compile Opa code to JavaScript, automatically slice client/server-concerns, and integrate JavaScript-versions of Opa code with the client-side.
  • HTML/XML: Because the heart of the web is HTML (and XML) it is not merely supported via an API or as objects, but as literal values. A portion of Opa syntax is HTML syntax - and it's not just being interpreted as strings, but closely integrated with the DOM on the client-side.
  • REST/SOAP: Web APIs are increasingly available and increasingly necessary - the Opa language facilitates transparent integration of web-services, allowing you program against remote services as you would any other local API.
  • Databases: Because web-applications by definition are multi-user applications, they are almost always backed by a database. Because this is such as central requirement to web-applications, Opa has language-level support for binding variables directly to database objects, as well as as for querying those objects.

In other words, working with technologies like HTML, CSS, DOM, XML and JavaScript is not a detour from the language itself - it's part of it.

Opa is also a compiled language, it's a functional language (which poses it's own barriers for most people with a classical OOP background) and every application is a static process - so this platform has drawbacks, too, but that's beyond the scope of this discussion, which only deals with the aspect of language.

tech·nol·o·gy (noun)
"The application of scientific knowledge for practical purposes, esp. in industry."
I'm not religious when it comes to programming languages. Technology as such is merely ideas and tools we create to make our lives easier, and every technology, without exceptions will one day be replaced. Because technology is only useful until it is no longer practical.

Even technology such as The Wheel will one day become a fun historical artifact that people will look back at with giggles.

Software is still a fart in the grand perspective of the timeline of History. How pompous would it be to assume that a little thing like a programming language is here to stay indefinitely?

The ideas and concepts in mainstream languages that dominate the web-industry, really weren't designed for the web - can general-purpose programming languages keep up indefinitely by merely adding another API or another general-purpose language feature?

I hope this is encouragement to start looking more critically at the languages we use for web-development.

No comments:

Post a Comment