Notes from the trenches.

Let’s take a shortcut

Posted: May 19th, 2009 | Author: admin | Filed under: code, personal | Tags: , , , , , | No Comments »

I’ve been working with a lot of new developers lately and have noticed that there’s a lot of useful keyboard shortcuts in Visual Studio that I never bothered to learn. Now I always stick with the default configuration unless it’s absurd or something I really like (for example turning hard corded strings yellow) because customisation doesn’t propagate.

Read the rest of this entry »


Best Hack

Posted: April 15th, 2009 | Author: admin | Filed under: code | Tags: , , , , , , , | No Comments »

I was just thinking what my best hack has been and I think it’s the fix for the following scenario.

I was refactoring the RSinteract source code to get rid of some duplicated classes that had over the course of a, shall we say, rigourous development schedule got disparate. Some classes were used from one set some from the other. I merged them into the common library and deleted all the old ones. This was fine until we ran an old report that had filters on it. Because the types had been serialized into the custom RDL of the report they had the old namespace stored there. Which threw an error when deserializing with the new hierarchy.

So what to do… I had a brainwave:

   1: using System;
   2: using System.Collections.Generic;
   3: using System.Text; 
   4:  
   5: namespace Ics.Reporting.Data
   6: {
   7:     [Serializable]
   8:     public class Dimension : Ics.Reporting.Common.Data.Dimension
   9:     {
  10:         //Proxy class to fix issues with old reports containing a reference to this class which has
  11:         //been moved to Ics.Reporting.Common.Data.Dimension
  12:     }
  13: } 

The empty proxy class in the old namespace that inherits from the new class. Leave a comment as to why. Et voila! No more broken old reports.

What’s your best hack imaginary readers?


Hacking My Life

Posted: April 2nd, 2009 | Author: admin | Filed under: code, personal | Tags: , , , , | No Comments »

I’ve been in a bit of a slump recently. Life is good, but my personal development has been suffering due to my active social life and burgeoning fitness addiction (more on that later). I always feel a bit down when I’m not running at full revs on my personal development.

So what am I doing about it. Well I have a plan. A learning plan and a structured one at that. I’ve still been reading blogs and keeping up with the newest tech as much as I can but I find this doesn’t really give me that much. The plan then, is:

1. Reduce intake of useless blog information
2. Stop procrastinating on music, cartoons, youtube
3. Make a spread sheet for each topic to learn
4. In each spreadsheet put between 1 and 10 things to learn about the topic ending in a specific goal
5. Complete at least 5 items per week.

learning spreadsheet

learning spreadsheet

Simple plan, but is it going to work?

Last night I started writing a WordPress Theme for the first time, and I started getting excited again.

The first step was to mock it up and I discovered can still write a decent looking 3 column layout in pure CSS. The next step is to come up with a pretty design in Photoshop, something I’ve never done before!

Other topics I’m looking at are:

  • Revisiting ASP.NET MVC
  • Design
  • F#
  • WPF
  • TDD
  • PHP
  • Some Misc topics that I’ve wanted to do such as writing a Ubiquity command
  • Guitar
  • French

There’s also a couple of side projects on the go at the moment which are helping to drive this.

Watch this space for a new theme with my name on it!


Improving in 6 minutes

Posted: February 24th, 2009 | Author: admin | Filed under: code, personal | No Comments »

Just read a post over at secretGeek on how to become a better programmer in 6 minutes. Leon explains a few quick activities that you should do to improve yourself.

My favourites are:

2: Make hard-coded strings look ugly.

I learnt this from Joe Cooney.

Go to your favourite IDE, and set it so that literal strings stand right out — for example a yellow background with a red font. Make ‘em ugly. Damn ugly. This will encourage you to perform less hard coding, and to notice when you are embedding strings in your text.

3: Pick an ‘obscure’ keyword and master it

Do you fail to yield?. Is there a keyword you never use?

Every keyword has a purpose. Learn to master those mystery keywords and your powers will become extraordinary.

Here are lists for a few .net languages: C#, VB.net, F#.

4. Increase code-coverage by 1%

Don’t kill yourself striving for 100% coverage of code with automated unit tests. But take a few minutes to increase your coverage by 1%.

Most likely, that means going from 0% to 1%. And that’s the biggest improvement of all.

Find a particularly ghoulish regular expression. Or a critical piece of business logic. These things can’t be trusted without tests.

7. Pick an ugly method to refactor

You know the method. That method you’re particularly ashamed of. That one that’s long and ugly and horrible. And it’s crucial to the whole application.

You don’t have to polish it from a turd to a diamond, but just neaten it up a little. Rename a variable. Hoist part of it out into a separate method. Start simple. The momentum will increase. Watch out.

These are all great little things you can do in those little time pockets where you’d usually just randomly click on stuff until an email comes back or someone responds on IM. I’ve got one more to add.

Automate a process
You know that thing that takes a few minutes and you sometimes have to do twice because you miss a step? You know the ones I’m talking about! The little oddity in your build, or that annoying service/api project, editting a version number for the latest build and putting it back into source control. Well, honestly you could probably do it with a script that you could write in under 6 minutes. I just wrote one to build and install a service for debug:

   1: @ECHO OFF
   2: CALL "C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
   3: msbuild "C:\Development\Solutions\Solution.sln"
   4: installutil /u "C:\Development\Solutions\Soution\bin\Debug\Soution.exe"
   5: installutil /username=IOC-DEV-UK5\Administrator /password=*** "C:\Development\Solutions\Soution\bin\Debug\Soution.exe"

Now I can get my service ready for debug in 1 click rather than openning the Visual Studio command prompt, typing in the folder structure, realising I’ve forgotten to do "Run as administrator" every bloody time!

You’ll be amazed how much time you save and the satisfaction you get from solving a little problem like this.


Experiences with Unity

Posted: February 18th, 2009 | Author: admin | Filed under: code, personal | Tags: , , , , , , , , , | No Comments »

I’ve been very busy over the last few weeks. The new RSinteract beta is due out at the end of this month (several clients are currently using it with no problems) and it looks sweeeet! Pretty proud of my contribution to that particular project and kind of sad that I’m no longer working on it. I’m now involved on a new project involving a certain sporting event taking place in 2012. It’s quite exciting and I’ve been given a fairly important part of the architecture to work on.

