Adventures of a wannabe geek!

Ranting within

Enum String Value With JQuery Mobile

A while back I had to use JQuery mobile for a project. The project needed to have 2 themes on an application and the configuration would need to tell the application what theme to load. With JQuery Mobile, the theme string could only be a single letter. I like keeping to decent and meaningful naming conventions, so I created a configuration setting as follows:

<add key=”Theme” value=”Plain” />

I could see easily that the theme for this build of the application is the Plain theme. How could I relate that back to a JQuery theme? Plain would not be acceptable with JQuery Mobile. Therefore I had to do something different. I was able to use an attribute on the Theme Enum:

I then overrode the WebViewPage to include logic to get the Theme as follows:

As you can see, I have an extension method in place to get the string value of the enum. This then taps back into my String attribute as follows:

This then allowed me to turn a simple readable string from a web.config, into something that JQuery Mobile could understand and parse as normal

You Think I’m Doing It Wrong, So Help Me Do It Right

I am fed up with reading more and more posts, mostly on twitter, telling me I’m wrong if I’m doing it this way or wrong if I’m not using this tool. Who gives you the right to tell me I am not correct? You do not know my problem space, domain or the criteria I need to work towards.

I have to say that this post is not in retaliation to anyone telling me I am doing something wrong. It is based towards all the posts titled ‘You’re doing it wrong….’

In my opinion, we are continually learning in this industry. Something you may be good at now, may not be the hot topic in 6 months time. I am not sure there is a single person who knows *everything*. You may have your niche of expertise and you may be able to help but be constructive. If you really think I am doing it wrong, then give me reasons why so and point out the flaws in my way. It isn’t black and white. This is not a math problem – there may be more than 1 way to do something.

I do a lot of speaking to groups about continuous integration & delivery. There is no way I would tell someone they are wrong. Instead, all I can do is to put the reasons out there for my way of doing something. If the person takes this on-board then that’s fantastic. If they don’t, I won’t get offended. Maybe we should focus on helping the devs who are supposedly doing it wrong rather than pointing that almighty finger at them. Who knows, you may even learn something yourself.

</rant>

Spoofing the Host Entry in a HTTPWebRequest

I had this idea to create a dashboard that would ping different version of a site in order to get the build number. The details are as follows:

www.mysite.com

runs on a local site at 192.x.x.x, a QA environment at 10.x.x.x, a staging environment at 66.x.x.x, and a live environment at 88.x.x.x (these IPs are made up). In order to hit each site, I would usually manually change the host file and then make the web request. This was not a great solution as I hate dealing with host file entries. On experimenting with HTTPWebRequest, I noticed that you can use reflection in order to change the Headers of the Request. The normal code to create a HTTPWebRequest would look as follows:

I was able to spoof the host by changing the host using reflection:

This allowed me to make multiple requests to different versions of the same site. Using a simple collection of my site objects to build a dashboard that had the following outline:

  Local QA Stage Live
Build Number web_12_4_qa web_12_4_qa web_12_5_stg web_12_4_prod

My Approach to Refactoring a Monster Switch Statement

I had to refactor some very old code a while back. The code looked similar to this:

I had to refactor it so that I could add more parts to it. There was no way I could add in more case statements so it all had to go. I took a cautious approach to the refactoring as it was pretty brittle and quite important code. The first step in refactoring made the code look as follows:

This mean that I could make sure that the function of the code didn’t change but that it was easier to read. This still couldn’t be unit tested though as there was no way to mock the behaviour of the case statements – it was all still in the same class. The next refactoring step was to allow some unit tests to be written. I was able to separate the behaviours into their own class and made the code look as follows:

This wasn’t enough for me. I still had this huge switch statement that was breaking the Open / Closed principle. This meant that in order to add more functionality to the switch, I had to change the switch and risk breaking it. This couldn’t happen. This made my final part of the code look as similar:

