Open Turds

I’ve open-sourced a lot of pretty shit code.

So whenever somebody says “I’m not open-sourcing this because the code is shit”, I think: wow, it must be spectacularly bad.

And that only makes me want to see it more.

The Page With No Code

It all started when I saw no-ht.ml, Terence Eden‘s hilarious response to Salma Alam-Naylor‘s excellent HTML is all you need to make a website. The latter is an argument against both the silly amount of JavaScript with which websites routinely burden their users, but also even against depending on CSS. As a fan of CSS Naked Day and a firm believer in using JS only for progressive enhancement, I’m obviously in favour.

Screenshot showing Terence Eden's no-ht.ml website, which uses plain text ASCII/Unicode art to argue that you don't need HTML.
Obviously no-ht.ml is to be taken as tongue-in-cheek, but as you’re about to see: it caught my interest and got me thinking: how could I go even further.

Terence’s site works by delivering a document with a claimed MIME type of text/html, but which contains only the (invalid) “HTML” code <!doctype UNICODE><meta charset="UTF-8"><plaintext> (to work around browsers’ wish to treat the page as HTML). This is followed by a block of UTF-8 plain text making use of spacing and emoji to illustrate and decorate the content. It’s frankly very silly, and I love it.1

I think it’s possible to go one step further, though, and create a web page with no code whatsoever. That is, one that you can read as if it were a regular web page, but where using View Source or e.g. downloading the page with curl will show you… nothing.

I present: The Page With No Code! (It’ll probably only work if you’re using Firefox, for reasons that will become apparent later.)

Screenshot showing my webpage, "The Page With No Code". Using white text (and some emojis) on a blue gradient background, it describes the same thought process as I describe in this blog post, and invites the reader to "View Source" and see that the page genuinely does appear to have no code.
I’d encourage you to visit The Page With No Code, use View Source to confirm for yourself that it truly has no code, and see if you can work out for yourself how it manages this feat… before coming back here for an explanation. Again: probably Firefox-only.

Once you’ve had a look for yourself and had a chance to form an opinion, here’s an explanation of the black magic that makes this atrocity possible:

  1. The page is blank. It’s delivered with Content-Type: text/html. Your browser interprets a completely-blank page as faulty and corrects it to a functionally-blank minimal HTML page: <html><head></head><body></body></html>.
  2. <body> and <html> elements can be styled with CSS; this includes the ability to add content: ::before and ::after each element. If only we could load a stylesheet then content injection is possible.
  3. We use the fourth way to inject CSS – a Link: HTTP header – to deliver a CSS payload (this, unfortunately, only works in Firefox). To further obfuscate what’s happening and remove the need for a round-trip, this is encoded as a data: URI.
Screenshot showing HTTP headers returned from a request to the No Code Webpage. A Link: header is highlighted, it contains a data: URL with a base64-encoded CSS stylesheet.
The stylesheet – and all the page content – is right there in the Link: header if you just care to decode it! Observe that while 5.84kB of data are transferred, the browser rightly states that the page is zero bytes in size.

This is one of the most disgusting things I’ve ever coded, and that’s saying a lot. I’m so proud of myself. You can view the code I used to generate this awful thing on Github.

My server-side implementation of this broke in 2023 after I upgraded Nginx; my new version doesn’t support the super-long Link: header needed to make this hack work, so I’ve updated the page to use the Link: to reference the CSS file rather than embed it via a data URI. It’s not as cool, but it at least means you can still see the page. Thanks to Thomas Bradshaw for pointing out the problem.

Footnotes

1 My first reaction was “why not just deliver something with Content-Type: text/plain; charset=utf-8 and dispense with the invalid code, but perhaps that’s just me overthinking the non-existent problem.

Instead Of Blogging…

