Archives / 2007 / June
Reviewing The Mythical Man Month
In my first job out of university my assigned mentor Alex always had a copy of The Mythical Man Month on his desk. He urged me to read it and said that the world would be a better place if everyone in charge of projects had read it.
That was almost six years ago, and I've just got round to it. I went through a period after uni where I'd had enough of reading text books. I've recently felt quite a strong urge to learn more, and this book seemed like a good place to start.
The author Frederick Brooks talks from his experience of working for IBM in the 1960s. In some ways this book is timeless. The fact that it is still highly recommended is proof to that.
If we don't learn from the past then we'll never move on. This book talks you through the many hidden pitfalls of software development. Most of these are still relevant today and many of them I would never have thought about if I hadn't read this book.
In some ways though the book shows its age. However, the historical aspect that it provides is fascinating and still very worthwhile. The material added in the second edition brings a lot of this into perspective and was my favourite part of the book.
This book alone is not going to bring you up to date with modern programming practice. However it's a great introduction and helps you start asking all the right questions.
Sending a list into an SQL stored procedure using XML
I wanted to pass a list of user IDs into a stored procedure. What I really wanted was to be able to pass an array, but you're not able to do that because it would be too easy. It took me quite a while to figure this out, but now I know how, it'll be easy next time.
There's a nice set of functions that allow you to get values from an XML string and treat the set of values like a table. Just what I wanted from arrays really.
Here is the XML string that I used:
<users><user id="24" /><user id="27" /></users>
And here is the relevant part of the stored procedure I made:
CREATE PROCEDURE pXmlTest
-- Parameters
@xmlStr varchar(255)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @xmlHandle int;
-- Prepare XML document and get a handle for it
exec sp_xml_preparedocument @xmlHandle OUTPUT, @xmlStr;
-- You can now use the OPENXML function which returns a rowset that behaves like a table
-- WITH chooses the field names you want to use from the XML and declares the type they will be.
SELECT * FROM tUsers WHERE id IN
( SELECT id FROM OPENXML(@xmlHandle, '/users/user') WITH (id varchar(50)) );
END