Thursday, January 24, 2008


Justin came up with this problem as part of an actual project and it puzzled me the simplicity of the problem and definition of the solution in your head, yet the complexity of the expressiveness in code for the solution, maybe another language would be better suited to solve this problem?

you have an array of the Doc class which has a DocIndex property, for which the property is not set, some elements of the array may be null

//*** small version of the Doc class, just for the puzzle
class Doc {
public int docIndex;

Doc[] docs = new Doc[] { new Doc(), new null, null, new Doc() };

then you have an array of ints that represent the indexes that are already taken, e.g.

new int[] { 2, 3, 5, 7, 9 }

your job is to assign the indexes to the Doc[] that are not "taken" (exist in the array)

so, for these examples:

The expected output would be:
existing :
2 3 5 7 9
docs :
0 1 4 6 8

existing :
0 1 2 3 4
docs :
5 6 7 8 9

existing :
5 6 7 8 9
docs :
0 1 2 3 4

what do you think of this problem for a code interview?

Saturday, January 19, 2008

find all tables with column name *

Applies to: SQL
Tested on: SQL 2005
Keywords: SQL, column, all, tables

I'm going to need this quite often...

just execute these queries on the same database where the tables reside

--get all table names for a specific column name
SELECT as TableName
FROM sysobjects o inner join syscolumns c on

you can also perform like queries

--get all columns and table names for a 'like column' query
SELECT c.[name] as ColumnName, as TableName FROM sysobjects o inner join syscolumns c on

Thursday, January 10, 2008

C# vNext wishlist: comma less argument list

Mitch Denny has a post about his feature request for the next version of C#

he wants to have a shortcut to format strings, which would basically allow you to go from this
string s=string.Format(”{0}{1}{2}”, a, b, c);
to this:
string s=@(”{0}{1}{2}”|a|b|c);

I don't think I like the proposed alternative, all you are doing is replacing the "," with the "|" character and making the name shorter.
You could always write your own little wrapper:
//*** you could call it "f" if you wanted
static string fmt(string format, params object[] parameters) {
return string.Format(format, parameters);

and get
string s=fmt("{0}{1}{2}",a,b,c);

which is almost the same as the proposed solution

another problem is that this proposal solves a very particular problem which is string formatting and we can get pretty much the same by writing our own little wrapper

but anyway, it gave me an idea for my own feature request
comma-less arguments

string s=fmt("{0}{1}{2}" a b c);

The scope of this change is much wider and actually "desugars" the language

now this change will most likely not happen, since this is a C family language and would take a significant change to the parser but this is my own wish/feature request so there you have it