Things I’ve been doing instead of blogging, this last month, include:

  • Code Week: hacking Three Rings code in a converted hay loft of a Derbyshire farm, as mentioned on the Three Rings blog.
  • Hoghton Tower: as is traditional at this time of year (see blog posts from 2010, 2009, 2005, 2003, for example), went to Preston for the Hoghton Tower concert and fireworks display, accompanied by Ruth, and my sister’s 22nd birthday. My other sister has more to say about it.
  • Family Picnic: Joining Ruth and JTA at Ruth’s annual family picnic, among her billions of second-cousins and third-aunts.
  • New Earthwarming: Having a mini housewarming on New Earth, where I live with Ruth, JTA, and Paul. A surprising number of people came from surprisingly far away, and it was fascinating to see some really interesting networking being done by a mixture of local people (from our various different “circles” down here) and distant guests.
  • Bodleian Staff Summer Party: Yet another reason to love my new employer! The drinks and the hog roast (well, roast vegetable sandwiches and falafel wraps for me, but still delicious) would have won me over by themselves. The band was just a bonus. The ice cream van that turned up and started dispensing free 99s: that was all just icing on the already-fabulous cake.
  • TeachMeet: Giving a 2-minute nanopresentation at the first Oxford Libraries TeachMeet, entitled Your Password Sucks. A copy of my presentation (now with annotations to make up for the fact that you can’t hear me talking over it) has been uploaded to the website.
  • New Earth Games Night: Like Geek Night, but with folks local to us, here, some of whom might have been put off by being called “Geeks”, in that strange way that people sometimes do. Also, hanging out with the Oxford On Board folks, who do similar things on Monday nights in the pub nearest my office.
  • Meeting Oxford Nightline: Oxford University’s Nightline is just about the only Nightline in the British Isles to not be using Three Rings, and they’re right on my doorstep, so I’ve been meeting up with some of their folks in order to try to work out why. Maybe, some day, I’ll actually understand the answer to that question.
  • Alton Towers & Camping: Ruth and I decided to celebrate the 4th anniversary of us getting together with a trip to Alton Towers, where their new ride, Thirteen, is really quite good (but don’t read up on it: it’s best enjoyed spoiler-free!), and a camping trip in the Lake District, with an exhausting but fulfilling trek to the summit of Glaramara.
Setting up camp at Stonethwaite.

That’s quite a lot of stuff, even aside from the usual work/volunteering/etc. stuff that goes on in my life, so it’s little wonder that I’ve neglected to blog about it all. Of course, there’s a guilt-inspired downside to this approach, and that’s that one feels compelled to not blog about anything else until finishing writing about the first neglected thing, and so the problem snowballs.

So this quick summary, above? That’s sort-of a declaration of blogger-bankruptcy on these topics, so I can finally stop thinking “Hmm, can’t blog about X until I’ve written about Code Week!”

×

The Modern Programmer’s Dictionary

In the field of  software development, there’s always something new to learn. Whether it’s a new language, framework, API or methodology, your need to study is never through – even if you’re a FORTRAN developer. But one of the more esoteric areas of your education will come in the form of the language programmers use, and I don’t mean programming languages.

And so I present to you a dictionary of modern programmer language (much of it shamelessly lifted from a discussion on Stack Overflow):

Ajah

Ajax, but returning HTML rather than XML (e.g. using jQuery‘s $.load method). Similarly, Ajaj, when you expect script to be returned (e.g. $.getScript).

Bicrement

Adding 2 to a number.

Boolean Zen

A principle of programming lacked by those who perform expressions to compare variables to boolean constants. For example, if (userHasLoggedIn == true) lacks Boolean Zen, because the == true at best does nothing at all, and at worst results in an unnecessary evaluation.

Classtrophobia

When someone chooses not to use the obvious object-oriented approach when it is available.

Common Law Feature

A bug in some software which has existed so long that it has begun to be depended upon by the users, who will complain loudly when it is “fixed”.

Doctype Decoration

