The Big Bang Theory!

Category: Programming

When you do something worth doing, do it with a Bang! At any job that you do, there will always be good people, bad people and just people. Take a look at the guy next to you. Is that the person you want to be like?

It does not matter how insignificant your job is, how unsatisfied you are with your job or how little your job means to you. If your job is to clean toilets, clean it like your life depends on it. Clean it like you are going to eat your dinner on the toilet seats. Bang! If you are writing software, write it like it is the heart of a nuclear power plant. Put the bang! in your software so the power plant does not go bang!

Look back at the day you first started your job. What was it about the job which made you excited about it? Bring that feeling back. This is not to say do not quit, but do not forget why you started. Work like you are still on probation, and need to put that bang! in everything you are doing.

It all comes down to your work ethics. Do you have the traits, characteristics and strength of character that makes you do your work and be worth the dollar you are paid? When you go home at the end of the day, ask yourself whether that day you earned the money you got paid, or you bludged and fumbled through the day. Did you come to work late today? Leave too early? Took a longer lunch? Extended coffee breaks? And did you make up for these lost hours?

I’ll say this again. Anything worth doing, it’s worth doing with a bang! The universe was created that way (after all it IS called The Big Bang), and last time I checked, I had to agree that it was worth it.

Random thoughts.

Comment » 2 Comments

On Interviews

Category: Programming

Job Interviews are like double-edged swords. While it is an opportunity for the prospective employer to get to know you, what most people fail to do is getting to know your employer. Is that company a place you really want to work for? Will you be happy there or will it be an endless battle with management until someday you decide that you have had it and move to yet another Dilbertesque place, to work for yet another pointy-haired boss. Please, do yourself a favour and use the other side of the proverbial sword and take your cut. Ask pertinent questions that will influence your decision whether they are a good employer for you.

 

However, when its time to for you ask questions, most people can think of nothing too interesting to ask. I have interviewed a few candidates in the past, and I do not recall a single one of them asking a notable question that can influence their decision to work there or not.

 

So what do you ask? Have you heard of the Joel test? If you haven’t then take your 3 minutes and follow the link. Go on. In fact, Joel writes an excellent blog, go read it and don’t even come back here.

 

The problem with the Joel Test is that, as Joel himself points out, most companies run at 2-3. (ok, if you haven’t read the Joel Test, it is about a 12-point scoring system that tells you how good a company’s development team is). If you are going to use the Joel Test, and will be picky about companies scoring at least a 10 on the test, let me tell you my friend that you will be looking for a job for a long time, and most likely you will miss out working for some of the most fantastic companies out there. I don’t know about you, but I do not really care if a company doesn’t have a bug database, or they cannot make daily builds. These are things that the company should care about, not me (not yet anyway).

 

 

Instead, I prefer to use my “question time” at the interview and ask these 5 questions:

1. How do you measure your developers performance?

2. What level of support is required of your developers?

3. How much/often do your developers go on training / What/when was the last training they attended?

4. What tools do you give your developers to do their job?

5. What are the career advancement opportunities at your company for a Software Developer?

 

 

These are things I care about. Let me elaborate.

 

1. Performance Measurement

Most companies you work at will have some kind of Bonus / Revenue sharing scheme that is directly related to your performance at work. This is something that affects your bottom line, so before putting pen to paper and accept the contract, you will want to know how you are going to be measured. Often enough, this is not on the contract itself.

Imagine starting your employment at a company, and finding out later on that your performance will be measured by the number of lines of code you write, or the number of source control check-ins you commit. Or that your performance will be measured by the number of bugs the software contains (yes some managers do think they can create bug free software by stating it in the developer’s KPI), or by the accuracy of estimates on vague requirements. This is a crazy world, and people do crazy things. Are you prepared to have your KPI set on crazy benchmarks?

2. Support

Have you heard of that place where software implementations require the developer, dba, sys admins, application support, management, janitors and cleaners to be on site? This is what happens when “You will be required to do support work on an ad-hoc basis” is slapped on your work contract and you think nothing of it. Don’t get me wrong, I am not saying you need to shy away from support, but a functional organisation will have procedures in place so that developers do not get called on the weekend at 4am. These include a tough and thorough test cycle, a proper hand over to applications and system support, and training of helpdesk people to manage issues as they arise.