With this code I could make sure that I could write some unit tests around the behaviour of the class. This post only talks about going this far. I have since refactored the TaskRunner class much more as it was doing a lot more than 1 thing and thus breaking SRP. How would you have handled the same refactoring?

Custom Blogging Workflow With YouTrack

In the past week, I have started using YouTrack 3.0 in the cloud as a think tank of blog posts that I want to write. Previously I had used Trello. there was no particular reason for moving away from Trello other than curiosity about what YouTrack could offer me. On setting up YouTrack I added a project to start the tracking of the blog posts. On adding the first post, I was given the following state workflow:

image

As you can see, you can pretty much change the state to be any other out of the box. I wanted to use this as the opportunity to create a custom workflow for YouTrack. I was able to download the YouTrack Workflow Editor and start the editor. Hadi Hariri has created a post on the basics of the workflow editor on his blog but this was only to create a stateless rule. I wanted to create a ‘statemachine’ rule. Basically the flow was to be as follows:

- Initially the issue created would be assigned to ‘To Write’

- Issues in ‘To Write’ could be changed to ‘In Draft’

- Issues in ‘In Draft’ could be changed to ‘In Review’ when complete or ‘To Write’ when paused

- Issues in ‘In Review- can be changed to ‘Published’ when closed or ‘In Draft’ when failed review

I immediately got to work and created a new rule as in Hadi’s post but this time I chose a statemachine rule. This gave me the following template:

image

I had to add the first transition. That when initially opened the state would be ‘To Write’:

image

I then had to implement the changes allowed to State from ‘To Write’. This says that when an issue in To Write, the only state it can move to is ‘In Draft’. As you can see, there is a stub of the state for In Draft created now by the Editor. I was then able to say that when the post is In Draft, it can move to In Review when finished writing or To Write when paused:

image

I was then able to implement that when the post is In Review, it could change to Published when verified or In Draft when it didn’t pass review. This gave us the stub for Published. As there were no state changes allowed when published, I just had to leave the Published state empty as shown:

image

After uploading the workflow to the server, as per Hadi’s instructions, I then had to attached the workflow to my project. I went to administration and chose the project type and then the workflow tab, I clicked the button ‘Attach workflow’. This game me the following:

image

I just had to choose the workflow I had created (stack72-blogging-stateflow) and I could then see the transition screens were working as appropriate:

image image image image

This was very easy. I must pay credit to the Youtrack team for such a simple workflow editor. IT has intellisense and was able to offer me all sorts of options on clicking control + spacebar together. Thanks also to Hadi’s post for introducing me to the Workflow editor.

Agile Teams and Working From Home

Yesterday (April 2nd 2012), I posed a question on twitter:

Does anyone think that people working from home in an agile team is a bad idea?

This seemed to be quite a controversial question to pose. My favourite response was “isn’t agile – as long as you get the work done, doesn’t matter home, office, card, no-cards, no??” Now, I can see what the author (@edonsojeva) is trying to say. I agree that one of the main principles of agile is getting work done. But, on the other hand, for me the best principle of agile is the ability to communicate with members of the team *and* the business. IM clients (Skype, Lync, MSN etc.) are a great way to keep in touch. But I have never found them to be fantastically efficient at being able to display the entire picture. When speaking to people I want to see them face to face (where possible). this allows us both to focus on the issue at hand.

when working remotely, people can get distracted. That’s just our nature. It doesn’t matter whether we get distracted by emails, twitter, other IM conversations happening at the same time or TV (yes I have seen this happen to some people), it happens. I find that that level of distraction is less in the office. Why email someone when you can get up from your desk, walk 10feet and speak to them and strike up a conversation instead?

