Showing posts with label Coding. Show all posts
Showing posts with label Coding. Show all posts

Sunday, 6 January 2008

Encapsulating javascript objects (xmlhttprequest)

As much as I loathe Javascript objects, using them gives the developer control and limit the opportunity of overriding existing Javascript. What I really wanted to do is encapsulate the xmlhttprequest into a nice class. Unfortunately, xmlhttprequest itself uses a caller function, onreadystatechange. This proves a huge challenge. Essentially, you want to include a function/method to handle the call. But believe me, this is a headscratcher. One interesting technique is to take a copy of the class instance before running the onreadystatechange function. You then have scope to the global instance and as well as the current instance as demonstrated at mike chambers. Unfortunately, it looks like firefox and ie handle things a little different. I tried to set a text attribute for my class within the caller function, to my surprise, Internet Explorer sets it but for some reason Firefox has it undefined and only used my text attribute in a local scope. Another solution is provided hunlock. This looks to be a useful module indeed, exactly what I am looking for. But once again, firefox doesn't appear to like it.

Javascript Objects

I remember a long time ago in a job interview, saying that there was no such thing as javascript objects. This was when the notion of javascript objects was introduced on very hoky browsers like Netscape and IE. It certainly wasn't cross-browser friendly then and it looks like not a lot has changed there. I still think Javascript objects and classes are immature. Looking at articles on Javascript objects, there are number of different notations that could give average developer a nightmare. For instance this oop javascript guide gives a thorough overview how to construct a javascript class properly. However, I do not like the idea of having to explicitly utilise such functions as makeConstructor, defineMethod, defineType, instantialize, getClassName. That said, the article is spot on its assessment of Javascript OOP...

"What you may say is 'Hey, the syntax is too complicated! Writing those syntaxes will frustrate me ...'
Actually, JavaScript is not an Object Oriented Programming language. But we create context so we can do OOP. And once the syntax is too complicated, we can simplify them. But I consider borrowing the existed mature Java language would be a better choice. That is, we can write in the style of Java, which is sure an OOP style language, and then we converts the Java codes into JavaScript codes, which is somewhat syntactic complicated. And then we have a great thing."

Fortunately, there are more simpler articles that demonstrates ways of creating Javascript objects, howtocreate, mozilla and mckoss still use the newly created class' prototype object. The only benefit I see, it gives you a chance to define functions and attributes for later and also can separate functions and attributes leaving the main class constructor. However, if you are comparing against natural OOP language like Java, C++ and C#, you usually do not have to define these functions and objects explicitly and you can incorporate methods and attributes into your classes (that you would normally see in naural OOP languages) as demonstrated in these even simpler articles from daaq and asp-ajax.

Also stumbled some interesting article on using JSON objects from hunlock and some useful javascript inheritance techniques in prototypejs.

Sunday, 2 December 2007

London Perl Workshop

Yesterday, I attended the London Perl Workshop just to see what stuff is the out there in the Perl world. There was some interesting stuff discussed. I should look into more of these details. I badly need a new (used) desktop with Linux. I'm still of the opinion things are better that way for Perl development. I bumped into a couple of acquaintances as well! One of the funny things that happened was someone brought in a cowbell and played it at the end of the workshop and made reference to more cowbell in a Saturday Night Live sketch, which I started playing the video loudly.

I also bought a couple of books Intermediate Perl and Mastering Perl for work.
But I will have a look at it first. ;)

Sunday, 15 April 2007

Let's get technical!!!

Greetings to one and all to my blog. I'll make no secret that I actually have another blog but this one is going to be more random technical musings. So enjoy...

Lately, I have been cooking up a perl module that I started on well over a year ago and then stopped until a month ago. It's an mp3 playlist generator. What it does it scans a given directory for files and prints off the mp3 (idv2) tag and prints it in csv/xml format. A CSV can be imported and mp3 tags can be reset. I've updated the module to update mp3 tags, check for duplicates and missing files in the imported CSV files.
The bottom line is I want to regenerate my playlist but also update the mp3 tag information to something I like (i.e. usual facts/trivia in the comments field).

I am probably my worst own critic when it comes to anything but I find I am a bit slow in coding. Mainly because I have a horrible nerve in getting things done properly. How other coders manage to program software amazes me, you will always miss something. The test::harness Perl module helps loads. I couldn't believe how many small mistakes (not enough to cause problems in regular program execution) I had made when I tested out the module I wrote.

I probably should try and release it as a CPAN module but I suspect that it is a bit specific.
My next pet project is to integrating that module with databases.

The weird thing is right now because I recently have changes roles at work and moved away from coding, I kind of miss it...