Recently, I’ve experimented in breaking up the text in my blog entries with pictures vaguely relating to the content. I must confess that when looking back at them I’ve found the effect to be quite pleasing (particularly Old JamesWiseman.com).

I’ve always intended this to be a notebook for myself, but am always looking for ways to improve my technical writing, and enhance the way I convey and present information. Technical writing is an important skill for any software developer, and the manner you writeinformation is often essential to convey meaning.Blog Picture

For most of my career I have written technical specifications, designed to state the facts as concisely as possible, but writing blog articles like this is very different experience for me.

For a start, the tone-of-voice is different, you have to be conversational and friendly. You also have to assume that people are reading this in their own time, and not time that is being paid for by their company. This places the onus on you to  make things a more interesting, and less taxing on the brain.

I did some reading up , and I quite like some of the suggestions I found on How To Write A Blog Post, which include:

  • Create a snappy title – Not sure that I’ve really been doing this, so I might try more after this post.
  • Hook your readers with a great first paragraph – Good idea. Not sure the first paragraph above is a great hook, so maybe more work required!
  • Get into the nitty-gritty. Write detailed blog posts – Hmm, well, I always intended this to be a notebook so I’m maybe shirking this task. However, getting high traffic was never the motivation for this blog.
  • Wrap it up. Add some sort of conclusion.

And of course, I’ll add my own – Put Some Pictures In. I tend to do a Google image search on any words vaguely relating to the topic and then put some images that catch my eye into the post.

For the record, the Google searches I did here were “Blog Posts” and “Conclusion”.

,

When it boils down to it, is there any difference really?

Not according to Senior Systems Engineer, Steven W. Pavick. He was quoted as saying:

A fighter pilot is merely like a truck driver delivering a package to someone who doesn’t want it but they’re going to receive it anyway

That’s nice to know!

I’m almost afraid to write this in anticipation of the spam this might generate.

Like moths around a light bulb, so spam comments appear to have gravitated towards this post: Generate And Sort Lottery Numbers.

I could surmise that suddenly the world has become interested in this blog and that its attracting much more interest, and a lowly article about using C++ code to generate an array of national lottery numbers is somehow of massive interest to the world. I would, however, be gravely mistaken in this assumption.

I suspect, however, the culprit is the word ‘Lottery’, hence my apprehension with regard to this post.

I mean, look:

My Blog Smap Posts

And even as I speak, three more arrived on my WordPress dashboard. Good grief! In fact, that’s twenty more in the last hour.

One tenacious spam actually made it as far as the ‘Pending’ queue; I was almost tempted to approve it for sheer persistence.

Before I started blogging, I never even considered the prospect of blog comments as spam, but I suppose it makes perfect sense. There over ten million WordPress blogs out there with over 250,000,000 readers, so it’s an obvious target.

,

This is a fairly trivial problem, but I remember being struck at how the most obvious solution sometimes isn’t the best. It’s often worth thinking a little more into a problem, and not just blindly start coding the first solution you came across.

My university course comprised three years of study and one year of industry placement, conveniently sandwiched between years two and three.

Around Easter-time I responded to an advertisement in the local paper for a local company called Head Software International, whoHead Software International were looking to recruit ‘Junior Programmers.’ I responded in the vague hope that they would consider hiring an undergraduate for the position for one-year only.

Soon after this I got a response, and was invited for an interview. I don’t remember much about it, except I was asked to write some code (something every interviewee for a programming job should be required to do).

I do, however, remember one of the questions very well:

Write a program that generates a line of National Lottery number.

Bonus: Sort the numbers into order.

At the time, the British National Lottery had only one game. You picked six different numbers between 1 and 49, and you won varying amounts depending on how many came up in the draw.

“Easy-peasy,” I thought. So I promptly set about writing a program with the following features:

  1. Declare array of six integers.
  2. Loop through the array generating a random number for each element, and checking it against all the previous entries.
  3. Sort the array.

So, excusing variable declarations, your program in C++ (yes, C++) might look something like:

while (i<6)
{
    num = (rand() % 49) + 1;

    //check our number doesn't already exist
    for (j = 0; j < i; j++)
    {
        bExists = (lotteryNumbers[j] == num);
    }

    //add to the array
    if (!bExists)
    {
        lotteryNumbers[i] = num;
        i++;
    }
}

//now sort the array....

Although I did include an Insertion Sort algorithm, you’ll forgive me for not including it here. I was even tenacious enough to suggest using some of the in-built sorting capabilities within C++.

This all received a positive response. One of the interviewers commented – ‘No-one has ever coded Bubble Sort as part of that solution.’ (It was an Insertion Sort, but I still preened).

Anyhow, I got the job. Sometime later, a developer at the company explained to me a different approach  (which apparently no-one had ever come up with in the interview). This is what they suggested:

  1. Declare an array of 49 booleans.
  2. Initialise each element to false.
  3. Generate your random number (lets call it x)
  4. Check array[x] - Set it to true if false, and increment our counter.
  5. Repeat 3-4 until our counter is six.

So it might look something like:

bool lotteryNumbers[49];

for (i=0; i<49; i++)
{
    lotteryNumbers[i] = false;
}

while (j<6)
{
    num = (rand() % 49) + 1;
    if (!lotteryNumbers[num])
    {
        lotteryNumbers[num] = true;
        j++;
    }
}

The advantages of this are as follows:

  1. You remove the need to loop through all your existing array items to check for a number’s existence.
  2. You don’t have to sort, as it is presorted!

You do have the disadvantage in that every time you want to access the numbers you must loop through (up to) 49 array items. To solve this you can do a one-time transfer to a six-element byte array after the generation is complete.

,

This was brought to my attention today, and made for interesting reading:

Oracle Database 11g vs. Microsoft SQL Server 2008Oracle 11g

The report claims in its ‘Executive Summary’ that Oracle 11g holds a substantial advantage over SQL Server, and alleges the following high level points:

  • Oracle is faster for DBAs to perform administrative functions
  • Oracle has fewer steps for standards RDBMS tasks
  • Increased Oracle DBA productivity due to lower complexity and higher efficiency
  • Oracle has architectural and functional capabilities for backup and recovery beyond those offered by SQL Server
  • Oracle demonstrates significant time savings with regard to performance diagnostics and tuning

Later in the Rationale section, however is the following statement:

Oracle has sponsored the studies in response to a challenge made by Edison to Oracle claims that Oracle Database was significantly easier and thus less costly to manage than the other major database management systems.

Which, of course, makes me suspicious. Regardless of Edison’s so-called ‘challenge’, the report is still sponsored by Oracle (and published on their web site), and I would have been surprised if this came back in SQL Server’s favour.

Predictably, Microsoft has published a response denouncing these claims. It alleges the following: SQL Server 2008

  • The report has unverifiable metrics and inconsistent interpretation of results
  • The report is not based on ‘real-world; data
  • SQL Licensing Costs are cheaper
  • Oracle databases consistently suffer from more security vulnerabilities
  • Security patching not reflected in true cost of operating Oracle 11g

I’ll not pass comment, but thought it interesting to share!

,

Most C# (and C, C++, Java and JavaScript developers for that matter) will be aware of the default keyword and its usage in the switch statement:

switch (options)
{
    case 1:
        {
            //do something
            break;
        }
    default:
        {
            //do something
            break;
        }
}

But it also has an additional use in C# in conjunction with Generics and types. Each type in C# has a default value. Value Types have a default value of zero (false for boolean) and reference types have a default type of null We can try a simple example:

int i = default(int); //i is initialised to zero

And then try it in conjunction with Generics:

class DefaultTest<T>
{
    public DefaultTest()
    {
        System.Console.WriteLine("Default for '" + typeof(T) + "' is " + default(T));
    }
}

class Program 
{
    static void Main(string[] args)
    { 
        DefaultTest b = new DefaultTest();  //outputs 'false'
        DefaultTest i = new DefaultTest();  //outputs '0'
        DefaultTest s = new DefaultTest();  //outputs nothing
        DefaultTest S = new DefaultTest();  //outputs nothing
        DefaultTest d = new DefaultTest();  //outputs 0
    }
}

You can read some more on these in this article: http://en.csharp-online.net/Understanding_Generics—The_default_Keyword_in_Generic_Code

 

,

Here’s an idea of something to try when you’re trying to learn about C# and the .NET framework classes.

When using a type, why not include its namespace in your code as as well. For example:

//without namespace
OleDbConnection oleDbConnection = new OleDbConnection(connectionString);

//with namespace
System.Data.OleDb.OleDbConnection oleDbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

I’m not necessarily advocating this for use when writing production or live apps (it is a bit wordy, but i’m undecided about that at the moment), however when you’re hacking about and learning new stuff, it may be advantageous for your learning experience if you include the full namespace declaration; hopefully this will help you remember the association between libraries, namespaces and classes.

Just a thought. Take it or leave it…

, ,

I recently encountered a problem in getting 32-bit Windows COM components running on a 64-Bit Windows server. This surrounded the reading of registry entries and COM registration.

As it turns out, running in a .reg registry file, or registering a COM component on the server will invoke the default programs associated with these operations, namely, regedit.exe and regsvr32.exe. These default programs are filed under c:\Windows\system32. Nothing new, right? Wrong!

Do not be mislead by c:\windows\system32. On a 64-bit machine c:\windows\system32 contains 64-bit versions of regsvr32.exe and regedit.exe. The 32-bit versions that you want are in c:\windows\syswow64.

Sorry, let’s just clarify. The 32-bit versions are in the folder with ’64′ in the name, and the 64-bit versions are in the folder with ’32′ in the name.

Windows System FoldersErr. Ok. Just to be clear, I meant that, and as we would expect, 64-bit Windows defaults to to the 64-bit versions of these components.

So why call it System32? Well, I think a lot of legacy apps have this (ill-advisedly) hard-coded. Microsoft state that “64-bit system files are in the \Windows\system32 directory for compatibility reasons.” Wikipedia says much the same thing as well.

So what’s the difference? Well, these two programs basically add information to the registry; but we have two different ‘Views’ upon the registry,  predictably a 32-bit view, and 64-bit view. In the background these are just separate branches of a wider registry tree that is hidden from us.

So what of WOW64? Well, this stands for “Windows-On-Windows 64-Bit Emulation Environment”. In this instance, the ’64′ means that we are emulating Windows 32 bit on a 64 bit environment. Maybe a better name would have been W32OW64, but that’s harder to say than “WOW-Sixty-Four.”

When you run a 32-bit component on 64 bit Windows, it automatically runs in the WOW64 Emulation Environment. This isn’t clearly stated in the documentation; when I started out I was looking for a way to get the component to run in this environment before I suddenly realised it already was!

The component will access the 32-bit view of the registry, so as long as you have registered things correctly, you will be ok.

Microsoft has made available a page on Running 32 Bit Applications on a 64-Bit server. In addition this, there is a document outlining best practice guidelines for WOW64.

There’s more reading in the above on maximum addressable memory and such-like, but I’ll leave that to you.

, , , ,