Archive for the 'Development' Category

I’m a scrum novice

I have been forced to learn what Scrum is due to two independent assignments.

So in the spirit of learning stuff by myself I just read Agile Software Development with Scrum and I’ve got Agile Project Management with Scrum in the pipe.

It struck me that Scrum is a little like it has turned out when I, and the good developers around me, have had some saying in the organization of software development.

I’m by far an expert in the field but I get the feeling that it will be hard to convince a customer to embrace Scrum. I would gladly work in a Scrum team though.

My Scrum encounters this far is by one customer that want to use Scrum in a project to migrate a rather large application from VB6 to .NET, and one customer where I helped them inspect and evaluate a software supplier (and their software) that uses Scrum for their application development.

Done in the right way I really think it enables both transparency and creative thinking.

Passing on knowledge

This week I had the opportunity to introduce a recently employed colleague. He came out of school when there were almost no programming work available. Being a smart guy he has nurtured his programing skills while doing other things to pay the bills.

I really like spreading the little knowledge I still have. It feels like I have forgotten a lot more than I remember. This week I worked on a couple of Visual Basic 6 applications. At the beginning of the week I didn’t remember anything. I had some small fragments of ghosts of memories in the back of my head. Thanks to Google I could find a lot of information about the topics involved. Information that filtered through my remaining knowledge lead to an understanding of the problems at hand.

This got me thinking about what I should try to pass on to the new guy. Experience is not easy to teach and we are working in an industry that is still very immature. Technical details can be found withing seconds on the net so that’s unnecessary to teach. I ended up recommending him to read Code Complete, Second Edition and The Pragmatic Programmer: From Journeyman to Master. That should take care of most of the, kind off, tangible things. I then spent most of the time to give him the guts to dare to have fun while working, to communicate his view when in disagreement with the customer and to ask for help before it is to late.

I really hope he enjoyed it as much as I did. It’ll take more than three days to pass on more than fifteen years of work life knowledge.

Refactoring in VB6

I just got handed a click event with 19 pages of code. Yep, you read it right: nineteen pages!

What can I say? My need for a refactoring tool that works in Visual Basic 6 became immediate.
Luckily I found CodeShine through a little googling.

It doesn’t do a lot, compared to Refactor! and Resharper, but the things it does are invaluable. Its functions are: Extract method, Introduce Explaining Var, Extract function, Localize module variables and Rename.

At about SEK500:- I’d probably pay for it with my own money if I would need it more than the 21 days I can try it for free. This is a tool everyone maintaining crappy legacy VB6 code should have.

I don’t miss COM+ development

This week I had to get Excel to run as a server object to serve an ASP.NET solution that I migrated from .NET 1.1 to .NET 2.0 and moved to a new server.
Please spare me the comments on running Excel on the web server. That decision is/was not mine to make.
Anyway; I got really reminded of how much I forget when I am not working with it. I think I once new all the COM-errors I encountered this week by heart.

Some things are best forgotten.

Open source translation service

Writing the previous post got me thinking:

I would like to have an open sourced free hosted translation service available.
It should offer procedures and tools for localizing .NET applications. A developer should be able to upload a bunch of strings and some context describing text so that volunteering individuals could translate them online.
It could be set up so that you got one string translated in return for translating another string. So if you know one language you could log in to the site and translate other developers stuff and get your things translated in return. This way you could pay someone to translate string to one language on your behalf and you would get more languages in return.

I’m not quite sure how the Ubuntu translations work but I guess we could learn a lot from them.

Is this already done or will it be done before I have had the time to think this through?

It is sometimes tough to turn down help

About a week ago I was offered help to translate logview4net to Russian. The offer came from a gentleman owning an open sourced project for translating .NET applications.

Of course I was thrilled by the offer. I had really thought about localizing it, but since English and Swedish is all I know I haven’t put it on top of my to do list. Most, if not all, Swedish users of logview4net are probably happy using it in English.

Anyway; after looking at the technical solution I decided I didn’t want to use it in my application. I feel a bit bad for letting him do all the work before I looked at his solution. I assumed to much. A bad habit I really need to get rid of. I have localized one large application as an after thought and one as part of the design so my decision is at least based on some experience.

I hope my turn down letter will be regarded as constructive criticism and not a flipped finger.

To any one else wanting to write tools for localizing applications; there a lots of stuff that works in the .NET framework. Try to create tools for all the things that are missing instead of starting from scratch.

Coalesce operator in C#

I got reminded about the ??-operator in C# today. It is a coalesce operator and works like this:


string a = null;
string b = a ?? "Woops, a is null.";
Console.WriteLine(b); <- Will write 'Woops, a is null.'

I really need to read the language specification at least one time per year to remind myself about all the things I don’t use frequently. It is way to easy to keep on solving programming problems with the same old tools all the time. I like to learn new languages. At least to the level that I know what to google about if I have to use a specific language. But at the same time I think one should try to master at least one language. C# has been my favorite tool for years so I am blushing a bit as I confess my shortcomings.

One more podcast

Today I added Rubiverse, a podcast about Ruby, to my jsiPodFetch feed list.

I’ve recently learned some Ruby and I like it a lot. I will definitively install IronRuby when it is properly released. Currently I’m using ‘real’ Ruby for my jsiPodFetch build scripts and for aggregating data from my weblogs. It feels a bit awkward to install something like Ruby just to do some scripting in Windows though, maybe I should look at Powershell instead. That is a bit more classic shell scripting. I think the things I’m using it for is more like programming. I’m not sure when something is to be called a program and when it should be called a script.