Finally, lots of new technology and challenges to overcome for me. One of these is dependency injection using an IoC container. I’ve worked on projects that have used it them and have understood the general principles but never have I had full control of it – it’s always been there already. This time I’m learning it properly myself. The technology that has been chosen is Microsoft’s Unity 1.2 which ships with the Enterprise Library 4.1 (Oct 2008 release). At first glance Unity appears overly complex because the documentation for it is – as Microsoft love to do – overly complicated and tries to show you everything on one page. For example:

   1: <?xml version="1.0" encoding="utf-8" ?> 
   2: configuration>
   3:  
   4: configSections>
   5:  <section name="unity"
   6:            type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
   7:                 Microsoft.Practices.Unity.Configuration, Version=1.1.0.0,
   8:                 Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   9: /configSections>
  10:  
  11: unity>
  12:  
  13:  <typeAliases>
  14:  
  15:    <!-- Lifetime manager types -->
  16:    <typeAlias alias="singleton"
  17:         type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager,
  18:               Microsoft.Practices.Unity" />
  19:    <typeAlias alias="external"
  20:         type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager,
  21:               Microsoft.Practices.Unity" />
  22:  
  23:    <!-- User-defined type aliases -->
  24:    <typeAlias alias="IMyInterface"
  25:         type="MyApplication.MyTypes.MyInterface, MyApplication.MyTypes" />
  26:    <typeAlias alias="MyRealObject" 
  27:         type="MyApplication.MyTypes.MyRealObject, MyApplication.MyTypes" />
  28:    <typeAlias alias="IMyService"
  29:         type="MyApplication.MyTypes.MyService, MyApplication.MyTypes" />
  30:    <typeAlias alias="MyDataService"
  31:         type="MyApplication.MyTypes.MyDataService, MyApplication.MyTypes" />
  32:    <typeAlias alias="MyCustomLifetime" 
  33:         type="MyApplication.MyLifetimeManager, MyApplication.MyTypes" />
  34:  
  35:  </typeAliases>
  36:  
  37:  <containers>
  38:  
  39:    <container name="containerOne">
  40:  
  41:      <types>
  42:  
  43:        <!-- Type mapping with no lifetime – defaults to "transient" -->  
  44:        <type type="Custom.MyBaseClass" mapTo="Custom.MyConcreteClass" />
  45:  
  46:        <!-- Type mapping using aliases defined above -->  
  47:        <type type="IMyInterface" mapTo="MyRealObject" name="MyMapping" />
  48:  
  49:        <!-- Lifetime managers specified using the type aliases -->
  50:        <type type="Custom.MyBaseClass" mapTo="Custom.MyConcreteClass">
  51:          <lifetime type="singleton" /> 
  52:        </type>
  53:        <type type="IMyInterface" mapTo="MyRealObject" name="RealObject">
  54:          <lifetime type="external" />
  55:        </type>
  56:  
  57:        <!-- Lifetime manager specified using the full type name -->
  58:        <!-- Any initialization data specified for the lifetime manager -->
  59:        <!-- will be converted using the default type converter -->
  60:        <type type="Custom.MyBaseClass" mapTo="Custom.MyConcreteClass">
  61:          <lifetime value="sessionKey"
  62:                    type="MyApplication.MyTypes.MyLifetimeManager,
  63:                          MyApplication.MyTypes" />
  64:        </type>
  65:  
  66:        <!-- Lifetime manager initialization using a custom TypeConverter -->
  67:        <type type="IMyInterface" mapTo="MyRealObject" name="CustomSession">
  68:          <lifetime type="MyCustomLifetime" value="ReverseKey"
  69:                    typeConverter="MyApplication.MyTypes.MyTypeConverter,
  70:                                   MyApplication.MyTypes" />
  71:        </type>
  72:  
  73:        <!-- Object with injection parameters defined in configuration -->
  74:        <!-- Type mapping using aliases defined above -->  
  75:        <type type="IMyService" mapTo="MyDataService" name="DataService">
  76:          <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement,
  77:                                     Microsoft.Practices.Unity.Configuration">
  78:            <constructor>
  79:              <param name="connectionString" parameterType="string">
  80:                <value value="AdventureWorks"/>
  81:              </param>
  82:              <param name="logger" parameterType="ILogger">
  83:                <dependency />
  84:              </param>
  85:            </constructor> 
  86:            <property name="Logger" propertyType="ILogger" />
  87:            <method name="Initialize">
  88:              <param name="connectionString" parameterType="string">
  89:                <value value="contoso"/>
  90:              </param>
  91:              <param name="dataService" parameterType="IMyService">
  92:                <dependency />
  93:              </param>
  94:            </method>
  95:          </typeConfig>
  96:        </type>
  97:  
  98:      </types>
  99:  
 100:      <instances>
 101:        <add name="MyInstance1" type="System.String" value="Some value" />
 102:        <add name="MyInstance2" type="System.DateTime" value="2008-02-05T17:50:00"  />
 103:      </instances>
 104:  
 105:      <extensions>
 106:        <add type="MyApp.MyExtensions.SpecialOne" />
 107:      </extensions>
 108:  
 109:      <extensionConfig>
 110:        <add name="MyExtensionConfigHandler"
 111:             type="MyApp.MyExtensions.SpecialOne.ConfigHandler" />
 112:      </extensionConfig>
 113:  
 114:    </container>
 115:  
 116:    <!-- ... more containers here ... -->
 117:  
 118:  </containers>
 119:  
 120: </unity>
 121:  
 122: </configuration>

(Note this documentation is from 1.1)

Now I’m unit testing from the ground up. I don’t care about most of this stuff. I need the simplest implementation to start with. So all I really need in my config file is: the unity section declaration, a type alias and the container.  Like so:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <configuration>
   3:   <configSections>
   4:     <section name="unity"
   5:                type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
   6:                  Microsoft.Practices.Unity.Configuration, Version=1.2.0.0,
   7:                  Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
   8:   </configSections>
   9:   <unity>
  10:     <typeAliases>
  11:       <!--IService-->
  12:       <typeAlias alias="IService"
  13:                  type="Project.Services.Contract.IService,
  14:                  Project.Services" />
  15:       <typeAlias alias="MockService"
  16:                  type="Project.Mocks.FakeService,
  17:                  Project.Mocks" />
  18:     </typeAliases>
  19:     <containers>
  20:       <!--Service is Mocked-->
  21:       <container name="UnitTest">
  22:         <types>
  23:           <type type="IService" mapTo="MockService" />
  24:         </types>
  25:       </container>
  26:     </containers>
  27:    </unity>
  28: </configuration>

