Categories
Cosmography Technology

Hex Code

Well I suppose I’m a programmer now. Of all things.

It’s not what I expected, to be honest. I still associate the word with men in lab coats and bow ties in front of banks of flickering lights, doing arcane things at rattly teleprinter terminals. Something to do with rockets probably. Robots even. And punched paper tape!

Hippo

Punched paper tape was amazing, I used to collect discarded lengths of it from offices where my mother worked as a temp. Its perforated patterns are the perfect metaphor for the state of computing when I was a child. Pretty, delicate, clearly meaningful and yet profoundly mysterious.

These days? It’s writing really. You’re using language, a kind of language, to convey your intended meaning. Like much writing it’s part creativity, part drudgery and repetition. Long-separated senses of the word “hack” meet by surprise in a foreign city.

And like their natural counterparts, programming languages are a pretty diverse bunch. But you’ll hardly find two more different than the ones I just certified in – SQL and PHP. They’re like Choctaw and Chinese. Or more helpfully, Latin and English. One is (relatively) ancient, dusty and rule-bound, the other young and a bit anarchic.

Strangely though, it’s the old one that was actually designed to be English-like. And in the time of the lab coats I guess it seemed like it. A SQL command is called a “statement”, and is constructed much like a sentence:

Select roses, tulips from basket join bouquet where colour = "red"

Sounds almost like the real thing, doesn’t it? But…

Select camel, serendipity from D547 join moonslip where fandango = "buttocks"

…is equally meaningful. The resemblance to human language is superficial for a reason: In SQL there is only a handful of verbs, representing the very limited set of things you can do with items in a database. Its ‘nouns’ are little more than arbitrary labels. Real language is almost immeasurably more complex than that.

The thing that makes SQL seem completely unnatural though is its obsession with data types. These are important up to a point of course. You need to know what kind of data you’re dealing with, whether it’s numbers, “string” (which is what programmers like to call written words), dates and times, or more exotic stuff. You can’t add a word to a number or multiply a date.

But in SQL these break down into seemingly endless subtypes: For a number you need to know what the base is, whether it has a decimal point, if it’s positive or negative. With words it matters what the language is so that the right characters are used, plus you need to know what alphabetical order is for those characters, whether case is significant and so on. Dates and times are available in a mind-bending range of formats, depending on, say, whether you’re more interested in events since 1,000 AD or 1970.

Where it gets ludicrous is that there are still further subdivisions, into units of different size. (My favourite is called the Binary Large Object – or for short, BLOB.) The idea was to set aside only as much space as your data is going to need. If you have a column wide enough for six-figure sums and then enter numbers in the hundreds, you’re effectively saving blank decimal places to your hard disk. In the ’70s, disks were expensive. There was no room for empty space.

Compared to this, PHP seems like it was invented by hippoes. (I meant to say hippies there but I’m going to leave the typo in.) It’s just so… relaxed, skipping lightly over the very things that make SQL tedious. It seems to just guess what your data type ought to be. “You’re trying to add a number and a letter together? No problem, let’s see what happens.”

What makes it even more like human language though is the fact that it’s “Object Oriented”. This is a big idea so I’ll leave the details for another post, but suffice it to say that like real nouns, an object in OO programming is meant to represent something in the world. As such it comes with its associated “verbs” (known as methods) that represent the actions characteristic of that object. So the things that exist in your program have hidden powers that you can call upon if you know the right words. Cool.

Perhaps the best comparison then is not with different natural languages, but with different specialised jargon. Moving from SQL to PHP feels a lot like leaving contract law to take up alchemy.

Categories
Technology

PHP For Very Beginners

500px-PHP-logo.svg

I’ve been talking about PHP a lot recently, but so far I’ve said little about what it is and how it works.

So, What is PHP?

It’s a programming language, used to greatly increase the capabilities of a website. In this way it’s very comparable to JavaScript, and can even be seen as its complement. Both are ‘scripting’ languages. Unlike ordinary programs which are written in human-readable code and then ‘compiled’ to the binary instructions that computers can execute, scripts stay human-readable. Their code is executed by an interpreter program. With JavaScript, that program is your Web browser – any script in a web page you view actually runs as a program on your own computer. PHP however is interpreted by the PHP program, and this must be installed on the computer where the web page is held – the web server. For this reason it’s described as a ‘server-side scripting language’.

PHP files are a lot like HTML web pages, but also contain these PHP instructions or ‘scripts’. In normal Web browsing, the user requests a file by clicking on a link to it. If this is HTML it is sent directly to them, to be rendered on the screen as text and images by their browser. If it’s a PHP file however it is sent first to the PHP interpreter on the server. Here the scripts it contains are executed and the results – which are always HTML – inserted into the document where the script used to be. Now entirely HTML, it is sent to the user’s browser to be rendered in the usual manner.

So What Can They Do There, These Scripts?

