March 2004 - Posts
I read an interesting entry on Wired about spim - instant messaging spam.
"While less than 10 percent of current instant messages are spim, spim is now growing at 100 percent a year,"
http://www.wired.com/news/infostructure/0,1377,62805,00.html
From an article on itweb, it's hilarious:
“As far as Telkom is concerned, ‘network bypass' software is illegal and - although it is difficult to police - if we feel there has been a transgression in this regard, we can investigate and file a complaint with the Independent Communications Authority of SA (ICASA), and it will then take the necessary legal action,” says Weldrick.
http://www.itweb.co.za/sections/telecoms/2004/0403241148.asp?O=S&CiRestriction=skype
I often use lazy instantiation in order to keep my memory utilization at an acceptable rate. This is useful especially in scenarios where a hierarchy of objects exists - meaning composite relationships exists between classes.
To illustrate what I mean, I have devised a little scenario.
We want to write is a system that represents a library - to such an extent that even the paragraphs of text in the books will be represented by objects.
So we will have a few classes:
- Library
- Book
- Page
- Paragraph
The relationships of these objects are very easy to understand:
- A library contains many books (and without books isn't truly a library)
- A book contains many pages (and without pages isn't really a book)
- A page contains many paragraphs (and without paragraphs can't really be called a page - except if it was written by Terry Pratchett)
The following image uses UML to illustrate this relationship:

It would make sense to:
- Add a property to the Library class which is a collection of Books instances - all the books belonging to the library
- Add a property to the Book class which is a collection of Page instances - all the pages belonging to the book
- Add a property to the Page class which is a collection of Paragraph instances - all the paragraphs belonging to the page
We could put the code to instantiate the collection classes pertaining to each class in the constructors.
This would cause a little problem. Consider this:
- We have a library with a 1000 books.
- The books have an average of 200 pages.
- The pages have an average of 4 paragraphs.
If we were to instantiate this library it will instantiate a 1000 Book objects - even though they might not be referenced by the caller. Maybe the caller just wanted to access the address property of the library.
Each Book object that will be instantiated will instantiate another 200 page objects, which in turn will instantiate another 4 paragraphs. In the end we'll instantiate these objects, although we just wanted to get the address of the library:
- Library 1
- Books 1000
- Pages 200 000
- Paragraphs 800 000
What would be the correct way to do this? Assuming that we want a property that returns all the child objects for each object, we could use lazy instantiation of the property's value.
For the Library object we'll insert a Books property and a books private variable(which will store the actual value), like this:
//the private variable which will store the collection of books
private BookCollection books;
public BookCollection Books
{
get
{
//check to see if a value has been assigned to the books variable
// if not - set the value
if(books == null)
{
books = SetTheBooksCollectionMethod();
}
return books;
}
}
This way, the collection properties will only be populated on demand, sidestepping the recursive instantiation. So if we want to instantiate the library to retrieve it's address, it will not lead to instantiation of over a million related objects.
Luckily I'm one of those people that uses something thats called “leave” from time to time.
I've put in some leave for tomorrow so I'm of to the Drakensberg until Monday...
I wrote a tutorial on the subject which was published on SaDeveloper.
It can be viewed at http://www.sadeveloper.net/viewarticle.aspx?articleID=155.
We were writing a ton of regular expressions, which was becoming a bit difficult to understand and support, so this really helped us out to manipulate markup.
I've struggled with VSS projects before, where I had to remove them in the end.
It works much better than trying to fix the existing DB/Solution configuration.
Here's a link to instructions on how to remove projects from source safe.
A problem with ADSL is that we are assigned dynamic IP's. This means that you can't host a mail-server on it, or even a small web server from home.
If you subscribe to an ADSL line you have to pay Telkom the monthly rate for the line and you have to pay an ISP (probably Telkom too) a monthly fee.
I don't know about you, but I feel that I should be able to host services at home if I pay roughly R1k per month for an internet connection.
I did a little research and I found a link to http://www.dyndns.org. At our offices we have a zyxel adsl router, which can be configured with a dyndns username and password. This means that you can set up an account for your domain name at dyndns and you router will broadcast it's current IP to DynDns at intevals. When your IP changes it will be changed in 5 different dns servers across the world, and from there it will broadcast your new IP.
Maybe everybody knows it already, but it's the first time that I've seen it.
http://www.howstuffworks.com/
Is this what the security seminar's going to be about?
http://science.howstuffworks.com/lock-picking.htm
I read a real interesting aricle about this subject a while go, I'm not sure if it was this month's issue or last month's.
Nanotechnology is mainly about building stuff from a molecular level upwards.
To do this you need something that's called a NanoFactory, a factory that will construct objects from a molecular level. It can work similarly to a modern assembly factory, only on a much smaller scale.
Just imagine. If we could have nanofactories that build other nanofactories. You'll go onto the web (however it has evolved by then), download the formula (code) for building a certain nanofactory, this nanofactory builds other nanofactories and in the end, you build your new wristwatch - or whatever.
Adds a whole new dimension to being a developer :)
http://www.foresight.org/
I know a lot of web developers and developers that have to code web applications from time to time. The funny thing is, all of these developers hate coding client-side javascript - I would know, I hate it too sometimes.
I'm not just talking about client-side validation - this is a must according to me. I'm talking about UI's that operate in their own framework. This will include stuff like functions to launch certain content in formatted pop-ups - without needing to understand the plumbing of the code. Also needed is dragging functionality for these pop-ups, scrolling capabilities for the pop-ups, etc. And rich functionality like this needs to be downloaded, so to try and avoid huge downloads, a download on demand model can be implemented.
A UI like this definitely gives you an edge in the market. It's easier to demo your tool to potential customers, people are rarely impressed by a demo if you have to keep telling them how cool the product is. It's sad but true, but people are more impressed by a product with a nice (and easy to use) look than a product with excellent functionality.
The problem with coding these nice interfaces is that nobody wants to specialize in it. Developers tend to think of Javascript and client side coding as grunt work. A designer designs the look and feel, but a developer must still make it work - due to a fact that most designers' Javascript knowledge is extremely limited.
Complicated Javascript takes ages to code, due to a a few factors:
- The debugging is horrible - to date I haven't encountered a decent debugger for it. For example, one of the rich web apps that I had to write references around 10 different separate .js files. When an error is encountered with the functions in these referenced files, IE just notifies you of the line it occurred in the file - but not the file it occurred in. To make matters worse, these files aren't all referenced from the start. The UI works with a download on demand model, so that needs to be tracked too.
- An unexpected limitation always curve balls your master plan. Even if you always provide a POC for the UI before starting to code, some limitation always hinders the development. Most of the times a workaround can be found, but this invariably takes a lot of time.
- The stabilization period takes much longer, due to the fact that a lot of user acceptance testing must be done on the UI.
I agree that it's real important to have an intuitive and well designed UI. The problem is that it takes much too long to implement and it limits the available time to spend on the server functionality.
An obvious solution is to get somebody that specializes in UI building, so that the “real” developers can focus on what they want to do. But where to find such a person? I've never came across somebody that specializes in front-end javascript coding.
Then there is another solution - The smart client application model. The smart client approach gives you both from both worlds. It allows you to provide a rich UI, and even allows the user to work offline.
It can also be kept up to date by use of the .Net Application Updater block. This alleviates the problem of administration and versioning of the product.
This doesn't mean that smart clients will replace web applications. Web applications are still great for apps that doesn't require rich UI's and it's platform independent.
But I'm really excited about it, this may mean that we'll have to struggle less and less with web UI coding, and focus more on “real” coding.
I wanted to include functionality to upload a markup file (html/aspx) in a web application of mine. The trick was that I needed to upload all the referenced images too.
My first approach was to try and dynamically create input objects of type “file” on the client side, populating it with the path to the referenced images (for the images residing on the local machine) and then submitting a form to the server.
The problem with this approach was a limitation (by design) on the input type=”file” objects. Due to security reasons the value property of these objects area read only. Thus I couldn't set the value property on the dynamically created file objects, before posting the form back to the server.
I found a solution to my problem in using the xmlHttp technology. XmlHttp technology allows the browser to communicate with the server in the background. You can also send binary data to the server via xmlHttp.
So I just looped through the image collection on the client side, read their contents with an adodb.stream and published the contents to the server via XmlHttp. Works like a charm!!
I got the idea on this site. My solution was a bit more complicated in the end, but I don't want to bore you with the details!
I hate mixing server side code into my javascript code. It's messy and it doesn't allow me to store my javscript in separate .js files.
I had to get access to certain querystring parameters from my client side code, so I decided to write a reusable javascript object to access the whole querystring collection.
//this is to store the key value pairs of the querystring
function qsObject(){
this.objects = new Array();
this.add = _add;
this.remove =_remove;
this.item = _item;
this.populateCollection =_populateCollection;
this.setRawString = _setRawString;
this.rawString ="";
this.setRawString();
this.populateCollection();
// to add items to the array
function _add(obj){
this.objects[this.objects.length] = obj;
}
//to remove items from the array
function _remove(index){
this.objects.splice(index, 1);
}
//gets a reference to an item object
function _item(searchKey){
searchKey = new String(searchKey);
searchKey = searchKey.toLowerCase();
for(i=0;i<this.objects.length;i++){
//the current key in the coll
var key = this.objects[i].key;
key = new String(key);
key = key.toLowerCase();
if(key == searchKey){
return this.objects[i];
}
}
}
function _setRawString(){
//Create regular expression object to retrieve the qs part
// Used regex 'cause the search property on the location object includes the bookmark stuff
var qsReg = new RegExp("[?][^#]*","i");
hRef = unescape( window.location.href);
var qsMatch = hRef.match(qsReg);
//removes the question mark from the url
qsMatch = new String(qsMatch);
qsMatch = qsMatch.substr(1, qsMatch.length -1);
this.rawString = qsMatch;
}
//takes a string and populates the array with the key/value pairs
function _populateCollection(rawString){
this.rawString = new String(this.rawString);
var rootArr = this.rawString.split("&");
for(i=0;i<rootArr.length;i++){
var tempArr = rootArr[i].split("=");
if(tempArr.length ==2){
tempArr[0] = unescape(tempArr[0]);
tempArr[1] = unescape(tempArr[1]);
this.add(new qsValue(tempArr[0], tempArr[1]));
}
}
}
function qsValue(key, value){
this.key = key;
this.value=value;
}
} //example of using the object
var qs= new qsObject();
var idObj= qs.item("id");
alert(idObj.key + " == " + idObj.value);