The best thing to do is probably to learn lots of languages and frameworks so that one can make educated decisions when it comes to solving new problems.

Shareware license key

This article will describe how I have implemented license keys in jsiPodFetch. I hope it will help someone else trying to do this. It would also be nice if someone reading this gave me feedback if this solution doesn’t work in practice since I haven’t analyzed this solution thoroughly enough to swear by it, but I think it will work.

Through out this code there are places that are open for variation. Most important if you reuse my code here is that you use your own unique strings.

Most payment processors (SWReg, Plimus, and so on) will be able to query a URL of your choice to create a license key. This solution uses a PHP-script to create a license key that can be validated by code written in any .NET-language. I will use C# for my examples.

The solution uses a multi part license key so that you can change the application code that checks the license when/if it gets cracked or keygened.

Let’s start with the PHP-code that creates the license key.

I start by creating three unique strings. Let’s use ‘AAA’, ‘BBB’, ‘CCC’. (I use more than three, but it will be enough to make my point.)

$g1 = 'AAA';
$g2 = 'BBB';
$g3 = 'CCC';

…then I create a hash from the unique string concatenated with the e-mail address used for registering the application.
By the way; I am constantly truncating the values at five characters to make the key a bit smaller. It will make the hash values weaker, but I think it will OK anyway.

$key1 = substr(md5($g1 . $_GET["email"]), 1, 5);
$key2 = substr(md5($g2 . $_GET["email"]), 1, 5);
$key3 = substr(md5($g3 . $_GET["email"]), 1, 5);

… and that’s about it. Now I can concatenate the individual hashes and the e-mail address.

$license = $_GET["email"] . “-” . $key1 . “-” . $key2 . “-” . $key3;

…then I create a hash of the license and concatenate that with the license.

$hash = substr(md5($license), 1, 5);
$license = $license . "-" . $hash;

Finally I return the license key:

echo ($license);

The result is this:

foo@foo.com-fb821-90d34-8b8c6-ca6ab

Now it’s time for some C# code. The main obstacle was getting a PHP compatible hash value out of strings in .NET. I googled a bit and found this (I’m not sure where it came from though so I can’t give proper credit.):

public static string Md5Hash (string pass)
{
  MD5 md5 = MD5CryptoServiceProvider.Create ();
  byte[] dataMd5 = md5.ComputeHash (Encoding.Default.GetBytes (pass));
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < dataMd5.Length; i++)
  sb.AppendFormat("{0:x2}", dataMd5[i]);
  return sb.ToString().Substring(1, 5);
}

This method will return the same string as the PHP md5() method given the same input.

Since I hashed all concatenated sub keys I can now validate a given license key with this:

public static bool LicenseIsValid(string license)
{
   int lastHyphen = license.LastIndexOf("-");
   if(lastHyphen < 4 )
   {
     return false;
   }
   string l = license.Substring(0, lastHyphen);
   string hash = Md5Hash(l);
   string[] lines = license.Split('-');
   return (hash == lines[lines.Length -1]);
}

I could include a fourth secret string when I do the hash of the full key, but at this stage I only want to validate that it is a license key for my program. I don’t want to check its authenticity yet.

To authenticate a key I get one of the hashed sub keys. With this function:

public static string GetKey(int n, string license)
{
   string[] lines = license.Split(’-');
   return lines[n];
}

I then hash the secret string I used for the n’th value together with the email and compare the result with the sub key from the license.


string email = GetKey(0);
string validHash = Md5Hash ("AAA" + email);
if(validHash == GetKey(1))
{
   //Allow registered stuff
}
else
{
   //Inform user that thy have to pay.
}

To make it a little bit harder to crack this, make sure to write this code in several places. If you encapsulate it in a method there is only one place to bypass.

When someone has created valid keys you can recompile the application and use your second secret key so that the key maker has to restart his work. You could also move the checking code around a bit so the cracker has to redo his work.

That’s all there is to it.

One thing I miss with this solution is the ability to encode data, like a date, into the key.

FreeMind and the current job

The current job is about defining/refining and documenting a system that is a couple of years old. I was a big part in building it initially but it has grown without much control since then.
As I see it, the main reason it is hard to get a grasp of it now is because there is (or has never been) a central role to consolidate the development. For each little project there has been a new project manager who only wanted to do his part at the lowest cost or him. No one has taken, or gotten, responsibility for all of it. This has led to more than one ugly hack to solve the same issue in different sub projects.
Now they have taken the opportunity to try to figure out what functionality there actually is, and what should be reused or refactored.

This is the first time my deliverables aren’t code. Starting with a blank sheet is always hard, but I remembered FreeMind, a free mind mapping tool. It helps a lot with the blank sheet syndrome since one can start dumping information in it and organize it later. Of course that is possible in any other text editor, but the graphical metaphor of FreeMind helps, at least me, get over the writers block.

I haven’t run FreeMind in Vista before so it was not very pleasant to discover that all file operations on new files failed. I solved it by copying one of the document that came with the install. When I double click it in my favorite file manager it starts FreeMind and I can save changes to ‘old’ documents. It is apparently a known bug so I will keep recommending FreeMind to any one who wants to listen.

I used to build my documentation for logview4net in a commercial competitor called Mind Manager. I think I will start using FreeMind for both logveiw4net and jsiPodFetch in the future.

Next Page »

Close
E-mail It