It’s really just a programming language like any other. If you already know one of the more popular ones – C++, JavaScript, Perl – it will all look pretty familiar.¹ So you could use it for any computational purpose imaginable (it is ‘Turing complete’, as the theorists say). I wouldn’t though. What makes PHP special is not so much what it is as where it is: Sitting between the HTML and a database on a web server, allowing one to talk to the other.

In this way PHP can take requests from a website user, turn them into SQL or some other database query language, and format the results of the query as HTML to send back to the user’s browser where they can be displayed. As I mentioned in the previous post (and the one before that), this is a hugely powerful and flexible technique that can be used for untold purposes. While pages of search results would seem an obvious example, that’s just the nursery slopes. Systems as complex as Facebook are built in PHP. And systems that are good too.

¹Don’t worry if you don’t, there is much you can do with PHP without knowing any programming at all. Thanks to the likes of WordPress, Drupal, Joomla and many more, you can install and run a PHP-based site without speaking a word of the language.
Categories
Technology

The Machines That Make The Web

CMScartoon1For our next project, we don’t just make a website. We make a way to make a website. Ya may have noticed the Web has transformed drastically in the last few years. Well OK maybe you haven’t noticed. Transformation is pretty much the norm for the Web. But in a short time there has been a sea-change behind the scenes. Or a scene change beneath the sea. One of those. To be clear, this ain’t your parents’ Web.

Twenty years ago when HTML was new-born, most pages were just text with a few code words (called “tags”) laced through. You could type a page into a computer by hand, upload it to another computer called the web server, and voilà, you had a website. Or more precisely, you had a document sitting on a server. Someone typed the address of your page into their browser, the software on the server sent them a copy of what you uploaded. Done. Things were simpler then.

You can still do this indeed. It’s easier than you will be imagining to create a basic website. What’s considerably harder is making a page someone will actually look at. Constantly-changing, information-rich things like Google search results or Facebook timelines or eBay auctions clearly aren’t waiting around as static documents on a server somewhere. Nor are they being typed up on demand by millions of underpaid interns – though that is an entertaining thought. All such modern sites have one thing in common: a database.

This really means no more than putting your information into tables so it’s logically organised and accessible, but the difference that makes is enormous. Say you’re looking for a particular car, a blue Golf around ten years old, for less than about 2,000 eurodollarpounds. Imagine having to read through the details of hundreds and hundreds of used cars arranged in no particular order. You’d settle for the first one you found. Hell after an hour you’d settle for a burnt orange Daihatsu three-wheeler. But if the info is in a database the computer can do the tedious work for you, instantly winnowing that huge list down to the few that meet your criteria. Most excellent; this sort of thing is why we keep those darn machines around.

And a huge proportion of modern websites also work this way. Instead of sending out static documents on request, new software on the web server takes the visitor’s input, queries the database for relevant information – which could include images and other media as well as text – and pours the results into a template to create a custom page. And that is what it sends back to the visitor – a document that didn’t even exist before they asked for it.

This ‘new software’ on the web server is called a Content Management System, or CMS. You create the templates that dictate how your pages will look, you put the information into the database, but the CMS mixes them together and serves them to your website visitors. Modern ones even give you tools to create those templates and an interface with which to enter your information. A good one is as easy to use as a word processor – like the one I’m writing on here.

A content management system is what we need for the ‘team thesis’ I spoke of. We could make our own one using PHP, a popular language for writing code that runs on web servers, but the objective is not to show off our coding skills. The objective is to deliver a real working solution to a real working client. If we were consultants here, we’d recommend they use an existing CMS, customised for their needs. So that’s exactly what we’ll do for them – choose the best for their needs, and customise it to suit them even better. There is a huge range of great ones available.

The question we face now is, which?

Categories
Cosmography Technology

A Walk In The Bog

Nesting swans

Web design with Drupal is weirdly impressionistic. Even after turning off all the parts of it I’m sure I don’t need – well, almost sure – there are still so many options and switches that I really can’t hold them all in my head. Maybe one day, but not yet.

And it’s difficult to know what consequences changing any one of them will have. It may achieve the goal of fixing an annoying behaviour, while elsewhere making half the site drop off. So progress has been a slow mix of careful testing, frantic searching to find a setting I know I saw earlier, installing several new modules in a vain attempt to gain one missing function, and just pressing buttons randomly to see what’ll happen.

All four strategies work about equally well.

So I went for a walk. Partly to take a break from this madness, but more because I’m still in mild but constant pain. To the point where I’m just annoyed with myself now. Even if I’d done nothing more than occasionally walk around a bit I wouldn’t be so prone to back injury.

My excuse all winter was that it’s just too wet outside to walk. But is it really? It doesn’t rain every day, even here. And there’s no shortage of roads worth walking, even a canal that goes right past the village. Our own canal! Built in the 19th century to drain the bog. I don’t think it works, but it teems with wildlife, and it is full of sky.

So some Desolate-West-of-Ireland pics:

One of my favourite trees
If I had a rowing boat, I wouldn’t leave it face up in the rain
Sky. For you. In the sky.
%d bloggers like this: