TheHumbleProgrammer

Just another WordPress.com weblog

Archive for the ‘Uncategorized’ Category

Keep on tweaking – solution

Posted by thehumbleprogrammer on July 10, 2009

in my previous post I published the following code

   1: public void SetCustomerPropertiesOnView(IEnumerable<Customer> customers)
   2: {
   3:     int count = 1;
   4:     string previousSurname = string.Empty;
   5:     foreach (var customer in customers)
   6:     {
   7:         this.View.AllCustomers.Add(new CustomerDisplay(customer));
   8:  
   9:         if (count == 1)
  10:             previousSurname = customer.Surname;
  11:  
  12:         if (customer.Surname != previousSurname)
  13:         {
  14:             this.View.SurnameFilter.Add(new NorthWindListItem(customer.Surname, customer.ID.ToString()));
  15:             previousSurname = customer.Surname;
  16:         }
  17:         count++;
  18:     }
  19: }

The context around this code is a view that shows all customers and allows the user to filter on surnames. Therefore I go and get the customers from the database I transform them for display and extract the unique surnames for the filtering functionality. I want to do all of this in one iteration of the customer list.

The above code achieves this aim, it may well be a naive implementation and there are other ways of doing this in a more efficient manner. That said the point of this post is to focus on the maintainability of this implementation, not it’s efficiency or approach. I would say that most developers would probably leave this implementation as is once they have achieved the goal. They would probably not be inclined to refactor this working solution into a more elegant solution that is maintainable over time.

My end solution to this problem looks like this

   1: public void SetCustomerPropertiesOnView(IEnumerable<Customer> customers)
   2: {
   3:     var customersAndSurnames = customers.TransformForDisplay().AndGetDistinctSurnames();
   4:  
   5:     this.View.AllCustomers = this.GetCustomersFrom(customersAndSurnames);
   6:     this.View.Surnames = this.GetUniqueSurnamesFrom(customersAndSurnames);
   7: }

The implementation of the two extension methods is not really that important in the end we still have the horrible implementation, but at the top level when the next guy comes along to add or maintain this code they will have some context around what we are trying to do. SetCustomerPropertiesOnView now has a more declarative style, you can see straight away that we are transforming customers for display and getting distinct surnames in order to give them to the view. The two private methods are just wrappers around extraction of the values in a C# implementation of a tuple, which is used to return two different types of values from one method without using out or ref parameters.

In conclusion once you have found a solution that works don’t just stop there, use the tests too aid your refactoring of a first attempt into a more maintainable elegant intention revealing block of code.

Posted in Uncategorized | Leave a Comment »

Another Stupid User!

Posted by thehumbleprogrammer on September 18, 2008

A couple of weeks ago my significant other and I decided to buy her father an entry level computer. Having completed a learn direct introductory course at the local  library, and having a considerable amount of free time at the moment we thought the time was right for an early Christmas present. So we opted for a basic Packard Bell PC from PCWorld. Buying it and setting it up was really simple and within 20 minutes of bringing round to the house John was up and running.

Out came the old learn direct disk, which I have to say I was very impressed with, explaining all of the basic aspects of using the computer. The disk was packed with lots of little games to aid learning too control the mouse and such like. After about an hour of happy learning a dialogue box appeared, which had no cancel facility, luckily my other half was in the room at the time and being the jaded experienced user that she is the dialogue box said;

“If you want to tech the tech, you need to tech the tech with the teching tech tech. Tech the tech? Yes / No”

or words to that effect. So John was instructed to click OK and the problem dialogue box would go away. On clicking OK the sound disappeared, at this point first line support for all the families computer needs was summoned to the room. I did the usual checks to see that the sound was not turned down or that it had not been muted. The sound was coming out from the sound card to the speakers in the monitor, so I unplugged the cable and plugged it back in again causing the offending dialogue box to appear again.

packardbell_issue 

As you can see the active window is asking “Which device did you plug in?”, so now I am being made to think, and as we all know users shouldn’t have to think. The device I plugged in was the line out to the monitor. So where is that option then, well ok trial and error time I went through them all and after getting no joy I was convinced that it must be the Rear speaker out option and that there must be a problem with the monitor. The assumption behind this option being, we had plugged the cable into the rear line out jack (I know, assumption is the mother of all….).

After reluctantly admitting defeat I took the machine back to PC world and explained the issue to the tech guys there, within a few minutes the guy came back handed me the base unit saying that it was all sorted. When asked what the fix was, he gave a little chuckle as if to say, don’t be a dumb user, and then said “you have to re-task the jacks, and that it was the front speaker out option”.

All’s well that ends’ well eh… Not really, to my mind it should not be that difficult to setup the sound from a computer’s sound card. The jacks are colour coordinated and so are the connecting cables. I have never had to learn what the colour coding means because on every other system I have setup I just plug the green cable from the speakers into the green jack on the system and hey presto as if by magic, we get sound. Quite simply to put the responsibility of re-tasking a jack into the hands of already overwhelmed novice users  is a poor design decision.

Posted in Uncategorized | Leave a Comment »

Not another one!

Posted by thehumbleprogrammer on July 3, 2008

Hi, my name is Dermot Kilroy. I am a .NET developer living in London, currently working in the Media industry on the content management system for one of Britain’s largest websites.

My interest in computers began way way back in the days of windows 95/98. I had reached the dizzying heights of middle management in the service industry and now had to use a PC as part of my job. As a typical user I found them to be incredibly frustrating and always wanted to do things in a different way to that suggested by the help files. The frustration of not understanding what was going on under the hood led me on a quest through formal education in Internet computing at The London South Bank university. I graduated from University in 2005 and have been working on Asp.Net C# applications ever since.

I have started this blog for one simple reason: have you seen what’s happened to Jeff Attwood since he started waffling on in 2004? I figure i can waffle with the best of them, so watch out blogosphere I’m coming to get ya. Oh yeah and I also have a lot to learn and say on all the usual topics of agile software development. Also it makes a nice way for me to formalise my learning with a searchable repository of topics related to software development, as well as a place for me to vent about the software industry in general from time to time. Finally, if only one person learns something from my ramblings on these pages then I will be happy that my work was not in vain. Hi mum I am on the Interweb…

I have chosen the humble programmer as the title of my blog after the paper by Edsger W. Dijkstra. The essence of the paper struck a chord with my approach to software development:

The competent programmer is fully aware of the strictly limited size of his own skull; therefore he approaches the programming task in full humility, and among other things he avoids clever tricks like the plague.

Throughout university and in my short career thus far I have felt that our industry promotes the need to hide the fact that sometimes we just don’t get it. This attitude stops us asking the simple questions that need to be asked for fear of being labeled as stupid. After reading Dijkstra’s paper I realised that I had to be confident in what I do know and willing to work really hard to learn and understand what I don’t. I figure that by publishing what I do know that I might be able to help someone by passing on that knowledge. I also want to learn from the collective power of the web and I am sure that if my understanding of a topic is less than correct, people will let me know.

Posted in Uncategorized | 1 Comment »