In order for this to happen, support cost for developers should be expensive. I have heard of phone handset companies where when the developer is to be “available”, it cost the company money – actual money in the bank, not funny “Time-in-Lieu” money. The rate is even higher if you indeed get called, consistent with penalty rates for weekend/out of hours support.

This provides a clear benefit to companies whereby it encourages them to properly release maintainable and supportable software. Often enough, documentation is what gets axed when a project overruns. Without proper documentation, proper support is impossible, and the developer will get called at the proverbial 4am when the disk is full and the application throws SQL Exceptions.

3. Training

When was the last time you got quality training from work? I’m not talking about gimmicky MS conferences  such as Heroes Happen. I’m talking about a real training session with real trainers. Is your new employer committed to the ongoing professional development of its team? Sure a lot of development and learning is on a per-needed basis: I need to do database access, let me read up on Linq2Sql. That is fine. But generally excellent developers will want to know more than just what they work on. The Microsoft Factory spits technologies at a dizzying rate: Linq2Sql, EF, WCF, WPF, WWF, WTF, etc. While you may not necessarily want intimate knowledge of the subject matter, excellent developers will at least want some ideas about it, and preferably see a seasoned developer use it a little bit to appreciate all its capabilities. Enter training sessions. Training with these real-world citizens with the likes of Juval Lowy, Dino Espositos, etc gives you that kind of exposure and an opportunity to pick the finest brains.

4. Tooling

What do you do when you have a performance problem in your application? Quite a few developers I have worked with attempt to guess where the bottleneck is, and start optimising. Did you know there are tools out there that will allow you to measure (profile) your application to your heart’s content – memory usage, execution times, etc. What are the odds of your company buying these tools should you request for it? How quickly can they purchase it? On numerous occasions I have worked with developers who will install trial software in order to fix real production issues.

Does your 15-year old niece have a faster computer than your work PC? Does it take forever to compile code? In my previous job, the latest computers were always given to the sales team because “they needed the application to run fast when they did a demo”. Opening the solution in Visual Studio took me 15 minutes every morning. Compiling? I used to make my cup of tea when code was compiling.

We are in 2010 now. Does your company allow you to install and run the beta version of Visual Studio 2010 on your machine or on a virtual machine? Or do you have to wait till 2011 “till the dust settles”? Bold companies out there have awesome software built and released to production with pre-release versions of various frameworks (go-live licence). Do you want to work in a company where the dust has settled and everyone else in the industry is working on the next big thing?

5. Career Advancements

What are the career prospects available to developers at the company you are interviewing? Are you expected that once you reach a certain level of proficiency, to take a role in Management in order to move to the next pay bracket? Joel Spolsky calls this “promoting someone to their level of incompetence” and I could not agree more with him when he says that the best programmers do not necessarily make the best managers.

 

Final thoughts

This is not, by any means, a complete list of questions of what you should ask at an interview. Go ahead, ask about flexible working hours and work life balance or anything else that is important to you. This list above isn’t a list of what you absolutely must ask your interviewer. Rather it is a list of things that over time I found to be pertinent to me – these are the things I care about. I would happily work for less money if I could get a fast pc, dual monitors, proper training and not getting woken up at 4am because the disk is full. I would be happy doing what I like doing best: programming. Are you happy to go to work everyday? Are you having fun? Are you motivated? Do you get to play with the latest technology? If you are, ignore everything I wrote here and do not change your job because you are lucky, my friend.

Comment » 1 Comment

How to get data in chunks from a WCF Service

Category: Programming

This is a simple solution on how to get data in chunks from a WCF service (e.g. a paged list of results)

Assuming that your service pulls data from a SQL Server database, you can use Linq2Sql and create your data context, OR if you are not using SQL Server, then the Microsoft Entity Framework may suit you.

Here is the code:

public IList <customers> GetCustomers(int pageIndex, int pageSize, out int total)
 {
  using (var db = new NorthwindDataContext())
    {
     var customers = db.Customers;
     total = customers.Count();
     var results = customers
      .Skip(pageIndex * pageSize)
      .Take(pageSize);
     return results.ToList();
    }
 }

Comment » No comments

Discover and Invoke methods programmatically at runtime

Category: Programming

I had a fairly simple problem recently (well, most problems are simple – solutions are not always so). I had an interface for a class that exposed about a dozen or so methods, and I needed to call them all, one at a time. The methods were parameterless and the return types were identical. Basically the methods was returning Generic dictionaries of Strings.

E.g.

