What to learn next?

I’ve been a bit all over the place recently in terms of what to learn next. The main languages I’m proficient in at the moment are C#, and web programming languages like PHP. (Aside: If I hear one more person refer to HTML as a programming language I may get angry). The thing about the software industry is that something you spend a long time mastering may be obsolete in 5 years. If you’re not continuously learning, you can fall behind very fast.

Over the next 6 months to 1 year, I’ve decided to focus on certain technologies/areas in an effort to become someway proficient in them.

I’ve decided on:

  • C++ – The expert consensus is that this will not be replaced in the next 50 years.
  • Mobile Development – But I’m unsure of which platform. iOS development interests me as I own an iPhone, but it has the extra added learning curve of Objective C, of which I have little experience. I’m thinking Android or Windows Phone 7 (should it be accepted by the masses), since I’m familiar with both Java and C#.
  • ‘Newer’ Microsoft technologies such as Silverlight, WPF etc. from the last few years that I haven’t looked at.

I feel if I apply myself I can certainly become proficient in the above areas in less than a year. By ‘proficient’ I mean be able to develop applications from the ground up as I can do in C# at the moment, not ‘master’. I’m fully aware that languages like C++ take thousands of hours to learn and many years of hands on experience to fully master.

No doubt I’ll be posting here of my experiences learning each.

C# – Using Bing’s Translation Web Service

Microsoft’s Bing Translator provides a translation web service which can be called via C#. In this post I’ll outline the steps to use this web service, and create a simple application to perform translations.

First, you’ll need to create a valid application ID for your application. This is required in order to be able to call the web service. Head over to Bing’s Developer Centre and sign in with your Windows Live ID. Follow the steps to create a new ID for your application, it’s a simple process and shouldn’t take you any more than 2 minutes.

Next, create a new project in Visual Studio, (I’ve created a simple Windows forms application to demonstrate this, but you could just as easily create a simple console application). You’ll need to add a service reference to your application either way. Do this by right-clicking on your solution and selecting ‘Add Service Reference’. Under ‘Address’, add this:

http://api.microsofttranslator.com/V1/SOAP.svc

Under ‘namespace’, be sure to enter a descriptive name for the service reference. Now, for the code to perform translations (You’ll need to add in the application ID you created earlier in order for this to work):

// Translating from English to German

string textToTranslate = "Hello, world";
string sourceLanguage = "en";
string targetLanguage = "de"
string translatedText = "";

try
{
BingTranslatorService.LanguageServiceClient client = new BingTranslatorService.LanguageServiceClient();
translatedText = client.Translate("Your App ID", textToTranslate, sourceLanguage, targetLanguage);
MessageBox.Show(translatedText);
}
catch (Exception ex)
{
MessageBox.Show("An error has occurred: " + ex.ToString(), "Error");
}

‘BingTranslatorService’ above is whatever you called the service reference added earlier. I’ve created this sample application to show how easy it is to create a simple translation application:

Simple Translation Application

Download the full source code, here. You’ll need to add in your application ID in order for this to work properly.

Localization of C# Applications – Short Introduction

If you plan on releasing your C# application in non-English speaking markets, you will obviously want the UI to display localized strings. When developing applications using .NET, it’s relatively simple to achieve this. In this post, I’ll outline the steps involved in localizing a simple C# application.

.NET applications store string resources in .resx files. These are XML format, with the main advantage being they are human readable and can be opened in any text editor, unlike resource DLL files for example. The only item not human readable in a .resx file, may be an embedded object, like a Bitmap file for example.

Start off by creating a simple Windows Forms application from Visual Studio, it will create an initial form for us to work on. ┬áSelect the form and on the ‘Properties’ dialog look for the ‘Localizable’ property and set it to ‘true’. You may also notice the ‘Language’ property, leave this set to ‘Default’ for the moment.

Next, add a button to the form and add some text to it, something simple, for example:

Simple Localizable Form

If you take a look under your form in ‘Solution Explorer’, you will notice a .resx file has been created. It will be named FormName.resx, open this up and search for the string on your button and you will see how it is stored. Now to add the equivalent German strings (or any other language you fancy!).

Recall the forms ‘Language’ property mentioned earlier, you will find it under ‘Properties’ when you’ve got the form selected. In the dropdown, change the value to ‘German’. You will not notice any visible changes, but you can now edit the strings on the form to represent the German equivalents. Do this for as many languages as you want to. Once you’ve done this, take a look under your form in ‘Solution Explorer’, you will notice that a new .resx file has been added automatically, FormName.de.resx. This will contain your German strings. You should note here that you can also change the layout of the form to include any required changes, in the event some strings are longer in certain languages, e.g. Greek.

Now when your application is run on a German operating system, the strings displayed will be automatically taken from FormName.de.resx, rather than FormName.resx.

A note about locale selection

The UI language used in Windows is a function of the CurrentUICulture setting. In order to see the German strings actually display, you would need to install a German language pack, and change your regional settings, or we could just set our locale programmatically in our application.

In order to test your German strings display correctly, first add the following imports:

using System.Globalization;
using System.Threading;

Then add the following code to your form initialization function, (before InitializeComponent()):