I understand that it can sometimes be very important to isolate yourself just to get a few hours of no distraction. Being at home, with no one round can give you this isolation. My thoughts here are that if you do have so much to do that requires you to be isolated from the rest of the team, that you a) haven’t planned very well or b) are not agile. Team is the key word here. For me working from home takes away that sense of being part of the team. It can just make you feel a little isolated. Architecture and code can be a bit of a beast sometimes. It can therefore take other people to wind in crazy ideas. Unless you are this incredibly focused person, you can sometimes go off in a tangent or with an idea that another has already tried. It can also save time. If you run into an issue, a team member who has been in this situation before can point out a fix.

This leads me to the general idea that working from home is the exception rather than the rule. I wouldn’t be fantastically happy with members of the team who constantly worked from home. They would feel more like remote contractors than anything else. I understand there are incredibly focused individuals out there that can block out all these impediments and work from home efficiently. I am in no way saying that it isn’t possible. This post is merely a scratch pad to get feedback on what others have experienced.

TeamCitySharp Now Builds With Mono

I am pleased to be able to say that TeamCitySharp is now supports mono. In order to get the project supported I had to change a few parts of the system.

Up until now, each project within the solution has a “BeforeBuild” event that downloaded the nuget packages needed to build the solution. This was in place to keep the github repository small enough to facilitate a fast download for people who fork it. Nuget doesn’t work with mono so there was a trade off I had to make. In this instance I chose supporting mono over the “BeforeBuild” event. This does mean that once the repository is cloned or forked. then it will work instantly. I hope to revisit this if / when someone manages to get nuget working with mono.

The sample build monitor was a standard ASP.NET MVC 3 project. I found that this didn’t build with mono out of the box. It was throwing errors due to the references contained. The following references were present:

before

On running a reference analysis, I was able to see that the following references were not used:

ToRemove

This meant that only the core references were left behind. This meant that the entire solution was able to build under mono.

In order to build the project with mono, you can run the following command:
xbuild TeamCitySharp.sln

Installing Mono on Windows

I have recently been thinking about making TeamCitySharp supported on mono. This would require me to either run a VM (that you can download form the mono project site) or install mono on Windows. As I would continue to develop TeamCitySharp in VS2010, I thought it would be better to install mono on windows.

When trying to install mono, I went to the mono project download page and was presented with 3 options for windows:

image

I had no idea what to install & tweeted to that effect. Almost immediately, Rob Reynolds tweeted this back:

cinst mono

This is a reference to chocolatey which I have used before. Chocolatey is described as “apt-get for windows”. In order to install mono I had a number of steps to follow:

1. Set the execution policy of PowerShell to unrestricted

execution-policy

2. Install chocolatey

chocolatey-install

3. cinst mono

mono-install-1

which, when downloaded triggers the install

mono-install-2

Mono is now installed and ready to be used. This was extremely easy using chocolatey. I have used it before to install nodejs but I have to admit I didn’t really pay attention to what packages it contained. I will be doing so from now on. If you have not checked out chocolatey then please do so – it rocks!

How Nuget Could Improve

Late in December 2011, I stuck my oar into a conversation on twitter (as I usually do) between Scott Koon, David Ebbo, Sumit Maitra  and Eric Ridgeway. This conversation was about why Nuget.org was not the best place for a Northwind DB Sample package. My comment was as follows:

@lazycoder @davidebbo @sumitkm @Ang3lFir3 maybe have the ability for codeplex to have a nuget style feed of its own for sample libraries?

I thought I should clarify my thoughts further. Nuget (and OpenWrap) have set the .net world into a new era for dependency management but there are not many enforced rules or moderation of the packages you can upload. For example, I maintain the NUnit package. This means I submit updates to the package when a new version is released by NUnit. I once received a comment on how I should split the package up into just a dll package and then have a full package.I really had to think hard about why I should do this. Who am I to change the way the guys who create NUnit distribute the package. All I do is to get the contents of their .zip and redistribute that – and I do struggle to think how I have the authority to do that sometimes. This led me to a very prudent question:

Is Nuget.org a site that should have strict regulations about the packages that get uploaded there?