IStaticData staticData = StaticDataImporterFactory.GetStaticDataAdapter();
Dictionary <string, string> dic = staticData.GetSomeValues();

Rather than writing code line by line that would call each method in that interface, I reflected (pun intended) there must be a better(?) way of doing this, and came up with the idea to use Reflection to discover the methods in the interface programmatically and then call them. Here is the code:

IStaticData staticData = StaticDataImporterFactory.GetStaticDataAdapter();
Type type = typeof(IStaticData);
System.Reflection.MethodInfo[] methodInfos = type.GetMethods();
foreach (System.Reflection.MethodInfo methodInfo in methodInfos)
{
  try
  {
    Dictionary result = (Dictionary)methodInfo.Invoke(staticData, null);
    // do whatever work I have to do with the result
  }
  catch (Exception ex)
  {
    // handle the error
    txtError.Text += "Could not execute " + methodInfo.Name + Environment.NewLine;
  }
 }

The above code relies on the assumption that the methods to call are parameterless. If you wish to pass parameters to the methods, have a look at MethodInfo.GetParameters() to determine at runtime what the parameters are, and you can then pass them as additional arguments to the Invoke method (noticed I passed null above?)

And the deed is done.

Cheers
Ash Moollan

Comment » 2 Comments

Choosing a blogging software

Category: Programming

I have tried various blog software in the past to run this blog.

.TEXT

I started using the now defunct .TEXT . In my opinion, .TEXT was excellent. It has a nice feature set and was more than good enough to run a personal blog. In addition, it had a 3rd party MS Access data adapter with everything requires to run it against it – it even had ms access versions of the stored procedures! Before we start shouting shenanigans, I know of all the evils that Access represents, but I still used it because it saved me an extra expense of MsSql hosting.

 

SubText

According to the makers of SubText,

Subtext is a personal blog publishing platform that focuses on usability, elegance, and simplicity. “

I gave it a test run on my local machine and it quite literally impressed me. The user interface was clean and easy to use, and offered just the features I needed to run my blog. It also exposed a great plug-in architecture which made it quite extensible.

 

Then I noticed something. Their website is powered by dotnetnuke!!! If they don’t think that SubText is good enough to run their own website, then why should I run mine on it? It’s a concept called dogfooding . Dogfooding is a pain, it is difficult and it tastes bad. But it shows me that if its good enough to run your own site on it, then i can consider running mine on it too. Community Server does it, Dotnetnuke does it and WordPress does it. Subtext doesn’t.

 

DotNetNuke

DotNetNuke is an extensible content management system. It is not a blogging platform per se. The appeal of dotnetnuke is that the average Joe can create and maintain their website without requiring a web professional to help them. There are convenient buttons and the text is editable in-place in a rich-text format ala Microsoft Word.

So why did I put dotnetnuke here as a blogging software? Because dotnetnuke is extensible, people have extended it to include a blog module. The blog module make dot net nuke behave as a blog engine and will run your blog sweetly on it.

I confess that I have used dotnetnuke in the past to run this website. I loved it. The user interface was friendly and it was very easy to add and edit posts and best of all, the post entries were fully SEO (Search Engine Optimised).

Having said all this, my design skills suck. I started, like most, with the basic default skin. Eventually I went on to create my own skin, and I can tell you – creating a skin in dotnetnuke is a Royal pain in the A**. Excuse the language.

Community Skins are rare. Most (of the few) persons who could make good skins for dotnetnuke try to make a profit by selling the skin (rightly or wrongly). And finally I gave up on my website looking good with dotnetnuke, and i tried Community Server.

 

Community Server

Community Server is used by MySpace and powers 70 million+ users. That is incredible. Community Server has more to it than Blogging – it has forums, photo gallery and file sharing as well. Community Server is created by the Author of .TEXT, Scott Watermasysk along with other guys from the nGallery and ASP.NET forums.

I gave Community Server a shot for a little while, and while sporting quite an impressive feature set, it was not suitable for a 1-person site running nothing more than a blog. While it does work for that scenario, it is just an overkill. The default skins were better than the dotnetnuke skins by yards and miles, but it had that “generic” feel to it. And so I dumped it.

 

WordPress

And here I am running this blog on WordPress. There is a buzz around wordpress. Lots of people use it, and what more so, lots of people like it. It’s clean, simple to use and has a powerful plugin framework (yes i know, they are the rage) .

