Sunday, August 24, 2008

Disqus

I decided to try out discus.

Monday, January 14, 2008

Repository Based Code

Last week I listened to the first episode of the_stack[trace] about Image Based Development. This is a new podcast with excellent technical content. Today I read a new pattern from Martin Fowler's Wiki, Repository Based Code. Maybe I'm wrong, but I think these two patterns are synonymous.

Windows Power Shell is definately an environment that lends itself to this style of development. Lisp has a dribble function that tells the shell to spit out all commands to a file. Power Shell has the Get-History commandlet which can be used the same way.

This one liner will dump all commands that set a variable into a script called foo.ps1.

get-history -count $MaximumHistoryCount where-object { $_.CommandLine -like "$*=*" } > ~/foo.ps1

Friday, November 30, 2007

ASP.NET AJAX is Broken

I spent a couple of hours debugging this problem. I recently upgraded a web site to .net 3.5 and decided to make use of some of the ASP.Net AJAX controls. "It's so Easy!" they say. "Just drag and drop two controls and 'Welcome to Web 2.0!'" Not for me.

I was able to create use the UpdatePanel from a new site, but in my legacy site the page would do full page refreshes. I followed the example from MSDN's UpdatePanel Class Documentation. Comparing the html from my new site and my legacy site, I see my new site some additional JavaScript that initializes a PageRequestManager.

Now I know that it's not my code. Something must be configured wrong. So I compare the web.config in new site to the web.config in my legacy site. I identified the problem to be this line in my legacy site


Here's the kicker. I do a google search for - xhtmlConformance mode legacy asp.net ajax. Scott Guthrie's blog post from December of last year is at the top of the list. I read this post over a year ago, but failed to recall it when necessary.

After fixing the config problem I played with my new AJAXy site and had to grin. It was very little code to change for such a pleasant performance benefit.

Tuesday, October 09, 2007

Microsoft MVC

I just finished watching Scott's video of Scott presenting and Scott arguing. Watch it! What impressed me most was the knowledge that Scott Gu had around other MVC, Templating, and IOC. Martin Fowler put it nicely "Add a rich sauce of clear understanding and learning from other work in this space."

Friday, September 21, 2007

Visual Studio Macro to Remove Vertical White Space

One of the things that makes legacy code hard to understand is all of the extra noise.  A lot of developers (myself included) will comment out a line of code rather than delete it.
I wrote this little script to clean up the comments and white space.  This macro combined with the format document command in Visual Studio do wonders for readability.
    Public Sub RemoveVerticalWhiteSpace()
DTE.UndoContext.Open( _
"RemoveVerticalWhitespace")
txt = DTE.ActiveDocument.Selection
lines = Split(txt.Text, vbLf)
txt.Delete()
props = DTE.Properties( _
"Environment", _
"TaskList")
tokens = props.Item("CommentTokens").Value
For Each line In lines
If ShouldPrint(line, tokens) Then
txt.Insert(line)
End If
Next
DTE.UndoContext.Close()
End Sub

Private Function ShouldPrint( _
ByVal line, _
ByVal tokens)
If String.IsNullOrEmpty(line.Trim()) Then
Return False
End If
If line.Trim.StartsWith("'") Then
If line.Trim.StartsWith("'''") Then
Return True
End If
For Each t In tokens
t = "'" & t.ToUpper().Split(":")(0)
l = line.Trim.ToUpper()
If l.StartsWith(t) Then
Return True
End If
Next
Return False
End If
Return True
End Function

Saturday, July 21, 2007

Vb.Net Capitalization

Paul Vick has an interesting post about capitalization of keywords in VB.

Yes VB is verbose, but not because it capitalizes it's keywords. VB is verbose because it favors keywords over punctuation. This favoring improves readability. Standard formatting and capitalization also improves readability. Even though VB is more verbose than C#, I am able to write code in VB faster than C# because of Visual Studios excellent Auto-Formatting.

Paul poses the question, should we add keyword capitalization options to the current code formatting options. YES! But why limit the capitalization options to keywords? It would save me tons of time if Visual Studio would automatically capitalize namespaces, class names, method names and variable names according to my company's standard.

Excellent question Paul. I can't wait to see it in VBx :)

Friday, June 15, 2007

Variable scope in VB

I just came across a “feature” of VB that I was unaware of. I’m now a little bit scared of how many bugs I’ve written because I was unaware and ignored the compiler warning to initialize all variables.

Here is some example code.

    Public Shared Sub VisibleLifetime()
For i As Integer = 0 To 5
Dim x As Integer
Console.WriteLine(x)
x += 2
Next
End Sub

For some reason I thought, since we declare x within the for loop and the scope of x is confined to the for loop and dot net initializes integers to zero, that x was initialized within the for loop to zero on every iteration. It turns out I’m wrong.

http://blogs.msdn.com/vbteam/archive/2007/06/15/closures-in-vb-part-4-variable-lifetime.aspx