That’s it. (Obviously any types referenced here need their assemblies referenced in the unit test project). Why isn’t there a good tutorial that points this out? It seems like Microsoft tripping themselves over again. I’ve found this with other parts of the Enterprise Library too. Thank god for StackOverflow!


Redirecting STDERR to STDOUT

Posted: January 7th, 2009 | Author: admin | Filed under: code | Tags: , , , , , , , | No Comments »

I like to post things that I just learned so here’s a good one. Some batch commands output their errors to the STDOUT and/or STDERR by default. If you’ve got a long batch script this can cause an issue because the output is lost due to the command line truncating the output.

Now most people know about redirecting the output to a file like so:

   1: command -option arg > commandlog.txt

However, this is only handling STDOUT, most commands will put error information (which is what we’re most interested in) to the STDERR. So how do we get at that?

Well to log both do this:

   1: command -option arg > logfile.txt 2>&1

The final token there redirects STDERR to STDOUT, thus putting it all into logfile.txt.

You can also log to seperate files if you like.

   1: command -option arg 1> stdoutlog.txt 2> stderrlog.txt

That concludes today’s lesson. I hope you find this useful at some point!

Good times.


Playing with dynamic styles in IE and the Dev toolbar

Posted: December 19th, 2008 | Author: admin | Filed under: code, web | Tags: , , , , , , , , , , , , , | No Comments »

Ever wanted to isolate just one element and mess with the style after it’s been generated with javascript? It’s always been a bit of a tall order with Internet Explorer due to the lack of Firebug and the unrealistic results when using IE developer toolbar to change styles. However, the latter tool does have a feature which allows you to save the element outside of the page with all styles copied, even if they were generated by javascript! Awesome.

You will need: IE, IE dev toolbar

Here’s how:

  1. Load up your page step1
  2. Open the dev toolbar and select the element using the aptly named element selector or in the DOM tree
  3. You will see all the styles in the developer toolbar.
  4. Right click the element in the DOM tree and selected Element source and style
  5. A new window will open with the HTML for the element, nicely formatted step2
  6. Click File>Save>Original HTML Source
  7. Save the file where you want

Now you have your element with all the CSS that was applied to it in the main page in an external file to play with at your leisure!

step3

[The pictures are from RSinteract, a product I am working on.]

Enjoy!


All Aboard the Test Driven Express

Posted: September 22nd, 2008 | Author: admin | Filed under: code | Tags: , , , , , , , | No Comments »

Recently I’ve been following the great store front tutorial for ASP.NET MVC. To begin with it’s actually a tutorial about patterns and the new features of .NET 3.5 such as LINQ to SQL. In this respect it’s a great place to start learning to create .NET web applications. Rob Conery’s brisk but explicit style is excellent and really keeps you interested. I highly suggest any developer watch this series. Read the rest of this entry »


Pushing for Change

Posted: September 17th, 2008 | Author: admin | Filed under: code, rant | Tags: , , , , , , , , , , | 3 Comments »

In a the constant rush of new techniques in the development world it’s hard for us (and by us I mean working developers) to keep up with everything. That is the point though, you don’t have to. Not everything we learn will be ultimately useful to us. I learned “awk” in university but I’ve never used it. However, this doesn’t mean we can be complacent either! I want to learn about the latest developments or I feel like I’m losing my grip on my skills, personally I think that’s a trait of all (hmm – ed) developers. Granted, I’m sometimes a little behind the crowd (I didn’t touch .NET until 2005) but that’s neither here nor there.

Read the rest of this entry »


Ideas, Motivation, Goals and Fish

Posted: September 12th, 2008 | Author: admin | Filed under: code, personal | Tags: , , , , , , , , | No Comments »

Lately, I’m finding it hard to get excited about work. What’s that I hear you cry? No one gets excited about work! I’m not just talking about work to get paid I’m talking about work for fun, work in your spare time. This may be just post-travelling wind down, but it feels deeper and I think I know what the problem is: I have no goal. Without a goal you’re just treading water and that doesn’t get you anywhere.

Read the rest of this entry »