// Sets the UI culture to German (Germany).
Thread.CurrentThread.CurrentUICulture = new CultureInfo("de");

This will make our application believe it’s running on a German locale. Now run your application, you should see your German strings displayed:

German Strings Displayed

This post outlined the very basics of localizing .NET applications. In future posts, I plan on expanding this a bit to advanced topics such as avoiding common internationalization issues.

Retrieve settings from COM+ components via C#

Recently, I had a requirement to be able to retrieve settings information from a number of COM+ components running on a server, such as the Constructor String etc. The idea behind this was to give us a snapshot of a servers configuration, and also allow easy comparisons between different servers in the event of issues. This is tedious and time consuming to do manually, especially if you’ve got a large number of components within each COM+ application, so I resolved to write a small C# program to do this for me and write the data to a file.

COM+ provides an administration object model that exposes all of the functionality of the Component Services administrative tool, so by adding a reference to the necessary library, you can achieve anything you can do through the graphical administrative tool, programmatically. To get started, you’ll need to add a reference to the necessary library – ‘COM + 1.0 Admin Type Library’. This can be found under the ‘COM’ tab when you go to add a reference to your project in Visual Studio.

You’ll need to add the following import also:


using COMAdmin;

First, we’ll need to create an Object to store the catalog of COM+ components installed on the machine. Here’s the code to create this catalog, and also retrieve a list of all the COM+ applications it contains:


COMAdminCatalog catalog;
COMAdminCatalogCollection applications;

// Get the catalog
catalog = new COMAdminCatalog();

// Get the list of all COM+ applications contained within this catalog
applications = (COMAdminCatalogCollection)catalog.GetCollection("Applications");
applications.Populate();

Now we have an Object above, ‘applications’, which contains all the data regarding what COM+ applications are installed on this machine. To go a little deeper, and see which components each application contains, it’s just as easy:


foreach (COMAdminCatalogObject application in applications)
{
COMAdminCatalogCollection components;
components = (COMAdminCatalogCollection)
components = (COMAdminCatalogCollection)applications.GetCollection ("Components", Application.Key);
components.Populate();

foreach (COMAdminCatalogObject component in components)
{
Console.WriteLine("Component: " + component.Name);
}
}

The above code shows you how to get a list of COM+ applications and their components, but what about retrieving or setting the values of specific component settings like the Constructor String of a component?

Here’s how:


// Set the value of a constructor string
component.set_Value("ConstructorString", "127.0.0.1");
// Get the value of a constructor string
component.get_Value("ConstructorString"));

That’s a quick overview, I leave it as an exercise to the reader to explore the other functionality of the ‘COMAdmin’ library, but if you just need to retrieve values of settings from specific components, the above will get you started.

As per normal, MSDN has some great documentation here.

iPhone Application Development

I’m currently learning the application development process for the iPhone OS. A book that caught my eye recently while browsing Amazon was “Building iPhone Apps with HTML, CSS, and JavaScript: Making App Store Apps Without Objective-C or Cocoa” by Jonathan Stark. Since I don’t own a Mac currently, and don’t really feel I’d get any value from learning Objective-C, this sounded like the perfect place to start.

First off, I think the title is perhaps a little misleading. The author advocates building iPhone applications as web applications, rather than native iPhone OS applications. This has all the obvious advantages of any web application, (faster development cycles, real-time bug fixes etc.), but has a few unique advantages from the iPhone developers perspective. First off, you dont need to register (and pay!) to become an Apple developer. Secondly, your web application will not need to through Apple’s approval process as you will not need to submit it to the App Store in order to deploy it to your users.

Obviously, there are also some serious challenges to overcome if you make your application web based, with the main one being you will need to implement your own payment system if you wish to charge for your application.

The book contains many good tips for optimizing your web based application for the iPhone OS specifically. In Chapter 6, there’s also information on how to convert your web based application to a native iPhone app, using PhoneGap, although you do need a Mac to do this. Then your application will have to go through the Apple approval process in order to be made available on the App Store. It may be refused – but while you work on this and make any modifications necessary etc, your web based version is still available.

I’ve found this book a great starting point, now all I need to do is get the time to complete my app! I’ll be posting a release note here once I do, so stay tuned…

12 Steps to Better Code

The ‘Joel Test’ has been around a long time (Joel Spolsky originally wrote the article in 2000), but having only discovered Joel’s blog in the last year, and reading every article back this far, I think this particular post is amazing.

For those not familiar, the ‘Joel Test’ is Joel Spolsky’s 12 simple steps to better code and a better software development process. Lately, I’ve been trying to adhere to these steps in some personal projects, and some development projects I’m involved in at my day job.

Here are the questions to ask yourself when rating the software team you work in:

1. Do you use source control?
2. Can you make a build in one step?
3. Do you make daily builds?
4. Do you have a bug database?
5. Do you fix bugs before writing new code?
6. Do you have an up-to-date schedule?
7. Do you have a spec?
8. Do programmers have quiet working conditions?
9. Do you use the best tools money can buy?
10. Do you have testers?
11. Do new candidates write code during their interview?
12. Do you do hallway usability testing?

Read Joel’s full article here, I think it’s great!