Friday, October 31, 2008

New Gmail Mobile v2.0

The new Gmail mobile client is avialable, you can download it by visiting on your phone.

Monday, October 27, 2008

New .Net Logo

Following NotAtPDC
I heard there's a new .Net logo.

Weekly Source Code: ASP.Net AJAX UpdatePanel And UpdateProgress

On the VCC website that I wrote, there is a Sermons web page You will notice that when you select a month it displays a progress animation image at the bottom of the drop down box and within seconds the grid refreshs with the new sermons without reloading the entire web page... This is a good example of an AJAX call that happens when you select the drop down box but did you know that I didn't write any Javascript code to get it working?

To accomplish this I used ASP.Net AJAX in MS Visual Studio.Net 2008 with no Javascript or C# coding. ASP.Net AJAX is part of ASP.Net 3.5 but as a seprate download for ASP.Net 2.0 (MS Visual Studio.Net 2005).

The magic is done by the control with the drop down box and the grid getting wrapped inside the tag of ... the drop down box is a control and the grid is a control, so nothing special about the drop down box or the grid.

Also within the is the control that executes when the is busy updating the page, this gives feedback to the user that something is happening.

You must also add the control since all ASP.Net AJAX pages requires this control.

Thats it! Nothing else required, no JavaScript code... no coding at all!

When the drop down box fire an event when the user chooses a new item the update panel handles the event a-synchronously , fetching the new updated grid and displaying it all the while the update progress controls indicates to the user the busy image.

ASP.Net AJAX makes this easy for you, as a developer since it takes care of all the back-end stuff for you so it generates and handles the JavaScript code etc without you even knowing about it.

Friday, October 24, 2008

I'm On Twitter

Everybody thesedays are on Twitter so way not me?! Go visit

Thursday, October 23, 2008

Next.... Windows 7

The next MS Windows version will be called Windows 7

I believe, we all hope that this time MS will do a proper job than what they did with Windows Vista or allow us to always downgrade back to Windows XP :-)

Tuesday, October 21, 2008

Weekly Source Code: My AJAX Library

Back when AJAX first came out there wasn't any libraries - no ASP.Net AJAX etc. I was mainly doing classic ASP with VBScript development (yes I know - that sucks!)

Most AJAX books and samples demonstrated using the XMLHttpRequest object are for making AJAX calls but the main problem was compatibility between the different web browsers - IE vs Firefox vs Safari vs Opera.

So I wrote my own AJAX library, I mainly used it for validation and later to pull customer information into a HTML form if the customer already placed an order.

To use it:

Setup 1: Include the JavaScript file into your HTML page.

Setup 2: Call AjaxValidate function, this function has 3 parameters:
  • psWebPage: The back-end server side page to call.
  • psCode: Code that identifies the request, if you send more than one request to a back-end server side pagethen this can be used to identify the request so that the page handles different request. You can leave this blank if your page handles only 1 request.
  • psValue: The request value.
Setup 3: When the result comes back it will call the setOutput JavaScript function that has 3 parameters:
  • sWebPage: The back-end server side page that was called.
  • sCode: The code sent to AjaxValidate function your JavaScript can process the request.
  • sResponseText: The response from the AJAX call. This can be HTML, plain text or even JSON.
With the AJAX frameworks of today my library don't have much of a meaning since you can do alot of advance AJAX functionality.

More about AJAX in the next Weekly Source Code.

C# From a Java Developer's Perspective

When I was moving from years of experience in Java to my first C# project with no knowledge of the framework or even the language I found this artical. It was very helpful to make the conversion from Java to the C# language especially since there's some differences that can bite you, when moving between them (like what I currently do on a daily basis).

Friday, October 17, 2008

What is Type Inference?

You might ask, "Lennie, in your previous blog about how bad variants are... what is type inference? Isn't it also a variant...?." The answer is yes and no, type inference comes from dynamic languages (remember Ruby, Python? yes those ladies!) and was added to the C# 3.0
language as part of the "var" keyword.

Basically what it does is that when you declare a variable with the "var" keyword its determined that the type of the variable from the data you assign to it, e.g.:

var firstName = "Lennie De Villiers"; // Hello, I'm a String type!
var age = 12; // yebo, I'm an int type!

but with type inference you can't change the type of the variable after its been assigned, e.g:

var firstName = 12; // Ooops, invalid!

With raw variants you can change the type of a variable all the time, like in the previous blog entry the MyNumber variable is a true variant since it is passed in as a number (probably a double) and then changed into a String type.

Microsoft added the "var" keyword since with LINQ queries the type of a variable is unknown but only know after execution.

Be careful of type inference since they're also bad and only should be used with LINQ queries when you execute them but afterwards (very important!) convert them to a proper known type else since you've the same problem where a developer looking at your code can't determine
the type of a variable - same problem with raw / true variants.

So to recap, type inference:
  • Infer the type from the value assigned to it;
  • Can't change the type after first assignment (its forever a string, int etc)
  • Bad coding practice since you still don't know the type of the variable.