I have heard about a few broken packages and actually sample applications. Is this the correct place for these packages to go to?Has it become a dumping ground for software. Sites like codeplex, github and bitbucket are used more frequently for source control. Are these sites the correct areas for the sample applications? I would argue yes. I feel that Nuget should contain only packages that I can download and use immediately. I don’t want to have to download a 12mb sample application when I could view the source in github or codeplex. Maybe a way to take this further would be to set up the ability for nuget to hook into these types of systems:

nuget install-sample <path to codeplex>

This would keep the nuget library free of the packages not deemed useful. Who can classify a package as useful in this theory I hear you say? Well the users of the site, via a stackoverflow style voting system. A broken package gets a downvote, then any packages below –4 (for example) would get archived by the system and the package owner to get notified. There would have to be some sort of moderation of this though or people with rival packages could eliminate the competition Devil

I do believe that uploads to the nuget library should be regulated. There are more than enough people in the .net community that would spend a few minutes a day clearing out / verifying packages. If we regulate the packages then developers will continue to use for nuget. If it continues with the following types of packages then this may not be the case:

NuGet Gallery

The naming conventions of these packages contain the letters ‘–ci’. How on earth can I work out what the different between MvcContrib.MVC3-ci is? Is it a special kind of package for CI use only or was it built with a CI system? This is exactly the issue. Some kind of visual check around this would have stopped – for the record I actually installed MvcContrib before I realised it was not compatible with MVC3 – this should have been noted in the description, in my opinion.

I enjoy using nuget and I really want to continue enjoying it. All we (as a community) need to do is to be respectful of other developers when we create a package. When delivering software to paying customers, do we release potentially untested applications or do we make sure that they work?

$0.02

CodeMash 2012–what an Awesome Event!

This past weekend (January 10th – 14th 2012) CodeMash was held in the Kalahari resort in Sandusky, OH. Yes I know – Ohio in January!! I had been warned that firstly its cold there and secondly there is usually a lot of snow. This time we were quite lucky and only got a little snow. I arrived on Wednesday night after a very long journey and walked into what was just a hive of activity. I have been to a lot of conferences, this one was not only huge but very interactive and social. A lot of the attendees brought their families for the week!

495876401

I was very lucky to have a session accepted for this conference (Introducing Continuous Delivery) and was extremely pleased to know that my session had made it from over 700 applications. I was also lucky enough to have my session early on Thursday. If you look at the schedule, marvel at the level of speakers here and you will see why I was so pleased!

The big thing for me on this conference is that there were a lot of companies there in force. Edgecase and Leandog are the 2 that stick out for me. Edgecase as they were usually in the hot tub drinking and leandog because of those hats Smile. There was also the small matter of a party on Thursday evening after the sessions that actually moved to take over the waterpark between 10pm and 1am. A-Maze-ing! I, in fact, did ‘a Corey Haines’ and smashed my head off the bottom of the pool. At one point on the Friday, Cleveland were trying to get me to stand on the runway as a beacon for the planes to find the runway as it was so red!

a Corey Haines :
  • To injure oneself at CodeMash in the waterpark
  • OMG Dude you just did a Corey Haines – are you ok?
    Oh and the bacon bar – bacon with all sorts of toppings available – from butterscotch to white chocolate.

i4hea

Without the sponsors this event would never have been able to happen. Please do say a thank you – tweet them even! I seen tweets as to the magnitude of the event:

Just picked up cashier’s check to Kalahari for partial conference payment: $330,000. Nice double-take from the cashier when I said amount

Most importantly, I would sincerely like to thank all the organisers. These guys work on this conference while holding down jobs. Its an incredible accomplishment. It was what I would certainly class as the best conference ever. Thinking of 1300 geeks in a waterpark in Ohio in January doesn’t do this event justice at all. It is quite literally a software conference for the entire family.

I met so many cool people – I couldn’t begin to name them all or acknowledge them all! I will certainly be back next year! For now I will have to get over the bacon sweats, keep icing my head from my stupidity and start working on my submission next year!