Monday, February 26, 2007

Valid characters for ID and NAME attributes

The W3C defines ID and NAME requirement as -

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

So colons is a valid character used inside an ID.

Why do I mention this? We want to find a way to specify unique ID names, even we do not know what the outside HTML will look like. Say we are building a component containing some HTMLs. This component is going to be embeded into other pages. We may consider add a prefix for example

wasterpack::id_error

is a valid ID.

Sunday, February 25, 2007

Tricking Microsoft Script Editor to edit PHP files

Microsoft Script Editor is a great tool to edit HTML pages and debug client javascripts. However, it only recognize file with several extensions, and show unformatted pages to .php and .tpl files. It seems that Microsoft does not want you to use this tool to edit PHP and template files. Many people want this feature and have to change the file extension back and forth. Needlessly to say, this is a tedious work and prone to errors.
Today I found that you can hardlink a file under Windows XP, just like the command "ln" on UNIX. A hard linked file looks like a regular file, but points to another file. If you change the contents of one file, the another changes as well. Let's say that we need to edit file index.php, we can create a hardlink file called index.html. Now every changes made to index.html go into index.php. In this way we can edit file contents in Frontpage or Script Editor, but test it with index.php.

The command to create a hardlink file is
fsutil hardlink create index.html index.php

Note that the new file name is before the old file name.

Thursday, February 15, 2007

Ternary Operator - multiple branches

I use ternary operator ?: in C++ a lot. Unfortunately I never went further to use it on multiple branches. Today I found that it is legal to write

char* str = size < 10 ? "small" :
size < 20 ? "medium" :
size < 30? "large" :
"extra large";

It is equivalent as:

if ( size < 10 )
str = "small";
else if (size <20)
str = "medium";
else if (size < 30)
str = "large";
else
str = "extra large";

Nicer, uuuhhh

Sunday, February 11, 2007

ATL Server is much faster than Script

Today I spent about six hours rewriting an ASP page with C++. The existing page was too slow - it took a whoopee 10 seconds to load. It is an ASP page written in VBScript. A lot of database code inside. Theoretically we could optimize the database queries to make it faster; but I decided to rewrite in C++ instead.

It turns out much better result than I expected. I am a C++ programmer. C++ is a much better language in many tasks, but I never thought that it is also useful for creating a robust web application.

An ATL server project includes two parts - a SRF file and a web application DLL. This arrangement makes the separation of presentation (UI) and logic possible. I have not thought about this before; but I can also build logic blocks and UI blocks as well. The SRF syntax is a little bit limited; but it does support the include syntax which allows you to include a static HTML file or another SRF.