Speaking of plugins, WordPress has an addin called Askimet that is very very good at sorting out spam comments without needing a captcha! (you know those images that you need to type in a box?)

The skins are customisable and there are tons and tons of free wordpress themes all over the internet . Heck the one I am using at the moment is one of them (thanks wpthemespot)

The only caveat so far about WordPress is the amount of database calls it makes to load each page. Why should you care? Let me tell you. If a blog does not have that many visitors, then that is fine. but the more visitors a blog has, the more database calls it makes, and the slower the website responds. And with the database calls, the server also uses more CPU to render your website, which does not help to make it run faster.

Having said this, the WordPress community has quickly caught on and developed plugins that will cache your pages and serve from the page where possible – and this drastically improve performance. Pity that this isn’t an out-of-the-box feature.

 

Closing Comments

Interresting (but totally useless) piece of information. All blogging software mentioned except for WordPress are built in .NET (and thus requires a windows hosting environment). What IS interresting is that they all use a database as a back-end and sql server (that is what the windows based applications generally use as a database server) hosting tend to be a lot more pricey than their non-windows counterpart.

WordPress on the other hand is built on php and uses MySql as the backend. Both are cheap as dirt to host.

And the question I get asked more often by my friends is “why the hell did you use a php blog software when you are clearly such a .NET guy!”. Heck I AM a professional .NET developer after all. Why I chose a php solution? Simple. The implementation of the blog software is the least of my concern. As a user, what I do care about is a hassle free, clean and easy to use software. WordPress gives me that.

All of the blogging software discussed here are free software that you host on your own domain. I have not discussed hosted blog software such as blogspot etc, althouth wordpress does offer free hosting for you.

 

Now that I have confused you with all these, my work is done.

Thank you.

Ash Moollan.

Comment » 7 Comments

Community Server

Category: Programming

I currently run my website on DotNetNuke as a content management server. I am considering changing to Community Server instead. I will give that a spin over the next few days at home, and if I am happy enough I will change this site to run on Community Server.

Typically I am considering Community Server because of its cool photo gallery (yes i know DNN has one too, but the community server is, IMHO, sexier). I also plan to add extra stuff on my website soon that would otherwise be a pain to do with DNN. Having said that, i need to experiment with Community Server first to see if it fit my needs.

The downside of all that is that, inevitable, all my links will change. I will aim to keep the RSS feed link unchanged (http://www.moollan.net/rss.aspx). If you are not using this one, then please update your bookmark since it is the only one that I support.

Comment » No comments

How to Serialize an Object to XML and then Deserialize back to its Object

Category: Programming

I often get asked questions about serializing a class to XML and then deserializing it back to its original object.

There are numerous reasons why you would do this, but more commonly I found that it is the preferred way to persist objects in a database.

I’ve put together these two methods that will take any object and serialize it to XML and vice versa. I have added the option to set the encoding type as a parameter to the method instead of going by the default Unicode encoding. Although Unicode encoding is the preferred way to serialise when persisting to a SQL server database (talking about the XML data-type that will only accept UTF-16), this method can be put to other uses as well. I have opted to fully qualify my namespaces in this example so that you can copy-paste it without having to worry about imports.

Say you have a class called person defined as such which you want to serialize:

 

   1: public class Person 
   2: {
   3:   String name;
   4:   public String Name 
   5:   {
   6:     get { return name; }
   7:     set { name = value; } 
   8:   }
   9:  
  10:   String surname;
  11:   public String Surname 
  12:   {
  13:     get { return surname; }
  14:     set { surname = value; } 
  15:   }
  16:     
  17:   DateTime dateOfBirth;
  18:   public DateTime DateOfBirth 
  19:   {
  20:     get { return dateOfBirth; }
  21:     set { dateOfBirth = value; }
  22:    }
  23: }

 

You can call then serialize/deserialize as such:
 
   1: Person p = new Person();
   2: p.DateOfBirth = DateTime.Now;
   3: p.Name = "Ash";
   4: p.Surname = "Moollan";
   5: String xmlPerson = SerializeToXml<person>(p, Encoding.UTF8);
   6: Person personFromXML = DeSerializeFromXml<person>(xmlPerson, Encoding.UTF8);
 

And the actual implementation of the serializer and deserializer:

 

   1: using System.Xml.Serialization;
   2:   public String SerializeToXml(T o, Encoding encoding)
   3:   {
   4:       XmlSerializer serializer = new XmlSerializer(typeof(T));
   5:       using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
   6:       {
   7:           using (System.Xml.XmlTextWriter xmlWriter = new System.Xml.XmlTextWriter(ms, encoding))
   8:           {
   9:               XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();
  10:               namespaces.Add(String.Empty, String.Empty);
  11:               serializer.Serialize(xmlWriter, o, namespaces);
  12:               return encoding.GetString(((System.IO.MemoryStream)xmlWriter.BaseStream).ToArray());
  13:           }
  14:       }
  15:   }
  16:   public static T DeSerializeFromXml(String xmlString, Encoding encoding)
  17:   {
  18:       Byte[] aBytes = new Byte[encoding.GetByteCount(xmlString)];
  19:       aBytes = encoding.GetBytes(xmlString);
  20:       System.IO.MemoryStream ms = new System.IO.MemoryStream(aBytes);
  21:       XmlSerializer xs = new XmlSerializer(typeof(T));
  22:       return (T)xs.Deserialize(ms);
  23:   }
 

Hope it is useful to someone. Do bear in mind that only the public properties will be serialized. There are also extra serialization attributes that you can add to the class to shape the way it gets serialized.

Thanks,
Ash Moollan

This post applies to
.NET 2.0
Visual Studio
Xml
Serialization

Comment » 1 Comment

Hello GI-Jane Grandma!!!

Category: Programming

The Australian Tech-Ed 2006 this year is hosted in Sydney. I’ll make sure I attend the session How to get your grandmother building Missile Defence Systems, it sounds like a lot of fun ;)

