Life of the software engineer RSS 2.0
# Tuesday, November 17, 2009

Had to share this photo:

Boris Johnson smokes a cigar

Yes it's Boris Johnson smoking a cigar. Ok, it's not really Boris, it's an actor, but good all the same.

Lifted from the truly brilliant When Boris Met Dave on Channel 4; The story of Boris and David Cameron when they were at Eton and Oxford together.

Tuesday, November 17, 2009 3:00:30 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -

# Saturday, November 07, 2009

I am very excited! Today, for the first time ever, I successfully made a loaf of bread.

loaf1

You might think that putting some ingredients in a bread machine and selecting 'program 2' would be very easy and consistently produce bread. However, several previous attempts were not successful at producing bread. They were successful at producing building materials though..

loaf2

Although it looks a little odd and is flat on top, I am very proud of my bread.

Saturday, November 07, 2009 10:57:37 PM (GMT Standard Time, UTC+00:00)  #    Comments [1] -

# Thursday, November 05, 2009

Enums are great for fixed lists of options, including things like user configurable application options. But what do you do in cases like this with the UI? You could just hard code it, which sounds fine, enums are hard coded too. However this isn't so fine when you need to add another value later; You have to go back and adjust the UI, and if you have lots of screens which display the same options there is always the chance you will miss one.

Wouldn't it be nice to get a list of values for an enum, with some display text included that you could bind to UI control, or iterate over to create things like radio buttons dynamically? You could just write some code to parse each enum and give you what you want, but that's a bit tedious too. What you really want is to be able to attach display text to the enum values right where they are defined and have a common function to get a list for you. And that's exactly what you get here:

How To Use It

Reference EnumUtil.dll in your project and EnumUtil in your namespace. Add an EnumDisplayText attribute to each item in your enum. The first parameter takes the text you want to display and the second takes an integer which defines the display order. Items with the same display order will be grouped and sorted alphabetically by display text. If an item does not have an attribute it will get the item name as its display text and 0 as its display order.

public enum DemoEnum
{
    [EnumDisplayText("Hello,", 0)]
    a,

    [EnumDisplayText("This is", 1)]
    b,

    [EnumDisplayText("a lovely", 2)]
    c,

    [EnumDisplayText("list.", 3)]
    d

}

To get a list containing the enum items with their display text use the static method GetList() from the generic class Enums<T>, where T is the enum you want.

List<EnumListItem<DemoEnum>> enumList = Enums<DemoEnum>.GetList();

 

You'll get back a generic list of type EnumListItem. The EnumListItem has the following fields:

  • EnumValue – An item from your enum
  • Name – The name of the item
  • DisplayText – The display text you specified in the item attribute
  • DisplayOrder – The display order you specified in the item attribute

So, for example, to bind the list to a winforms list box you could do this:

List<EnumListItem<DemoEnum>> enumList = Enums<DemoEnum>.GetList();
this.listBox1.DisplayMember = "DisplayText";
this.listBox1.ValueMember = "EnumValue";
this.listBox1.DataSource = enumList;

 

If you just want to get the display text for a specific enum item use GetDisplayText(T item).

string displayText = Enums<DemoEnum>.GetDisplayText(DemoEnum.a);

 

There is a little demo application included with the source that shows all this stuff in use.

 

How It Works

I'll walk through the GetDisplayText method, GetList does the same thing in a loop..

public static string GetDisplayText(Enum item)
{
    Type type = item.GetType();
    MemberInfo[] memberInfo = type.GetMember(item.ToString());

    if (memberInfo != null && memberInfo.Length > 0) 
    {
        object[] customAttributes = memberInfo[0].GetCustomAttributes(typeof(EnumDisplayText), false);
        if (customAttributes != null && customAttributes.Length > 0)
        {
            return ((EnumDisplayText)customAttributes[0]).DisplayText;
        }
    }

    return item.ToString();
}

First up, we get the type of the enum, then we query the type to get the details of the enum item we are interested in. Next, we get the custom attributes for the item (only attributes of type EnumDisplayText). If we find an attribute of the right type, access the DisplayText field and return it, otherwise return the name of the item.

That's it!

Thanks to Abhinaba Basu for his blog post which inspired this / did all the hard work..

Enjoy!

Thursday, November 05, 2009 9:53:44 PM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
General Programming
# Tuesday, October 06, 2009

vbtv

Anybody remember VBTV from when .net 1.0 first came out? I was just going through some old backups and found the files. They don’t seem to be on MSDN anymore, and Google doesn’t seem to offer any help finding them either. So, for your viewing pleasure, here they are:

(Right click and save target)

Episode 1

Episode 2

Episode 3

Episode 4

They’ll play in Media Player, but seem to use some obscure audio codec. If you don’t get any sound these should sort you out:

Acelp audio codec for Vista and Windows 7

Acelp audio codec for Windows XP

 

Chris & Ari

Head in The Box

Tuesday, October 06, 2009 7:29:33 AM (GMT Daylight Time, UTC+01:00)  #    Comments [1] -

# Sunday, July 05, 2009

I’ve been getting a bit distressed recently about what Google comes up with when you search for ‘Daniel McAdam’. Seems there are lots of pretenders out there who share this great name.

It is time to set the record straight.
I do not:

  • Collect Mexican stamps.
  • Have long blond hair and wear a baseball cap – That’s dodgy Dan on Facebook.
  • Work as a sales director.
  • Study at South Carolina University.
  • Have a middle name starting with P or J.

If you are looking for any of these Daniels go back to Google. This site belongs to the only real ‘Daniel McAdam’.
I do:

  • Work as a software engineer / architect.
  • Focus mainly, but not exclusively, on Microsoft technologies.
  • Have an interest in encouraging other software engineers to broaden their horizons by thinking about language, literature, culture, philosophy and how these things can relate to what they do.
  • Like to help charities out with their technology from time to time.
  • Like to read great works, particularly from Russian authors.
  • Like to ski.
  • Like good architecture (buildings and software).
  • Have a motorbike license (no bike at the moment).
  • Live in the North West of England.
  • Travel as often as I can.

Daniel McAdam 
This is me. In Mexico City. No Stamps.

Sunday, July 05, 2009 4:36:55 PM (GMT Daylight Time, UTC+01:00)  #    Comments [1] -
About Daniel

Last night I was at a barbeque with a few people on Claudia’s roof.
After midnight and a lot of drinks we got to reciting poetry. Here’s one by Ralph that I want to share:

Yes, I will grab the world by it’s horns and shake it until it gives me what I want!
Not wasting any time anymore.
No! Proactive and full of power and energy, making the best of my life and my current situations.
And as the last shirt has no pockets, lets give it all now.
Already by 9am I start.
In front of my computer, ready for action.
When it crashes and freezes all my personal and professional documents.
Leaving me in utter disbelief, helplessness, despair and finally panic.
10 hours later by 7pmish – no progress!
I am shattered, but on the way to a meditation workshop in Wales.
Driving through heavy rain and snow in a tiny car with no heating and a very tired windscreen wiper.
Maharishi talks about the absolute and relative aspect of life.
And the beauty of a flower and other manifestations of this higher intelligence.
And I meditate.
On anti-virus software, firewalls and frozen computer screens.
So much for taking my destiny by it’s horns!

Ralph is a rock star, poet and yoga teacher. He spends most of his life touring the world. In his spare time he is a GP.

Software engineers, what can we take from this? The software we produce can have profound effects on the lives of the people who use it. Always remember this. By taking the time to make it robust, resilient, effective and pleasant to use, we can improve in part the lives of others.

Sunday, July 05, 2009 4:18:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Poetry
# Friday, July 03, 2009

I’ve just read a great article in MSDN Magazine online:

Anti-Patterns To Avoid In N-Tier Applications by Daniel Simmons

It does claim to be about building applications that use the Entity Framework, but forget about that, it’s a great article that applies to any n-tier design.

Six ‘anti-patterns’ are covered:

  1. Tight Coupling
  2. Assuming Static Requirements (i.e. the customer knows what they want in advance)
  3. Mishandled Concurrency
  4. Stateful Services
  5. Two Tiers Pretending To Be Three
  6. Undervaluing Simplicity

So what is an anti-pattern? It’s just an example of a bad way of doing things.

I’ve witnessed countless horrible situations which could have been avoided by avoiding each of these anti-patterns.

Tight coupling: Systems where every bug fix generates new bugs (sometimes hundreds). Dev teams end up in an endless cycle chasing their tails and everyone with an interest in the product from the developers to the customer gets upset.

Assuming Static Requirements: There are so many situations where it is obvious that a change in the spec is likely to happen at some point the future. Designing a system to be tolerant of change reduces the risk of having to do some serious reworking, or even binning the whole thing and starting again. Sometimes this can be as simple as just storing lists in a database that can be added to instead of hard coding them.

Mishandled Concurrency: This can be a nightmare. Customers start complaining that their data disappears or isn’t right – sometimes. A related and even harder to track down issue is mishandled threading. This is a big area, but here is one tip: do not wrap database connections in a singleton in a multithreaded app. It will break.

Stateful Services: Complicated and time consuming to build, don’t scale. Enough said.

