May 2003 - Posts

Designs, testing secured code with nUnit and a book review
My current project is finishing the design phase this week. Our leads are insisting that we design to a low level, including method signatures for business objects, the database layer and the stored procedures. We have been iterating the designs extensively and they are becoming very detailed. I've learned a ton about my functional area and will now be able to easily write the code. As I understand it, the rationale behind extensive upfront design is that changing the code is much more expensive than changing the designs. With modern tools this is becoming less true. I can change a method signature and callers in VStudio as quickly as I can update a Word document and fix up the Interaction Diagrams in Visio. My recent projects have been 2 or 3 developers using an Agile process, this one is 10+ developers.

If you need to use nUnit to test code that is protected by .NET security, you need to provide a Principal to the nUnit thread. For example,
   // This principal will be used throughout the tests
   Thread.CurrentPrincipal = new GenericPrincipal( new GenericIdentity("TedsTester"), new string[] { "DeleteEverything" } );


[What I'm reading: Effective Java Modeled after Scott Meyer's incredible Effective C++ books, this manual of Java best practices should be required reading for C# developers. Joshua Bloch is an architect on the Java class libraries and this book is filled with the knowledge that comes from years of use. C# is quite close to Java and most of the tips in this book apply beautifully. Especially good for C++ developers moving to C#. In 5 years someone will know C# well enough to write an equivalent book, but this one will help you code better while we wait. (I'm an Amazon affiliate, all monies will be matched and donated to a homeless shelter in southern Colorado)]

Output params from stored procs using MS Data Access Application Block

As my current client is early in the architecture phase, I’ve been reviewing the MS Data Access Application Block. I did a brief experiment, and I’m having problems retrieving output parameters from stored procedures. I created a simple stored proc (with CodeSmith):



[Edit: I just debugged this with one of the MS Consulting Services Architects on this project. There is a bug in the Data Access App Block that causes this problem when you call methods that take an array of objects that hold your parameter values. Calling the overload that takes a SqlParameter array works fine.  He wasn't real suprised that there are problems with the DAAB.]

[Edit2: Bill Selznick's comment is right on.  Most of the people that mail me about this problem are calling the wrong overload of ExecuteNonQuery.  Step into the DAAB and make sure you are calling the overload that you intend to.]

 

CREATE PROCEDURE dbo.InsertValidationPolicy @Severity int, @Message nvarchar(50), @Required bit, @ValidationPolicyID uniqueidentifier OUTPUT AS SET @ValidationPolicyID = NEWID() INSERT INTO [ValidationPolicies] ( [ValidationPolicyID], [Severity], [Message], [Required] ) VALUES ( @ValidationPolicyID, @Severity, @Message, @Required ) GO 

And created a simple data access object with static methods (doing the prototype before I build the CodeSmith template). The below method calls the stored procedure to create a new object. Notice the fourth parameter is an output parameter, and that the stored procedure is executed using SqlHelper (the main component in the Data Access App Block).
 static public Guid CreateValidationPolicy(int severity, string message, bool required) { SqlParameter paramSeverity = new SqlParameter("Severity", SqlDbType.Int); paramSeverity.Value=severity; SqlParameter paramMessage = new SqlParameter("Message", SqlDbType.NVarChar); paramMessage.Value=message; SqlParameter paramRequired = new SqlParameter("Required", SqlDbType.Bit); paramRequired.Value=required; SqlParameter paramID = new SqlParameter("PolicyID",SqlDbType.UniqueIdentifier); paramID.Direction = ParameterDirection.Output; SqlParameter[] parameters = { paramSeverity, paramMessage, paramRequired, paramID }; SqlHelper.ExecuteNonQuery(ConnectionString, "InsertValidationPolicy", parameters); return (Guid)paramID.Value; } 

This method throws an Exception complaining that, “Object must implement IConvertible”. It works fine if I don’t use output parameters. There are several threads discussing this problem in the newsgroup dedicated to the MS Building Blocks. The best discussion was started by Jim Bentley on 2/27/03 (sorry, but I don’t know how to link to news threads) and includes some responses from Microsoft, but no solutions.

Ted
Stored Procedures vs. ???
Commenting on my blog entry about generating data layers Jesse wrote, "I don't think entity broker supports stored procs, but they suck anyway" and Frans agreed, "In the next version of LLBLGen I will not generate stored procedures either, just code which at runtime generates an optimized query especially taylored for the situation." This is the first I've read about the move away from stored procedures. I recognize the problems with handcoded SQL statements in the code, but I thought there was agreement that stored procs solved many of these problems. Can someone explain the reasoning behind these statements?

This is my first blog and I'm not sure when I should be asking in the blog and when I should be posting on a forum. Opinions appreciated.

[What I'm reading: Applied Microsoft .NET Framework Programming I read this for the first time last summer and it remains the best .NET book I've read. This is the definitive look into the .NET framework. You'll need other books on Web Forms, Windows Forms and Web Services, but understanding this one will change the way you program. Wow!]

First post leads to first retraction
Roy (a fellow blogger) wrote, "Interesting! Can you write some of your experiences about working XP style? There aren't that many of us practicing it... :("

I haven't been doing pure XP. My last two projects have been done with a partner and we used just enough methodology to get the project done predictably. Of the 12 tenets of XP, we used OnsiteCustomer, PairProgramming, TestDrivenDevelopment, ContinousIntegration, RefactorMercilessly, SimpleDesign, CollectiveCodeOwnership, CodingConventions and SustainablePace. We didn't do PlanningGame, SystemMetaphor or SmallReleases. We didn't have an XP coach and didn't involve our customer in feature prioritization as much as we should have.

A negative observer might have called our process HackAndSlash. For two experienced developers who work together comfortably, pair programming and lots of nUnit tests keep things in good shape. The Wiki I linked above is a great place to learn more!
Bug tracking systems, are they that fun to write?
It seems like most software shops write their own bug and issue tracking solutions. As a consultant, I see lots of projects and a surprising number use a homegrown solution. I just got out of training on my current client's system and it has so many gotcha and special behaviors that the demonstrator made several mistakes. I've always wanted to use FogBUGZ but I've never had the chance. Do you have a favorite system?
Generating data layers and testing the results

From initial discussions of the technical architecture I think we are planning on handwriting all the stored procedures and the data objects that wrapper them. I'd much rather use LLBLGen or another data layer tool to automate this, but it may not be my decision. I'd love to hear anyone's experience using data layer tools. Ideally I'd like round-trip generation, but could consider generating the initial objects and maintaining them by hand. I read the Great Data Generation Layer Debate with interest, but it was a discussion of different tool styles instead of first hand reports on using the tools. Regardless of how we build the data layer, I'd like to use nUnit to test it. I've had great experiences with nUnit and many of the consultants agree, but the MCS architect I discussed it with thinks writing the tests will slow us down.

[What I'm reading: The Things They Carried A series of brilliantly written short stories about the adventures of a squad in Vietnam. I read it in a day, but it would make a great bedside book if you want to read 15 minutes a night.]

First post as I start a new project
I started a new project last Thursday; it is an interactive website for a large client. There are two Microsoft Consulting Services architects running the project, half a dozen outside consultants and another six or seven client employees working as functional architects, team leads and developers. MCS has been here for 3.5 weeks already and they already have a solid development process in place and a good logical design describing the system functionality. My last couple projects have been XP style with a partner, so I'll have to adjust to having more paperwork and process.
More Posts