Javascript best practices

18 Jan

Well I guess if I’m going to write any code then I should write it well. In an attempt to address my aversion to using javascript to do anything more complex than mucking about with the DOM and spicing up the interaction layer I’ve been looking around at how other folks are doing it.

Many of the blogs, discussions and  articles I found had a lot to say about old school client side javascript but that’s not what I’m looking for. I did come across this article on It discusses javascript best practices in a server side context and address one of my javascript bug bears. Specifically “what is this“, meaning what is the this that is currently in scope and how can I write my code so that this will be what it to be? By using the bind method when returning functions or passing functions as parameters the context in which they are called (their this) can be determined.

My mistrust of javascript as the sort of language you would want to do complex things with has decreased a little. In my next post I hope to describe the tools and environment needed to solve my pet problem described in  this article.

Server side JavaScript – what’s that good for then?

17 Jan

I used to hate Javascript. All those ugly unreadable DOM manipulations based on getElementById. Yuk.

But then I discovered jQuery and javascript was suddenly not only usable but also fun. I haven’t implemenbted a website since then without using jQuery. There are a few jQuery plugins that I regularly use, typically sliders, calendar clickers, that sort of thing but the real fun starts with coding up your own custom DOM manipulations and interaction layer bells and whistles. In the beginning I would pack all the code into $(document).ready(...) but these days I typically try to generalize the functionality and write a plugin.

But what’s all this fuss about server side javascript? Is it really a language that you want to use to create complex software? I’m not so sure about that. We’ll have to see. Despite my reservation about the prospect of using javascript to implement complex software I have an example where the ability to use in a server environment is at the least helpful and possibly essential.

Recently a collegue asked me to help him a with a problem he was having with a web scraping backend component. Certain information was being scraped form another site that was protected by a login. He had an account on the site so that with a bit of curl and a cookie jar he could fetch the information to incorporate into his own site. The problem arose when the site in question started using a login form that had a session specific identifier that was generated using jQuery after the page was ready. So the curl output did not contain the login form with its session specific login identifier and his POSTs to the login form’s URL were being ignored. This is where server side javascript comes into play. If I can run the DOM manipulation contained in the javascript in the page (and in linked js files) then when all is done I’ll have the login form with session specific identifyer that I need to make the login request.

Now that I think about it the session specific identifier probably comes from an ajax call. All I really need to do is find the call in the page’s linked js files and duplicate it with a curl request and I’ll have everything I need. Ignoring this (probably better) solution I’m going to press on and see what it takes to get jQuery (or whatevery other client site library, mootools, etc) running on a server.

Stay tuned for the next installment…

Augmented reality translator

13 Jan

Augmented reality translator in actionFabulous! Take a look at this. Welcome to the future.

Choose your weapon

12 Jan

What CMS do you use ? What CMS do you want to use? Compare them here.

Database version control

12 Jan

I’ve been breaking my brain for some time now thinking about how to incorporate database changes into version control. Here is a helpful article that addresses database structure version control. However the question of how to apply inserts in the production database with complicated record relationships is not addressed. Consider a CMS with a highly productive production environment. It is unreasonable to require all the authors, photographers and even editors to participate in version control, it’s hard enough to get some programmers interested! Unless some action is taken the database key values in the development and production environments will diverge.

If it is acceptable to prevent modifications to the production environment for the duration of the release and deploy process then the solution comes down to just doing the work. This is unfortunately not always the case.

When it is not acceptable to lock down the production environment for the duration of the release and deploy process then a differencing tool is required that understands the semantic relationships in the data and can apply the deltas to the production tables with respect to those relationships. I’ll be looking out for such a tool and if anyone knows one please post it here.

Time to start the list of lists

10 Jan

Daniel Raffel’s Favorite New Geek Stuff Of 2010

Business names in Holland

04 Jan

Ubiquitous, ubiquitous, ubiquitous. Lovely word. Yeah yeah, but useless as tits on a bull in Holland. Ask any Dutchman what it means and all you’ll get is a blank stare. I really have to stop wearing my propeller hat. It seems that a nerd is only worth the word that can be heard…

I had the same problem when I proudly announced that I’d be trading my web development and hosting services under the luminous name Prodigious… Blank stares, crickets chirping… Wassat then?

Ok, ok, ok. Lets make it Mobile Media Constructs then. Much better. Now I can concentrate on doing some work again.

The state of mobile browsers

16 Dec

“Users expect websites to work on their mobile phones. In two to three years, mobile support will become standard for any site. Web developers must add mobile web development to their skill set or risk losing clients…”

The world of facebook

15 Dec

Visualisation of global Facebook reltionships


13 Dec

Visionary insights from the last century. The last millennium!

Stuart McFarlane

Mobile Media Constructs