Two Tiers Pretending To Be Three: I have seen so many systems which started out with grand 3-tier intentions and after about five minutes the business logic is spread out all over the place. Some of it is in the middle where it should be, some of it is in the UI and some of it is in stored procedures in the database. And there is SQL in the UI. And there are pieces of UI in the database (as is stored procedure gets some data, applies some business logic to it and returns HTML which goes through the middle, possibly getting modified along the way and inserted into the rest of the UI). Nasty to debug. Nasty to change. Nasty.

Undervaluing Simplicity: I just cannot face another complex solution to a simple problem. I get the feeling that some developers like to create complex solutions to somehow prove that they are smart. The smart thing to do is keep the simple simple. Here’s a quote from Tony Hoare (the creator of QuickSort): “The pursuit of complexity is easy, and the implementation of complexity can safely be delegated to competent managers. But the pursuit of simplicity is one of the most difficult and challenging activities of the human mind.” - Challenge yourself every day.

Friday, July 03, 2009 2:23:47 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Patterns and Software Design
# Thursday, July 02, 2009

About a year ago I went to London with Claudia for the weekend to attend a conference. We stayed with another doctor Claudia knew and her husband Naoise (pronounced NEE sha).

On Saturday Naoise got a delivery from Amazon containing about five books. He told me that he gets a similar delivery most days and is having trouble getting into his office it’s so full of books. I wondered why he would spend so much money on all these books. Now I do love reading, and think everyone should read as much as they can, but he couldn’t possibly get through 25 to 30 books a week.

However, he was adamant that he could. He went on to tell me about a speed reading course that he had taken years ago, the effect it had had on him and strongly encouraged me to book a place on one as soon as I got home.

On getting back to the lovely north west of England I soon discovered that such courses are only available in the south of England.. However my search results for a course included a link to Amazon. A few days later I had a copy of The Speed Reading Book by Tony Buzan.

The Speed Reading Book

 

 

 

 

 

 

 

 

 Amazon UK Page | Amazon US Page

The book describes itself as a revolutionary approach to increasing reading speed, comprehension and general knowledge. Would I say that it is revolutionary? No. Did it increase my reading speed, comprehension and general knowledge? Yes.

It’s got some good reviews on Amazon and some not so good. I find myself agreeing with both to a degree. However, if you follow it through to the end it will definitely have a very positive effect. I have been a fairly slow reader for most of my life. Now I get through a page in a novel in just under a minute (currently reading The Gulag Archipelago by Aleksandr Solzhenitsyn – brilliant, buy it - Amazon UK Page | Amazon US Page). It can take a while for speed reading to feel natural, and it can feel like it’s taking away from the enjoyment of reading the book – at first. But after a bit of practice it will make reading books for pleasure much more satisfying.

Speed reading makes a bit difference to your life as a developer. You can effectively skim through 800 page tombs like Code Complete (essential material for any developer, if you don’t have it buy it - Amazon UK Page | Amazon US Page) in a day and detailed blog entries in seconds and retain a surprising amount. If you combine this with listening to podcasts on the way to work you will dramatically increase the range of tools and techniques you have available to tackle projects at work. Your work will become more satisfying, the quality of your work will increase and eventually you’ll be worth more to your employer – and hopefully they’ll recognise this and pay your more.

So there you have it. Change your life with one pink book. I’m off to buy some shares in Amazon.

Thursday, July 02, 2009 10:56:00 PM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Speed Reading
# Wednesday, July 01, 2009

Podcasts are great for keeping up to date, getting new ideas and generally helping you to feel connected with the rest of the geek community. Much less effort than reading a book, particularly with subjects that you're not even sure you're interested in yet, and you can listen to them on your way to work.

The quality of some of the podcasts out there is truly fantastic. Here's what you'll find on my iPod:

.net General Programming

.net UI and UX

General Software Engineering

Technology News

  • PRI's The World: Technology - Not just another latest gadget show. This one covers things like innovative use of technology in the third world and how technology is effecting politic and vice versa.
    http://www.theworld.org/technology-podcast

Non Programming (but still essential for the well rounded programmer)

 

That's all I can manage on my commute to work. If you've got any suggestions let me know and (if I like them enough to subscribe myself) I'll add them to the list.

 

Wednesday, July 01, 2009 1:13:01 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0] -
Podcasts
Navigation
Archive
<November 2009>
SunMonTueWedThuFriSat
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Send mail to the author(s)Daniel McAdam
Sign In
Statistics
Total Posts: 10
This Year: 1
This Month: 1
This Week: 0
Comments: 18
All Content © 2010, Daniel McAdam
DasBlog theme 'Business' created by Christoph De Baene (delarou)