Out of the corner of my eye

Exploring HumanStateSpace

Out of the corner of my eye header image 1

Get current form data from TinyMCE

December 6th, 2007 · No Comments

If you’re using TinyMCE for some kind of web GUI and want to access the current data contained in the textarea using JavaScript, you may have noticed that just getting it will only give you what was loaded into the textarea’s inner content in the HTML. To get the content the user has inputted into the textarea without submitting the form, simply call

tinyMCE.triggerSave(0,1);

This will force tinyMCE to write back its internal data to the form.

→ No CommentsCategories: Web dev

Audio CAPTCHAs

December 6th, 2007 · No Comments

I spent quite some time implementing an audio version of our CAPTCHA. It took longer than the visual version, and I ended up modifying Nick Swardh’s code to get it done in the end. It isn’t too hard once you figure out how to join mp3s together so let’s look at what’s out there already, because I have a few things to say about them…

Google Accounts and Microsoft Live both feature an audio CAPTCHA. The initial presentation leads you to believe this could be something that genuinely improves accessibility — that is, until you actually try to listen to them. Microsoft’s pops up windows all over the place for a start (can’t be much fun in a screen reader, can it?). Then both of them play an audio stream that, quite frankly, is harder to decipher due to the excessive background noise than the worst visual CAPTCHAs I’ve seen.

This could be justified by that argument that “well, blind people’s hearing is better than sighted people”, but to be honest I think it’s just another case of “CAPTCHA overkill”. This leads to lots of false positives and a reduction in site visitors.

What’s the point of locking out people from using your site just to stop spam? Is it really worth it?

→ No CommentsCategories: Web dev

The Destruction of Sennacherib

December 6th, 2007 · No Comments

by Lord Byron

The Assyrian came down like the wolf on the fold,
And his cohorts were gleaming in purple and gold;
And the sheen of their spears was like stars on the sea,
When the blue wave rolls nightly on deep Galilee.

Like the leaves of the forest when Summer is green,
That host with their banners at sunset were seen:
Like the leaves of the forest when Autumn hath blown,
That host on the morrow lay withered and strown.

For the Angel of Death spread his wings on the blast,
And breathed in the face of the foe as he passed;
And the eyes of the sleepers waxed deadly and chill,
And their hearts but once heaved, and for ever grew still!

And there lay the steed with his nostril all wide,
But through it there rolled not the breath of his pride;
And the foam of his gasping lay white on the turf,
And cold as the spray of the rock-beating surf.

And there lay the rider distorted and pale,
With the dew on his brow, and the rust on his mail:
And the tents were all silent, the banners alone,
The lances unlifted, the trumpet unblown.

And the widows of Ashur are loud in their wail,
And the idols are broke in the temple of Baal;
And the might of the Gentile, unsmote by the sword,
Hath melted like snow in the glance of the Lord!

→ No CommentsCategories: Culture

Response to “signs you’re a crappy programmer”

December 2nd, 2007 · No Comments

Damien Katz blogged some “signs you’re a crappy programmer (and don’t know it)”, and the article ended up on the front page of Digg. Many of the comments criticised some of what he said, but I didn’t anywhere find what I felt should be the strongest criticism of “You think no function/method should have multiple return points.”

A lot of people vaguely mentioned it makes functions harder to debug, but weren’t very specific. In case anyone is still undecided on this, I’ll tell you about one of my experiences trying to debug such a function.

It was when I was working in the games industry. Video games these days when they come out are expected to have 0 bugs and 0 memory leaks. Probably an unobtainable goal, but most devs work pretty damn hard towards this target, particularly the memory leaks part. This is because consoles don’t have anywhere near as much memory as high end gaming PC’s - you just can’t afford to waste any memory.

The function in question was quite a large one (another thing Damien states is perfectly fine). I can’t remember exactly what it did, but I do remember at one point it implicitly allocated memory to play a sound. Then about a page further down, there was an “early out” condition. Finally, at the end of the function, the memory was freed.

It took me quite a few hours to nail the memory leak. It wasn’t immediately obvious the memory was being allocated, and more importantly, it was only after very carefully examining every line of the function that I even realised there was an early out - just that one little “return”, hiding amongst a massive set of complicated conditional statements.

Someone on Damien’s blog post commented that “what’s the problem, your IDE highlights return anyway, you can’t miss it”. If I remember, I did have syntax highlighting on, but return wasn’t one of the keywords highlighted unfortunately (we used VI, not Visual Studio).

Much time would have been saved if:

1) early outs hadn’t been used
2) the function had been refactored so it wasn’t so long

To further drive this point home, my lead at the time had already told me about how he doesn’t like people using early outs and recommends we try to avoid them if possible. Obviously it’s a recommendation, but a good one I believe.

→ No CommentsCategories: C++ dev

Lazy programmers - why is ‘protected’ the default?

December 1st, 2007 · No Comments

Lots of programmers seem to use protected as the default access level, and I think it’s lazy.

I can kind of see the reasoning: you don’t want to expose your variables and private methods because the user of your class probably won’t know what they should be changing and what should be left alone, but you assume if someone is deriving from the class, then they can be trusted to work out how everything works, and it’s safe to give them free reign over everything. Besides, they can just change the base’s members to protected themselves, so why bother trying to stop them?

Personally I think that’s exactly what should happen. Unless you specifically intend something to be used by derived classes, members should be marked as private, and the programmer deriving the class should be responsible for opening up the parts of the base that they require access to. That way, the strongest level of encapsulation is maintained, and hopefully the programmer will be more motivated to learn about how the class works.

Conversely, this may put off people from deriving classes when it makes sense to do so. How high a fence should you really build around communal stuff?

→ No CommentsCategories: C++ dev

What happened to webrings?

November 11th, 2007 · No Comments

Back in the good ol’ days, when half of the web’s personal homepages were hosted on geocities, there were a standard set of homepage ‘add ons’ that most people used: hit counters (now superceded by more complicated backend analytics programs that parse web server logs), guest books (supplanted by more general comment systems), and web rings.

Joining a web ring involved registering your site with some central server, which gave you an html fragment you pasted into your page. This fragment contained some form of description of the web ring, and “Next” and “Previous” links that would take you to your neighbouring sites in the ring.

Of course, the idea had several flaws: broken html could break the entire ring, and sites were usually subject to an approval process of some kind to make sure no inappropriate sites were included. However, despite these flaws, I found web rings could be quite interesting - it was a way of seeing other sites that covered the same interests as yours, and helped build a little bit of community into your site.

These days, it’s every man for himself in the big old world of SEO and traffic monetization. Web masters serious about promoting their site are in a perpetual backlinks arms race. It’s a shame, because in many cases, link building has overridden building quality content. People don’t really look at their competitors sites as much anymore to see what they’re doing right or read what other people have to say about a subject. Instead of community, we have competition. It’s a shame.

Is it possible to bring back some of that community, some of that “my web neighbourhood” feeling, without compromising the professional design most sites require these days? Personal blogs were embraced by many companies - perhaps one day the lowly web ring will make a comeback…

→ No CommentsCategories: Web dev