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.

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!

LINQ to XML – What I’ve been missing

Ok. You may laugh. I’ve just today used LINQ for the first time to parse an XML file, and I’m seriously blown away at how easy it was. I’m a little embarrassed, since LINQ has been available since .NET 3.5 was released around November 2007.

If you are like I was, (LINQ-less!!), I’ll give a brief introduction here. LINQ (Language INtegrated Query), is a component that adds native data querying capabilities to .NET languages. It can be used to read, parse and write XML files (and also SQL, which I may cover in a future post). Take a look at the example below to see how easy it is to use this technique to read data from an XML file.

Reading data from an XML file is a very common scenario. I always used .ini file as configuration files for any applications I wrote, but .NET doesn’t provide any built in support for .ini, and hence wants you to use XML.

Consider the following XML file:

In order to read this using LINQ to XML, you need to ensure you have specifed the correct header files:


using System.Linq;
using System.Xml.Linq;

Now for the easy part, here’s the code to read data from the XML file, and print out the values to the console:


XDocument xmlDoc = XDocument.Load(@"example.xml");
var servers = from server in xmlDoc.Descendants("server")
select new
{
     Name = server.Element("name").Value,
     IP = server.Element("ip").Value,
     Owner = server.Element("owner").Value,
};


foreach (var server in servers)
{
     Console.WriteLine("Server Name: " + server.Name);
     Console.WriteLine("Server IP: " + server.IP);
     Console.WriteLine("Server Owner: " + server.Owner);
}

Easy huh? The line beginning with ‘var servers=…‘ may look strange to you if you’ve never seen it before, (it did to me). This is an anonymous type declaration. If you’ve never heard of anonymous types in C#, MSDN has some great documentation here.

Happy coding.