Default Constructor vs. Empty Constructor

December 16th, 2006

While coding away new classes for your C++ project, do you have the habit of just dropping in a contructor definition, just in case you may in the future need to do some initialization at construction? A while ago, I had wondered if there would be any difference at compile time between having an empty constructor and having no constructor at all (and thus using the default constructor). I did a quick investigation by writing a simple test application and looking at the disassembly. It turned out that there is actually a difference (in a debug build). Read the rest of this entry »


Rendering N-sided Polygons with DHTML

November 28th, 2006


With this technique, convex polygons with any number of sides can be rendered, with a solid color or a background image as the fill. Click here or the image below to launch the demo (opens in a pop-up window).

DHTML Polygon Rendering Demo

You can probably figure it out on your own by playing with the checkboxes at the lower left corner of the pop-up, but read on to find out how it all works. Read the rest of this entry »


browsersize.com

November 18th, 2006

A simple website that I had put together a while ago, that harbors two simple tools that web designers may find useful. The main site shows you decently current statistics on different screen resolutions that web surfers have nowadays. You could use that as a starting point for deciding on the dimensions for a non-fluid website layout.

browsersize.com

setmy.browsersize.com allows you to set your browser size to any desktop resolution without the need for extra add-ons/extensions. This is useful for seeing how users with different desktop resolutions will be viewing your website. whatsmy.browsersize.com tells you your current desktop resolution and browser size along with all the installed popular plug-ins (with links to download sites for missing ones).


Using Fewer Images

August 27th, 2006

Image rollovers are usually composed of two individual images; one for the default state and one for when the mouse is hovered over the image or link. However, it bears some advantages to use a single image by taking advantage of CSS background image offsets. Read the rest of this entry »


Opt for Pre-incrementing Iterators

August 26th, 2006

There’s a slight performance advantage in using pre-increment operators versus post-increment operators. In setting up loops that use iterators, you should opt for using pre-increments:

for (list<string>::const_iterator it = tokens.begin();
    it != tokens.end();
    ++it) { // Don't use it++
    ...
}

The reason comes to light when you think about how both operators would typically be implemented. Read the rest of this entry »


PHP-style Serialization of JavaScript Objects

July 30th, 2006

Heavily-scripted data entry forms that expand on-the-fly as the user enters new data make life easier for the user. However, it can be hell for a developer to devise a method for the representation and submission of data with arbitrary length and depth.

A logical thing to do seems to be to take an object-oriented approach to represent all client-side data as one or multiple JavaScript objects. The objects themselves could be arrays or objects with child objects and so on. Of course the objects need to be serialized in some way before they’re posted back. Now, if you’re using PHP at the back-end, you might make use one of the multitude of JSON implementations out there for posting back the data in JSON format and converting the data back to PHP objects (assuming that you want to end up with PHP objects.) JSON is pretty much native to JavaScript (clever use of the toSource method may cut it in most cases) but you need extra PHP code for deserialization.

If you want to take the opposite approach and use PHP-native serialization, then the following function will convert any complex JavaScript object into PHP-serialized string which can be converted back into PHP objects with a single call to the deserialize PHP function. Read the rest of this entry »


Don’t Hand-count Characters

July 15th, 2006

A common mistake that most programmers do is to hard-code hand-counted lengths of string literals. For example:

if (!strncmp(str, "MAGIC_PREFIX_", 13)) {
    ...
}

Even if the string literal "MAGIC_PREFIX_" is not due to change in a life time, it makes the code more prone to human error and harder to read when the length of the string is hand-counted and hard-coded as a separate entity (13 in this case). Read the rest of this entry »


Spelling “Quake” With The Quake Logo

July 10th, 2006

I created this GIF animation back in 1997, when I used to play Quake 25 hours a day. I recall the tedious process of manual tweening to create the individual frames (by calculating the angle and position differences and dividing them by the number of frames) using Freehand. I would probably use Flash if I were to do it today…

Quake Anim


Finding Out Class Names of JavaScript Objects

July 10th, 2006

JavaScript lacks a built-in function for getting the exact class names of object instances. The typeof operator just returns “object” for instances of both Object and Array, as well as user-defined classes. The following example illustrates this:

function MyClassA() {
}

var obj = new Object();
var arr = new Array();
var myobj = new MyClassA();

document.write(typeof(obj) + "<br />");
document.write(typeof(arr) + "<br />");
document.write(typeof(myobj) + "<br />");

The output of the code above, with your browser is:

Read the rest of this entry »


Win-Res-Q 1.0 – Lost Window Rescue

July 10th, 2006

Win-Res-Q (read “win rescue”) is a simple utility that restores (shows) hidden windows. It can be used for bringing back your “lost” applications after their taskbar icons disappear following Explorer crashes that abundantly occur on Windows 98. It’s also useful for exposing strange, hidden windows lurking around your desktop. Read the rest of this entry »