Daily Developers Wants You!


The Daily Developer site needs your help. We want you to add some content, no matter how small. This site has been set up so that developers like yourself can share tips and experience and help others. The content theme of the site is anything to do with the day to day life of being a programmer. Come on, you know you want to!

Missiles, Money, Cabs

Some time ago I watched Martin Grenell‘s presentation “How to get your Grandmother to Build Missile Defense Systems”, and in it he briefly showcased an application built using the Composite Application Block called CommSee, an internal application written and used by the CommonWealth Bank of Australia. This presentation is downloadable from the PDC 2006 webcast series. [The Composite UI Application Block is a proven framework for creating ‘pluggable’ applications, based on the MVC/MVP composite pattern].

While I was watching his excellent presentation, I thought it would be interesting to find out more about the design and process behind this application. Well Ron Jacobs has done just that over at Arcast. Nice one, Ron!

TechEd 2006 WebCast Series

If you haven’t seen this already, you can download around 140 of the TechEd 2006 webcast and breakout sessions. It never ceases to amaze me how many resources Microsoft offer for free. [They also seem to have streamlined the registration/download process somewhat. Thanks Ron!]

In fact, Dan Appleman (the VB legend) recently commented on this phenomena, mentioning what it was like to develop software back in the mid to late 1980’s, before Google and when documentation was a lot scarcer than it is now!

Microsoft Privacy Guidelines

Microsoft have released a must read, downloadable document Privacy Guidelines for Developing Software Products and Services based on their internal privacy guidelines.

Before collecting and transferring personal information, you, as the entity
requesting the information, must have a compelling business and customer value
proposition. A value proposition that benefits customers may create a
natural incentive for them to entrust you with their personal information.
Only collect personal information if you can clearly explain the net benefit to
the customer. If you are hesitant to tell customers “up front” what you
plan to do with their information, then do not collect their data. This
applies to data collected and stored locally on the customer’s machine or
transferred over the Internet.

Windows Vista Blog Gets a Facelift

Jim Allchin has re-released the Windows Vista blog with more of a ‘Vista’ feel. The previous site was infrequently posted to, and this time Jim is pushing his co-workers to improve the content. If you’re already running Vista, they are looking for feedback.

Better Presentation Tips

Kathey Sierra has posted an article on how to start a presentation, book, article… and as usual it’s worth reading. A few hilights are:

You should not:

  • Start at the beginning
  • Tell, show instead
  • Start with history
  • Start with pre-requisites

You should:

  • Begin with a question
  • Be provocative
  • Evoke empathy
  • Do something surprising
  • Start with something funny
  • Start with a dramatic key event or turning point
  • Have some mystery, suspense or intrigue

The T-SQL Way: Converting Integers to Binary Strings

A post over at Rob Farley‘s blog on converting integers to binary using Transact-SQL caught my eye and it reminded me of a challenge a fellow developer gave me a few years ago, namely that I couldn’t speed up one of the VB functions he had written with the condition that it must still be written in VB. I did, by 3 orders of magnitude!, but that’s another story…

My solution is probably not quite as elegant as Rob’s CTE solution but I reckon it might be faster and use less memory. In fact there are two very similar function based solutions. One is certainly more readable than it’s slightly faster counterpart.

Originally, I used the formula as the basis for a computed column, like so:

CREATE TABLE #t (

intVal int ,

binaryStr AS (

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , (IntVal / 268435456) * 4 + 1, 4 ) +

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , ((IntVal / 16777216) & 15) * 4 + 1 , 4 ) +

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , ((IntVal / 1048576) & 15) * 4 + 1 , 4 ) +

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , ((IntVal / 65536) & 15) * 4 + 1 , 4 ) +

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , ((IntVal / 4096) & 15) * 4 + 1 , 4 ) +

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , ((IntVal / 256) & 15) * 4 + 1 , 4 ) +

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , ((IntVal / 16) & 15) * 4 + 1 , 4 ) +

SUBSTRING( ‘0000000100100011010001010110011110001001101010111100110111101111’ , (IntVal & 15) * 4 + 1 , 4 )

)

);

— Test values

insert into #t VALUES (0)

insert into #t VALUES (1)

insert into #t VALUES (2)

insert into #t VALUES (3)

insert into #t VALUES (4)

insert into #t VALUES (15)

insert into #t VALUES (31)

insert into #t VALUES (65)

insert into #t VALUES (127)

insert into #t VALUES (128)

insert into #t VALUES (129)

insert into #t VALUES (65535)

insert into #t VALUES (65536)

insert into #t VALUES (166754132)

insert into #t VALUES (1073741824)

— int’s are signed, max value is therefore, 2^31 – 1 = 2147483647

insert into #t VALUES (2147483647)

select * from #t

The first function version is:

CREATE FUNCTION IntegerToBinaryString(@intval int)

RETURNS char(32)

AS

BEGIN

DECLARE @bincode char(64)

SET @bincode = ‘0000000100100011010001010110011110001001101010111100110111101111’

RETURN (

SUBSTRING( @bincode, (@IntVal / 268435456) * 4 + 1, 4 ) +

SUBSTRING( @bincode, ((@IntVal / 16777216) & 15) * 4 + 1 , 4 ) +

SUBSTRING( @bincode, ((@IntVal / 1048576) & 15) * 4 + 1 , 4 ) +

SUBSTRING( @bincode, ((@IntVal / 65536) & 15) * 4 + 1 , 4 ) +

SUBSTRING( @bincode, ((@IntVal / 4096) & 15) * 4 + 1 , 4 ) +

SUBSTRING( @bincode, ((@IntVal / 256) & 15) * 4 + 1 , 4 ) +

SUBSTRING( @bincode, ((@IntVal / 16) & 15) * 4 + 1 , 4 ) +

SUBSTRING( @bincode, (@IntVal & 15) * 4 + 1 , 4 )

)

END

GO

This uses a concatenated string of the 4-bit binary string representations of 0 to 15, indexed by the 32-bit input integer broken into 4-bit chunks. You can reduce the number of arithmetic operations still further by creating a combined string of the 256 8-bit combinations:

CREATE FUNCTION IntegerToBinaryString2(@intval int)

RETURNS char(32)

AS

BEGIN

DECLARE @bincode256 char(2048)

SET @bincode256 = ‘00000000000000010000001000000011 …’

RETURN (

SUBSTRING( @bincode256, (@IntVal / 16777216) * 8 + 1, 8 ) +

SUBSTRING( @bincode256, ((@IntVal / 65536) & 255) * 8 + 1 , 8 ) +

SUBSTRING( @bincode256, ((@IntVal / 256) & 255) * 8 + 1 , 8 ) +

SUBSTRING( @bincode256, (@IntVal & 255) * 8 + 1 , 8 ) )

END

GO

[Note: I originally posted the whole 2048 characters of @bincode256, but it caused my blog some alignment problems! You can either use the technique of small cranes to build big cranes, using the following T-SQL snippet to call the first function to create the string, and then cut and paste it, OR type it in yourself. Personally, I ‘d go with the first suggestion!

DECLARE @i int

DECLARE @res varchar(2048)

SET @i = 0

SET @res =

WHILE @i < 256

BEGIN

SET @res = @res + + CAST(Substring(dbo.IntegerToBinaryString(@i), 25, 8) as varchar(8))

SET @i = @i + 1

END

PRINT @res

GO

I’m not sure what Rob and Omnibuzz (!) use for their timing harness or test dataset but hopefully, I’ll follow up with relative timings.

Rob’s was originally inspired by this post.