Comment » No comments

Forcing a Page_Load on BACK button in .NET

Category: Programming

There’s a little tip on how to force a page_load when the user press the back button on the browser.

In your page_load section, add this line of code:

Response.Cache.SetCacheability(HttpCacheability.NoCache)

By disabling ASP.NET Caching on a page, we can force a Page_Load on BACK button. There are a few reasons why you would want this kind of behaviour.

1. Populating a page with data from database/session variables
2. More importantly, going back to a page that previously posted back to itself.

Point 2 is noteworthy. It avoids the unpleasantness of having a “page has expired” when pressing back. This is because when a page posts back to itself, it does a form submit. Navigating back to such a page forces the submit again, with an IE prompt. By storing the page values temporarily (e.g. in, say, a collection pushed in a session variable) we can then check for the existence of that session variable and then reload these values on the page on the back button. In doing so, we nicely avoid the page is expired issue. All it takes is a little extra effort, but the user experience is greatly ameliorated.

In my case I had a page that was creating a temporary XML file that I use to create SVG Pie Charts and I clean (read delete) the XML file when the page finished loading. This causes problems when the user navigates back to the page and it can’t find the XML file to draw the Pie.

Any which way, Response.Cache.SetCacheability(HttpCacheability.NoCache) is a useful code snippet to have in your ASP.NET repertoire.

Thanks,
Ash Moollan

This post applies to
.NET 1.0, 1.1, 2.0
Visual Studio
ASP.NET
Caching
Postback
Back Button .NET

Comment » 3 Comments

Hmmmm Something!!!

Category: Programming

It’s a bit of a disappointment that “Something” hasn’t been added to the Visual Basic Language. I have been dreaming of a day when I can use

Dim Blah as New Person
...
If IsSomething(Blah) Then
   ' Do Stuff with Bla
Else
   MessageBox.Show(”Blah has not been initialised”)
End If

Well, until that day comes, I refuse to use

If Not IsNothing(Blah) Then …

and instead I have created a global public function

Public Function IsSomething(ByVal Expression As Object) As Boolean
 If Expression Is Nothing Then 
   Return False
 ElseIf TypeOf (Expression) Is String AndAlso CType(Expression, String) = "" Then
   Return False
 ElseIf TypeOf (Expression) Is DBNull Then
   Return False
 Else
   Return True
 End If
End Function 

So that I can still use the IsSomething method until it becomes part of .NET.

I enjoy things like testing datarow items with this method, which will test if the item is either DBNULL or an empty sting.

If IsSomething(ds.tables(0).rows(0).item(2)) Then
...
End If

Thanks
Ash Moollan www.moollan.net

This post applies to
.NET 1.0, 1.1
.NET 2.0
Visual Studio 2005
Is Nothing

IsSomething

Method Discovery

Comment » No comments