True variants:
  • Bad coding practice since you still don't know the type of the variable.
  • Can change their type all the time, first a String then an int, then your PoolBoy class etc.
My golden run:
  • Type inference only when executing LINQ queries but afterwards convert to a proper type.
  • No variants, they're just bad!

Thursday, October 16, 2008

Variant Types Are Bad

I'm busy converting to Java code but having problems since the original coder used variant type e.g. you don't know the type of the variables: MyNumber, DecimalPlace, Count etc looking at the variable declaration but only once you assign a value to it, it also doesn't use type inference (the var keyword in C#) meaning you can assign a string to the variable then later an integer... bad boy! So this makes conversions hard. Not just
that but what about maintenance?! If this code is used in a production environment what about the poor junior that must maintain it a year / decade from now (if VBA code is still running in 2020).

Tuesday, October 14, 2008

C++ 0x Compiler

C++ 0x is the next version of C++ with some added language features, libraries etc. The C++ standard committee is planning to have it released around the end of the decade. The "0x" is because the year of release is unknown.

The GCC 4.3+ compiler has support for some of the C++ 0x features, also some of the features was released as part of TR1 in MS Visual C++.Net 2008. I will blog about TR1 and C++ 0x features in the future.

Monday, October 13, 2008

Weekly Code: Find Duplicates in SQL

Sometimes you need to check if there's duplicated rows in a SQL table, for this you can use the query:

SELECT field, COUNT(field) AS NumOccurrences
FROM checkdup
GROUP BY field
HAVING (COUNT(field) > 1)
  • checkdup: This is the table name to check.
  • field: This is the field name to check.
This will return 2x columns, the first column is the duplicated data and second column is a count of how many times its duplicated.

Friday, October 10, 2008

RGB Color Calculator

If you require the hex (hexidecimal) value of a RGB (Red, Green, Blue) color combination then here is one you can use color calculator.

Thursday, October 9, 2008

Programming Language Wars

Normally I don’t agree or join language wars but: I programmed for 4 years in Java, VB ( and VB 6), C++ and C#, PHP etc. The fact is that each language have advantages and disavandages, yes the .Net framework is more solid than the Java lib but Java is cross-platform to portable devices etc… VB is easy to code since it hide you from the details of the framework where with C# its more “C++ system style” of coding where its not so abstract like VB…. the point that i’m making is that anyone can go on how bad one language is over another etc but hey, be glad that we don’t live in the days of Assembler since that was bad! A language is a tool, use the tool that you prefer (its your own personal opnion) and have knowledge in, for example: I will not go write a complete website in a week using Ruby on Rails since I don’t know it but it doesn’t mean its a bad tool. Use the tool that suite the task at hand and what you prefer… damm if you want to write a website in Lisp then go for it!

When it come to language wars, I don't care... I will even use Fortran if I must / want too!

On the job market side you might want to consider your options since that is a total different story to use the language that your employer want etc.

Tuesday, October 7, 2008

Escaping Special Characters In C#

When you add records into a database you need to escape special characters like the single quote (') else your insert statement might fail.

After searching hard I found that C# does provide a method that does escaping by providing a string parameter and returning the escaped string, the surprise is that its not part of the String class but actually inside the SecurityElement class thats part of the System.Security namespace... find the Escape method!Now I wonder... why did Microsoft add it to that namespace? :-( grrr....

Monday, October 6, 2008

Mono 2.0 Released!

Mono 2.0 as been released! Get it here.

Saturday, October 4, 2008

Weekly Code: C# ForEach Method In C++

This week's source code is a C++ version of C#'s ForEach method available here The ForEach method isn't the foreach statement, C#'s ForEach method you pass a delegate to a method and it will execute the method for every element in the collection.

The C++ version works similar where you pass it the vector collection and a function pointer, it will then execute the function passing in the vector. The function can then perform any action on the vector, in this case sample it change the values to 1.

Function pointers are powerful in C++ but yes they've a very error-prone ugly syntax.

Friday, October 3, 2008

Cool Tool: Time Calculator

Ever need to add/substract or even devide time? Use Scott Severance's online Time Calculator

A good tool when your calculating your monthly time sheet :-)

Java Gotcha: mkdir vs mkdirs

In Java's File class there is the mkdir and mkdirs methods but note that both of them work very differently.
  • mkdir: Creates the directory named by this abstract pathname.
  • mkdirs: Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories
So if you want to create a directory like /reports/customer with mkdir method it will be unable to create the /reports directory if it doesn't already exist.

This is one of those Java Gotchas that can waste alot of debugging time.

Wednesday, October 1, 2008

Compile Objective C With MinGW

Objective C is a special dialect of C that allows you to code for the Mac OS X and the iPhone.

It's very interesting to know that MinGW contains the GCC compiler that can compile Objective C code.

Using MinGW with MSYS I got to compile and run the following sample Hello World program saved as Hello.m:

#import <stdio.h>

int main( int argc, const char *argv[] )
printf( "hello world\n" );
return 0;

All that you do is open MSYS and run the GCC compiler.