Sunday, January 13, 2008

Never Render a POST!

There are a few things in web design that you should never do, yet people seem to do them quite often.  I'll give a little explanation of this one first so my non-technical audience can tag along.  PHPers, please pay attention.

Web browsers understand two verbs when making a transaction with a web server: POST and GET. Generally, POST means you're sending information to the server, and GET means you're getting information back. In a perfect world, every web page you ever see would be the result of a GET, and every time you POSTed you would be redirected to a GETable page. But we don't live in a perfect world, do we?

The culprits are poorly-designed web-forms. Good web-forms like google.com submit via GET, which puts your search arguments in a query string after the url, like so: http://www.google.com/search?q=awesome . This is good because now you can copy that url and paste it to someone else, and they can see your search results too.

POST, on the other hand, sends the form's information to the server invisibly. If you render a page on a POST, you can't paste the url to someone else, because they will not have posted that information. If you hit Refresh on a posted page, or try to navigate back past one with your Back button, your browser will warn you that you are posting again. You have to POST again in order to see that page again. And that's annoying. Your browser can't even cache the page because it knows this is a dynamically generated response to a POST, so it will load slowly too.

POST should only be used for actions that change something on the server's side. They should never render content, but rather redirect to a GETable page to do that.  When you redirect, the POST's target page is stricken from the record, so can no longer navigate back to it and accidentally POST again.  Hooray!

Tuesday, January 8, 2008

Probability, Coincidences, and His Dark Materials

I finished reading The Subtle Knife yesterday, the second book in Philip Pullman's action-packed His Dark Materials science-fantasy series that deals with alternate universes, and attempts to link all of religion, science, and mysticism at once. Well, today was quite an interesting coincidence for me, but I'll have to say more about the series first.

Quite often Pullman refers to probability theory: it's at the root to his multiple universes idea (and everyone else's, for that matter), and he also makes the point that many of the characters' smallest choices could have had a dramatic effect on the multiverse--most especially the very first scene. It's almost a game at times, like when he states that Lyra is a girl who is "destined to end destiny". This passage near the beginning of The Amber Spyglass refers to probability theory explicitly:

"When you choose one way out of many, all the ways you don't take are snuffed out like candles, as if they'd never existed. At the moment, all Will's choices existed at once. But to keep them all in existence meant doing nothing. He had to choose, after all"

Well you can imagine my surprise when I went to my first day of classes, and that's exactly what both of my professors were talking about!

In Stochastic Mathematics, the professor told us that many elementary events exist in a sample space at first, but once an event has occurred, many of the outcomes cease to exist. The Professor even went so far as to explicitly say that they exist in alternate universes, and that "It is impossible to reach these alternate universes" in which these other outcomes would have occurred, once they are past.

On the way to lunch, a girl walking by said "Ugh, why must it be cold AND rainy. Couldn't it just be one or the other?" And I was compelled to say that the probability of cold ^ rainy far outweighed the probability of ~cold ^ rainy, because I am a geek and was in a probability mood.

It didn't end there, though, because next was Algorithms Analysis. And once again, we talked about probability theory! We were discussing pairing algorithms, and this professor just happened to use the very same wording as the other, when examining possible outcomes of stable pairing algorithms to prove it was optimal or pessimal for the related parties. "If, in some alternate universe, Ann and Zeus were together..."

Both were required classes, and I didn't give a second thought to what they were about before I stumbled in, though it seems they were both tightly linked to probability, and just as I got into the His Dark Materials series! What are the chances of that? *laugh track*

Anyway, in an alternate universe, I would have said this portion first:

The first book, for those unfamiliar, is called The Golden Compass. Any recent printing of this installment in the series is adorned with a little yellow bubble informing you of the related "Major Motion Picture" that New Line Cinema just released. And anyone interested enough to read the book and see the movie can tell you what a horribly mangled product New Line has produced. Though even those who haven't should be able to tell from the ridiculous dialog that something isn't quite right. Check out Bridge to the Stars, the series' fan-site, for a little back-story on how this atrocity occurred. Excuse me for the following paragraph's rant.

Much of the magic in the book is in how Pullman gradually reveals the facts, making earlier oddities and clues suddenly clear, and twisting your perception of his world in an instant. But the movie makes no attempt to preserve this--in fact, it reveals nearly everything you shouldn't know in the opening narration. The story itself is mangled beyond belief; it introduces a brand new antagonist, switches the order of the latter two thirds of the book, chops off the final three climactic chapters that change your perception of the entire story, and destroys every defining emotional moment for the sake of family friendly entertainment. The book was filled with compelling metaphors about religion and authority, but the movie seems to have only one moral: "It's better to read the book".

It was pretty funny to watch, being so bad, but it bothers me how a lot of people will probably just watch the movie instead of reading the book, and cheapen the whole experience for themselves. Movies have a way of becoming the definitive source for things, so of course the videogame will be terrible as well, as all games that ride on movie marketing are, and so will be many people's perceptions of the story. So I'd be quite interested in acquiring recordings of the two theatrical versions of His Dark materials, from the National Theatre and Playbox Theatre. Non-readers may actually watch these too!

The Subtle Knife is great, but it's a terribly violent book. I'd like to see New Line try to make that one family-friendly. But still, I hope they do make their silly movie after all, so I can play the second terrible game! The Subtle Knife cuts through dimensions after all--hey Portal fans, are you pondering what I'm pondering? I sure hope this gets something interesting started in the Half Life 2 Homebrew community!