In web development, the practice of putting a Doctype Declaration (e.g. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">) into the document despite not actually writing standards-compliant code. Often accompanied by putting a “Valid HTML & CSS” link on the site, but never actually checking that the site passes the validator’s test.

Egyptian Brackets

That style of coding which puts the opening brace { of a block on the same line as the expression (wrapped in parentheses) before it, e.g.:

if (expression){

So called because the ){ sort-of looks like a stereotypical ancient Egyptian pose, depending on your preferred coding font:

Floater

A bug that sits at the top of the bug tracking system, but nobody claims responsibility for it. Everybody just works around it.

Flock of Geese Code

A block of deeply-nested and heavily-indented code forming a tight V-shaped wedge. Often occurs when adding functionality to a complex block of evaluations, by a developer who hasn’t noticed that perhaps a return statement, exception-handling, the && operator or even a goto statement might be more appropriate! Especially poignant when using a bracketed-block language, where you’ll see a string of closing braces flying away at the end of the code.

Hi-Driven Development

A variety of printf-debugging where you pepper your code with alert('hi'); in order to find out where it’s going wrong, rather than breaking out a proper debugger. Other acceptable string literals include “hello”, “here”, “xyzzy”, etc.

Higgs-Bugson

A bug that you believe to exist based on sparse log data and theoretical examination, but you have no evidence to support the idea that it has ever actually been observed, except perhaps vague anecdotal evidence from users.

Hindenbug

A catastrophic bug resulting in a devastating loss (typically of data). “Oh, the humanity!”

headlessCamels

CamelCase words lacking a leading capital letter, as required or recommended for various languages, frameworks, and styles. As opposed to ProudCamels.

Heisenbug

First noticed on Usenet in the 80s, but still awesome: a bug that defies investigation because, during debugging (when you’re observing it), it behaves differently.

Hydra Code

Code so bug-riddled that killing one problem results in two more in it’s place, like the mythological Lernaean Hydra‘s many heads.

IRQed

Interrupted while you were trying to program. Not necessarily by somebody with an actual flag.

Loch Ness Monster Bug

An important bug, if ever it could be proven to exist. Only ever observed once or twice by users who were unable to back up or reproduce their claims. These users often go on to swear by the existence of the bug, blaming it for all kinds of unusual phenomena even in completely unrelated systems for years to come.

Ninja Comments

Comments which are so stealthy that you can’t see them at all. It’s almost as if the code weren’t documented at all!

NOPping

Like napping, but what programmers do while they’re downtiming while waiting for a computer to finish a task. Based on the NOOP or NOP operation found in many low-level languages.

NP Hilarious

An algorithm whose complexity is a joke, whether deliberately (e.g. Bogosort, but not Quantum Bogosort) or not.

Object Oriented Pasta

Spaghetti code wrapped up into classes to look like proper object-oriented code. Also Ravioli.

Pokémon Exception Handling

For when you positively, absolutely, “gotta catch ’em all.” I’m talking about hideous code like this:

try {
MessageBox.Show(message);
} catch(Exception exc) {
MessageBox.Show(exc.Message);
}

See also Try, Catch, Forget.

Refucktoring

As defined by Jason Gorman: refactoring code in such a way that you are now the only person capable of maintaining it. E.g. stripping all comments and whitespace from an arcane bit of code that you wrote in order to give yourself the illusion of being indispensable. Results in Mortgage Code (code which pays your mortgage because you can’t be fired while it exists).

Rubberducking

Sometimes you’re working on a problem and what you really need to do to solve it is to talk through the problem with somebody else. The other person doesn’t even need to be a developer: often, they don’t even need to listen – they just need to be there while you talk your way to your own solution. So much so, that they might as well be replaced with a rubber duck, sat atop your monitor. A name come up with by a programmer who apparently actually did this.

Scar Tissue

Commented-out blocks of old code, after refactoring, that have been checked in to the main codebase.

Shrug Report

A bug report which contains no reproducible information whatsoever, or is so unclear as to be ambiguous. Often contains phrases like “doesn’t work”, or doesn’t show how the anticipated behaviour differs from that observed (e.g. “when I click the print icon, the document is printed onto A4 paper from the feeder tray of the printer”).

Smug Report

A bug report submitted by a user who acts as if they know more about the system than the developer does.

Stringly-Typed

Use of strings for all kinds of inappropriate variables, like strings containing the words “true” and “false” for use in comparisons (not helped by the fact that some languages, like PHP, will let you get away with boolean comparisons on these). Also common among inexperience database developers, who’ll make an entire database of VARCHARs because they’re then able to store whatever they want in there, right?

Troolian Logic

Using a boolean variable to deliberately hold three states of information: true, false, and null. Often requires the use of the === operator to function properly.

Try, Catch, Forget

An exception handling strategy based purely on catching exceptions and then doing nothing with them. In other words, telling your program “if something goes wrong… carry on anyway!” Sometimes also seen as a Trynally – a block of code with a try and a finally block, but no catch blog at all. See also Pokémon Exception Handling.

Unicorny

Adjective used to describe a requested feature that’s so early in the planning stages it might as well be imaginary. Used by Yehuda Katz to describe some of Rails‘ upcoming features.

Yoda Conditions

Expressions that test for (literal == variable) rather than the more-common (variable == literal). The former is preferred by some programmers because it reduces the risk of accidentally using a single-equals rather than a double-equals (this mistake would produce a compiler error rather than simply misbehaving). So-called because it results in Yoda-like phraseology (e.g. “has no errors, the form does”).

×

Dreadful Deadlines

Just been working like a demon towards a 13:00 deadline this afternoon, delivering a piece of software to a client. Barely made it, but what a buzz!!! Celebrated with a pub lunch with two colleagues, Lisa (the SQL Queen) and Alex (the CodeMonkey, our office pet).

Claire called from Norfolk to say “Hi!” I’d have liked to chat longer, but I have work to do.

Have promised to scan and archive some old magazines with Kit this evening. Ho hum.