Thursday, 21 August 2008
Simian - A Copy and Paste Code Hunter Killer!
I have already been making good use of NDepend and Resharper to assist with refactoring, and still have hopes that we will invest in Ants Profiler, but I was missing a tool that would nicely identify for me where copy and paste coding might have occurred. After a little Googling I discovered Simian.
This great little command prompt utility will analyse a Visual Studio solution and spot instances of the same code existing in multiple places. It was really simple to integrate in to the Visual Studio IDE and will make a big difference to my team going forward. Now when working on a piece of code we can quickly check to see if it exists else where and refactor accordingly. This new visibility is going to be invaluable as we move forward and attempt to bit by bit pay back the technical debt.
I found a great blog post by a chap from Conchango that showed how to integrate it with Visual Studio, but in the end I mainly just used the, plenty good enough, documentation that ships with it.
The line that I am currently using to have this tool scan my solution is:
-formatter=vs:c:\temp\buks_simian.log -language=cs $(ProjectDir)/../**/*.cs $(ProjectDir)/../**/*.aspx $(ProjectDir)/../**/*.js
What this does is:
-formatter=vs:c:\temp\buks_simian.log (specify that the output should be dumped to a file on my C drive and formatted for Visual Studio)
-language=cs $(ProjectDir)/../**/*.cs (specify that the all the files that are children of the parents of my current project directory should be searched (this is recursive thanks to the /**/))
$(ProjectDir)/../**/*.aspx $(ProjectDir)/../**/*.js (like above but also look at the aspx and js files too).
The reason why I am starting from the ProjectDirectory and then going up a level before initiating a recursive scan, rather than just using the Solution directory is that my Solution files live outside of the structure of the projects, ensuring that they don't end up source controlled.
Wednesday, 6 August 2008
SQL Server 2008 is RTM!
So SQL Server 2008 has finally made it to RTM. I can't wait to get it installed and to start seeing how the features look now, and how the performance compares. They're available now on MSDN and TechNet.
So there they are, although I don't seem to be able to download the Developer version yet.
Expect blog posts on this before long...
Wednesday, 30 July 2008
.NET 3.5 Microsoft Courseware with IEEE Computer Society
I've done a few of the course they provide before including the Certified Ethical Hacker course, and a bunch of .NET ones. The only downside with the .NET ones is that (at least last time I did one) you don't get the virtual labs, you do get the exercises though so you can setup your own machine and work through them anyway. There are bucket loads of courses available to memebers on .NET, Java, Databases (SQL Server 2000, 2005 and Oracle 8 and 9i), Cisco, Adobe, business skills, IT Security, SharePoint (WSS and MOSS) and lots, lots more.
So if you're not an IEEE Computer Society member and you're thinking of doing any self-paced at home IT courses then I'd recommend joining because for the cost of buying one of these courses from Microsoft you can have a years membership, a great magazine (Computer) every month, and lots and lots of free courses!
Oh and well done to Microsoft for supporting IEEE Computer Society members in this way.
Monday, 28 July 2008
Resharper 4 Bug with 'Use Format String'
But...
I've come across a small bug in Resharper 4.0 today, so I thought that I'd share so that others become aware.
Real code has been changed to protect the innocent (and because it belongs to my employer).
Start off with a StringBuilder.Append statement that uses the '+' operator to concatenate a string with an object. Why an object, well because that's what the code I'm working with has, not ideal, but that's working with legacy code for you sometimes.
Of course, using the Append statement with string concatenation isn't ideal practice either and what I'd like is to change it to an AppendFormat call. Now Resharper makes this very, very (seductively) simple.
Here's my example code before I let Resharper do its' thing:
Here's Resharper offering to do its' thing:
Here's the code that results:
The important line to note is that we now have:stringBuilder.AppendFormat("{0} likes Resharper.", (object[])canBeCastToString);
Note the unnecessary cast to an object array. Because of this we now get the error:
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Object[]'.
The solution is just to get rid of the superfluous cast to Object[].
I still really, really like Resharper 4.0.
Saturday, 19 July 2008
You Grok What You Eat
Following on from conversations that I've had with various people recently it has struck me, and its' not a revolutionary thought, that my practice, and my thinking about my practice, is intimately linked to the feeds I subscribe to, the books I read, the events I attend, the people I chat with, and my work. So, as I finally got around to adding my ALT.NET Geek Code, I thought I'd write a short blog focusing on the feeds I subscribe to and some of the more influential (on me that is) books I have read in the last couple of years.
With feeds I of course subscribe to those of friends (see right) and I won't list them again as they are always present on this site. I'll start by giving a special mention to my two favourite blogs.
Ayende @ Rahein's blog has to be top of my list, his blog is a pure goldmine of ideas and inspiration and I'd thoroughly recommend his Hibernating Rhinos series if you haven't seen it.
Next up, Scott Gu, always interesting to see what MS is coming out with next.
After these two, here's the rest:
- CodeBetter.com (it does what it says on the tin);
- Udi Dahan (great for design insights, esp. SOA) ;
- Object Mentor (TDD, XP, OO, SOA, and more from great thinkers);
- Scott Hanselman (all your ASP.NET desires and quite a bit more);
- Jeff Sutherland (a scrum founder);
- Jon Skeet (C# but other languages too);
- InfoQ (great for keeping up with what's going on especially as it gives a personalised feed);
- Roy Osherove (TDD);
- Simple Talk (general .NET and SQL Server + some practices)
- Bob Beauchemin (Sql Server, also Linq & EF stuff)
- Sebastien Lambla (ALT.NET goodness)
- Eric Lippert (C#, need I say)
- Threads watched by the Channel 9 team (what it says)
- Mir.aculo.us (Scriptaculous and Prototype stuff mostly)
- Mike Taulty's blog (new .NET stuff)
- The Moth (he has a blog apparently)
- Microsoft Research Headlines and News (what it says)
- Derik Whittaker (Alt.Net goodness)
- Devlicio.us (A collection of bloggers on .NET world stuff)
- Rick Strahl (ASP.NET, jQuery)
- Mike Hadlow (ALT.NET in particular TDD, Windsor, MVC.NET, LINQ and more)
- In Recovery (Sql Server)
- NotGartner (If the name wasn't appealing enough...)
- US ISV Developer Evangelism Team (keeping up with the wider MS world from a developers vantage)
- Rebecca Wirfs-Brock (OO stuff)
- JavaBlogs (what it says)
- Christian Shay (Oracle and .NET - yes I do have to deal with non-MS stuff)
- Tony Rogerson (Sql Server mostly - doesn't deserve to be last!)
For books the list is a lot shorter.
First up comes Object Thinking. I just loved this book and will happily rave about it to anyone. Having originally read Social Anthropology at university and then gone on to do a masters in social science research methodologies reading this book brought together for me a number of thoughts that had been swirling around in my mind about the potential importance of insights from Anthropology, Sociology and other social sciences that are rarely given any attention in computing. In fact when I read it, I read it as much as a anthropology of the practice of software development as a book that gives great concrete guidance on the practice of software development. It wasn't until going to a great talk by Alan Dean at the Southampton NxtGen that I realised I had probably missed a lot of what the author was actually trying to communicate. I fully intend to reread it before too long in the light of Alan's talk.
Next is 'Domain Driven Design' by Eric Evans. A fantastic book that has really changed the way that I try to design and code software. Putting it here is almost as much of a cliche as citing Scott Gu's blog but to ignore it would be to not mention an important part of my diet. I actually came to read it as it had been used so much as a counterpoint in Object Thinking's sometimes quite duological arguments.
Agile Project Management with Scrum by Ken Schweber. The first scrum book that I read. Easy to read, every page is worthwhile.
C# In Depth by John Skeet. I haven't quite finished this yet but I'm going to give it a mention anyway because already it is the best 'code' book I've read to date. A lot of coding books that I've got and read have really frustrated me because they all seem to cover the same old, same old ground every time. Jon's book is focused on C# and avoids being drawn in to the framework which is fantastic because the last thing that I'd have wanted is another book with another chapter on ADO.NET, ASP.NET, databinding, etc... I saw Jon give a talk on C# a while ago and for me it was the best technical talk I have ever attended. He involved the audience and I left feeling that I had really learnt something. This book is almost as good as his talks.
If C# in Depth was a book that I hadn't finished reading then the next book is a book that the authors haven't finished writing! 'Brownfield Application Development in .NET' by Kyle Baley and Donald Belcham is, so far, great and represents everything that I am trying to achieve in my job at the moment. I can't wait for the later chapters to be released and would recommend it to anyone who has to transform not just a poorly designed and coded piece of software, but the practices and patterns of a team also.
Other books worth a mention include the GoF Design Patterns, CLR via C#, Object Oriented Software Construction, The Knowledge Creating Company, The Object Primer, Being Digital (now that's going back some).
So where does this diet lead me? See the ALT.NET geek code on the right.
Thursday, 19 June 2008
Resharper 4.0 and Lambda Expressions
Now I'm fairly new to the wonderful world of Resharper, so barely a day goes by where I don't discover something new about it, or through it. But today I found a feature that just made me want to share about it straight away.
Let me set the scene.
I'm coding a Lambda expression for use as a predicate and when finished I notice the now familiar little light bulb. Hmmm I thought, now what could Resharper be wanting to tell me about my code?
(real code replaced throughout to protect the innocent)
That's right Resharper is offering to convert my Lambda to either an anonymous method or a statement! So let's see what it does to the code if I choose these options.
Well If I choose the option 'Lambda expression to statement it turns my code into this:
Note with this option I am given the choice to now convert on to an expression, or to an anonymous method.
If I choose the option 'To anonymous method' my code looks like this:
Note that it is offering to convert my code back to a lambda
If I choose the 'Lambda expression to anonymous method' option and place the caret in to the delegate keyword then I get a different option however.
This time the options include one to convert my anonymous method to a named method. Choosing this does what you will no doubt expect. It creates named method.
private static bool NewPredicate(Person p)
{ return p.Name == "Sue"; }
and changes my code to read:
Person sue = people.Find(NewPredicate);
Actually I added the prefix new, as Resharper just put Predicate, but you get the idea. Of course, Resharper now gives me the option to inline my Predicate as either an anonymous method, or as a Lambda.
Neat huh!
Choosing to inline as an anonymous method acts as I would expect, and puts the code back to be the same as the anonymous version above. Choosing to inline as a Lambda however a have a tiny, tiny gripe with.
As you can see above, Resharper has placed the target variable within brackets. Still, at least Resharper knows that it shouldn't have done this, as it offers to remove them!
What I really, really like most about this, and made me want to blog about it, it that it very neatly highlights some of the evolution of C# from version 1 with its' named delegates (though of course we didn't have delegate comparisons then), through version 2, with its' anonymous methods, through to the current version 3 with its' Lambda goodness.
Thursday, 12 June 2008
NxtGenUG Fest '08
Just got back from an excellent day attending the NxtGenUG Fest '08 at Microsoft's campus at Reading.
Like all NxtGen related events everything was smooth and incredibly well put together. I enjoyed all of the talks and some of them have definitely inspired me to go and hit the computer for a play.
Mike Taulty's talk on ADO.NET Data Services was an excellent and engaging introduction to this feature that will be properly released with the forthcoming .NET 3.5 Service Pack 1. The technology seems very seductive, and I will try and find some time before long to have a play with it but it seems very data driven to me and the implications of this if the technology was to be deployed much beyond a simple demo app concerns me a little. Still, until I look into it properly that's just a gut reaction and may well be wrong.
Daniel Moth gave a short talk on Parallel Linq which looked very interesting and this is something that I will definitely be looking into before long.
Dave Morrow gave a really interesting talk on providing BI using SQL Analysis Services, Proclarity, MS Performance Point and SharePoint (WSS 3). The world of BI (business information) is not one that I know particularly, but this talk has really gotten me wanting to have a play with these tools. It'll stretch the limits of my hardware (even with VMs) to get the necessary environments setup to play around sensibly with this stuff but I think that I'll enjoy it and it'll be worth it. One thing that I wondered watching this demo was whether I could bring SPSS (a statistical analysis package I used during my MSc) to the party and get some even more interesting information out of this mix. No doubt I'll blog about this when I've looked into it, and had a good play, some.
The talk that most interested me however was Oliver Strum's talk on F#. I can't overstate how interesting and well delivered this presentation was in my opinion. I'd been wanting to look into F# for a few months now without ever getting around to it. Oliver's talk has made this (along with my continued playing with Spec#) the new big priority for my personal R&D time. I'd heard/read that F# would be a good tool for writing business rules engines, but had been leaning toward doing this with a Boo based DSL. This introduction to F# is making me think that I really need to look into this before I make that decision. I suspect also that, as an added benefit, a play in this space will do wonders for my use of Lambda expressions in C# too.
Of course the day was not just about the great speakers (they were all great, not just the ones that I've highlighted), but like any NxtGen event it was also about the pizza, the swag. I got, amongst other things, a free copy of the full DevExpress software (no that's not why I'm so full of praise for Olivers' fantastic talk), and some Microsoft 'Heroes' chocolates. Beyond all of that though the chance to meet and chat with former colleagues (great to see such a large number from Immediacy) and other NxtGeners (great to see so many from the Southampton branch) really made the day. Congratulations and thanks to Dave, Rich and John for another brilliantly hosted and put together event.
Now I just can't wait for DDD 7 (which, incidentally, I have just submitted a proposal for a Grok talk on Design by Contract and Spec# for).