Rant: Freedom vs Safety

The following explains why I regret my descent into programming over the last 12 years:

Code Craft: Freedom vs Safety Languages
Coding Horror: A Scripter at Heart

So I hate Microsoft, both because they only allow safety languages at their core, and because they are in a constant state of change. The use of safety languages in a realm where freedom languages should reign is unacceptable to me. It is a backward methodology, making client side interaction more complicated than I ever thought possible. To reverse the trend, and make my life more tolerable, I have tried to circumvent Microsoft's best practices by implementing the following:
  1. Generate a data access layer (MyGeneration was recommended to me)
  2. Define Views for the data in the code behind in an aspx/asmx that acts as an API
  3. Implement StringTemplate to render any dynamic web pages using data provided by Views.
  4. Implement Mootools and/or JQuery for the user interface.
I have spent roughly nine months working on this architecture and have nearly reached step 4, the fun part. Data access with caching, views that expose data, and virtualized pages using templates have all been completed. So now I'm almost functionally equivalent to where I was 1.5 years ago working with Django and Python. Thanks Microsoft!

.NET 2.0: Return a property value from an object dynamically

public static object GetObjectProperty(object o, string property)
{
return o.GetType().GetProperty(property).GetValue(o, null);
}


AKA the simplest reflection you can use. Right?

SQL Server 2005: Recursive Query (aka Common Table Expression)

SQL recursion for cascading results from the same table.
-- UP THE TREE
DECLARE @Id INT
SET @Id = 1

BEGIN
WITH myTree (Id, ParentId, Field)
AS (
-- anchor member declaration
SELECT Id, ParentId, Field FROM myTable WHERE ParentId = @Id
UNION ALL
-- recursive member declaration
SELECT myTable.Id, myTable.ParentId, myTable.Field FROM myTable INNER JOIN myTree ON myTree.Id = myTable.ParentId
)
SELECT DISTINCT * FROM myTable INNER JOIN myTree ON myTree.Id = myTable.Id
END


-- DOWN THE TREE
BEGIN
WITH myTree (Id, ParentId, Field)
AS (
-- anchor member declaration
SELECT Id, ParentId, Field FROM myTable WHERE Id = @Id
UNION ALL
-- recursive member declarationjavascript:void(0)
SELECT myTable.Id, myTable.ParentId, myTable.Field FROM myTable
INNER JOIN myTree ON myTree.ParentId = myTable.OrgId
)
SELECT DISTINCT * FROM myTable INNER JOIN myTree ON myTree.Id = myTable.Id
END


I can't believe they call recursive queries "common table expressions." Who does that make sense to?

SQL Server 2005: Cursor Example

DECLARE @id INT
DECLARE db_cursor CURSOR FOR
SELECT id From myTable
OPEN db_cursor
FETCH NEXT FROM db_cursor INTO @id

WHILE @@FETCH_STATUS = 0
BEGIN
-- do something
FETCH NEXT FROM db_cursor INTO @id
END

CLOSE db_cursor
DEALLOCATE db_cursor

I have a terrible time remembering SQL syntax.