Sunday, August 12, 2007

What Comes First?

{

Although it's an older essay (November, 2004), The IDE Divide made for some good Sunday reading. Not only is the author, Oliver Steele, engaging but his visualizations are exceptional. I'd like to think of myself as a "language maven" - that is a person who puts the emphasis on language capabilities before tools - but I know that growing up in the Microsoft world as I did, I understand how big of a difference good tools can be.

One item I don't recall seeing in the essay was how tool mavens are responsible for their own obsolesence. It makes perfect sense to focus on language first and be flexible with tools - and to have a good text editor you can rely upon. I started using Textpad first with Java and nowadays I usually don't pass a day when I don't open something with it - either for quick inspection of a file or to write something in perl or python.

I know there are other good text editors out there but it seems like having good regex support and the ability to attach shell commands to keyboard shortcuts is most important. Syntax highlighting is a nicety too although as time passes it's not really as important to me.

}

Tuesday, August 07, 2007

!Normalize

{

Some time ago Jason Kottke posted an entry for which quite a few people bashed him about unnecessary database normalization. I've thought a lot about it since it represents some of my own internal sentiments and instincts. The two things I observe on a regular basis that I find annoying are bad naming conventions within databases and unnecessary complexity because of overzealous normalization.

It's hard to have an argument discussion on the topic with people lacking experience because the penalties for bad normalization are usually paid in the long term whereas the "effeciency" of storage with normalized data seems to be an ideal to strive for when one's perspective is short.

I was therefore heartened to see some caution from Patt Heland (courtesy of Dare Obasanjo who elaborates) on the topic. It may be a good idea to have a meeting at work and discuss some of the details given... maybe not to come to some "conclusion" or "database standard" that can apply to every situation, but more to generate good discussion and ideas.

}

Wednesday, August 01, 2007

Upsert Properly

{

For the longest time, my approach to update/insert logic has been the following:

IF EXISTS(SELECT...) BEGIN
UPDATE...
END
ELSE BEGIN
INSERT...
END

So courtesy of .NET Kicks this gem was very informative which is the same logic but with a cleaner approach. Instead of selecting records first, you attempt to do an update and check afterwards if the @@rowcount is greater than zero - if not the record doesn't exist so you can move logically to an insert.

UPDATE ...

IF @@rowcount = 0 BEGIN
INSERT...
END

Nifty, very nifty.

}

Tuesday, July 31, 2007

Fast Learning, Norvigian Thinking

{

I was looking over Justice Gray's post on becoming a better developer in 6 months and noticed that he had listed Freidl's Mastering Regular Expressions as a one week reading project. I'll preface my comments by admitting I am not the quickest read - unless I'm reading something I don't particularly care about I tend to go it slow no matter what the subject matter.

However.

Not really thinking of connecting the dots I checked in on Jeff Freidl's blog and digging around saw it took him 2.5 years to complete the first edition of the book.

It strikes me as funny that there would be such a disparity in creation and consumption. Of course I may be slow - a big part of my wanting to learn Perl was the desire to have the capacity to "think" in regular expressions - but over the last few years as I've gotten better and better I find it hard to think I could compensate the little projects and tools I've written without the pain and grit of using what I read slowly.

But then again we can all rest assured that there's no rush.

}

Sunday, July 29, 2007

Remove Duplicate Lines In Python

{

I had posted about the set operator in Python with some questions. All that changed today when I wrote a little script to remove duplicate lines from a file. The set operator takes a list and automatically gets rid of duplicate items. Very useful for situations like this:


#!/usr/bin/env python

f = open("c:\\temp\\Original.txt")
f2 = open("c:\\temp\\Unique.txt", "w")
uniquelines = set(f.read().split("\n"))
f2.write("".join([line + "\n" for line in uniquelines]))
f2.close()


}

Saturday, July 21, 2007

Shuffled Arrays

{

One of my weaknesses is that I love puzzles. And once I'm puzzle solving, I usually dwell on the problem beyond its worth. I recently saw a job ad - I'll leave this post disconnected - that had a quiz associated with it. The quiz amounts, basically, to shuffling items in an array (javascript).

My first stab was intuitive, but I wonder if it's the most optimal because it relies on a lot of discarded data. In my loop generating a random order, I essentially go through an undetermined amount of times discarding results that already exist in the randomized array. Additionally the array with random numbers is just for positioning and is probably unnecessary.
Here is the code:


function BuildArray(){
// just builds a random array to work with
var testArray = new Array();
testArray.push('Test 0');
testArray.push('Test 1');
testArray.push('Test 2');
testArray.push('Test 3');
return testArray;
}

function GetShiftOrder(testObject){
// this is what sorts things out
var upperBound = testObject.length;
var newOrder = new Array();
var shuffledArray = new Array();
builder:
while(newOrder.length < upperBound){
n = parseInt(Math.random() * upperBound);
for(i=0;i<newOrder.length;i++){
if(newOrder[i] == n){
continue builder;
}
}
newOrder.push(n);
shuffledArray.push(testObject[n]);
}
alert(newOrder + '\n' + shuffledArray);
}


I was thinking about this today and it may be more effecient to make a random number of passes at the array swapping pairs of items. A shuffling cards approach may be slightly more effecient although to have meaningful swaps there would need to be a minimum number of passes - and additional complexity with making sure pairs were swapped in random pattern.

Anyway, it was interesting and I'm always curious about more elegant solutions.

}

Thursday, July 19, 2007

CodePress

{

I'm taking a serious look at CodePress. Very, very, very cool.

}

Sunday, July 15, 2007

Sieve of Eratosthenes, Python, Set Operations

{

I pretty much broke down after TechEd. I thought I'd be patient enough to wait for Ruby but because Python is most mature I have started to learn it, whitespaces or no.

The first thing I did was check out Guido van Rossum's tutorial for programmers, which was an excellent first step. I've followed that up with some random programming - a lot of fun so far.

I was wondering about the set operations in python and how that made a difference in programming since there aren't syntactical equivalents in .NET. Incidentally at the time I was reading The Man Who Loved Only Numbers and ran across a short description of the Sieve of Eratosthenes as a way of finding primes. I thought it would be a good way to check out the set operations of Python.

I wrote the following:


from System import *

def multiples(num, thresh):
multi = []
for i in range(2,thresh):
m = num * i
if(m < thresh):
multi.append(m)
else:
break
return multi

primeThresh = 5000
print DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss")
nums = range(2,primeThresh)

for n in nums:
nums = set(nums) - set(multiples(n, primeThresh))

print nums

print DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss")


Interesting, but slow. The way I may do something like that in C# (which also works just fine in Python) would be this, which I wrote later:


from System import *

primeThresh = 5000
print DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss")
nums = range(2,primeThresh)

for n in nums:
for m in range(2,primeThresh):
try:
mult = n * m
if(mult > primeThresh):
break
nums.remove(mult)
except:
pass

print nums

print DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss")


It's a lot faster than the previous approach which makes sense - doing set algebra on large sets should take a long time... but that begs the question: are those set operations dangerous (ie. so slow as to be costly).

I'm wondering what's "pythonic" and how a jedi would write this most effeciently.

}

Saturday, July 14, 2007

Being Better

{

I probably won't be officially "tagged" but a meme is going around about what one would do in the next 6 months to become better. Hanselman, in his podcast, spoke of a few things and the responses seem to be going up around the blogs.

How will I be better? Most of the things people mentioned are things I already try to do: reading technical books, working on my software, looking at open source, training others... but one thing I want to do is to start posting code.

I write a lot of code and much of it doesn't make it here because I'm sheepish about looking foolish. But getting better is about having courage to show my work because without that, how could it get any better?

I'm going to start with my JAPH, a program that prints "Just Another Perl Hacker." It's meant to be novel and I actually like mine since it leverages some language features that don't exist in my mainstay, C#. The map operation can visit each item on an array performing some opertion - in this case I'm using a regular expression on each item and grabbing alternating characters! I haven't been writing perl for a long time so hopefully over time I can claim a better one but at least this is my own thinking at play, destined for improvement. I did post it on usenet (a first version which had some foolish mistakes) but this is after a little bit of massage:

#!/usr/bin/perl -w
# David's JAPH, volume 0.1
map(print(/(\w)\w/g," "),
qw(Jaubsctd Aenfogthhiejrk Plemrmln Hoapcqkresrt));


The original JAPHs, from Randall Schwartz, were not really about obfuscation but more about language features. The use of map, regular expressions, and $_ in the above are what make it interesting to me.

}

JLam on DNR

{

I never mind a long drive with a podcast. A few days ago I listened to John Lam on Dot Net Rocks. I'll admit that sometimes the DNR people can be annoying to me (think Richard Campbell saying over and over like it's a joke "Managed JavaScript??") but it was all worth it to hear some of the internal goings on with the Iron Ruby project.

Gleaning: Iron Ruby is a ways off. I got somewhat impatient and have been using IronPython in the meantime, but more on that later. That's not a small decision for me because I am of the Norvig perspective on learning a new language - it takes the length of time needed to think in terms of the idioms of that language, as opposed to just writing your code with different syntax and keywords (ala writing C# in Ruby).

Gleaning: Ruby is a powerful language for creating domain specific languages. That meme has been floating in my head for a while - listened to a good Software Engineering Radio podcast on the topic sometime back.

Gleaning: JLam talks a bit about how the learning curve for new languages these days revolves around the frameworks for languages - I think the idea of Ruby combined with .NET is that the .NET libraries will fill a gap that Ruby has always missed in library support. Dangerous or brilliant? In other words, I'm sure the open source crowd (is/will be) up in arms because this will, in their minds, dilute the community effort behind a language. Brilliant because the Mort you know (who is probably your boss) will have a better level of confidence about using it.

Gleaning: Iron Ruby is implemented in C# but Managed Javascript for Silverlight is a VB.NET implementation!

}

Monday, July 02, 2007

True Story: The Cat Ate My Source

{

A security issue prompted my ISP to change passwords for all users. Normally, this wouldn't be a problem - I'd go to my repository of code, divided at present by year in a "Code05," "Code06," "Code07" format and update a constant in my Constants class and *presto* the connectivity would be back.

Problem is, what if I have to go back more than 3 years?

I'm usually not that irresponsible. In fact, I'm fiendish about backing things up. Yes, I use source control, even on my own little-bitty projects that matter to no one but me. But my mistake was using an external drive - a flakey one - which died after I'd had to reformat/reinstall. I'd backed everything up to it, and my data was gone.

Edge case since I'd after the reinstall I'd moved what was important back to the machine. Edge case because it was in a "code archive" that was something like 6 years old - code that was so long forgotten it was like a head bludgeon when I got a phone call from the client saying that their site was down.

After panicking and looking for some accidental backup (why do we look for things when we know they're gone for good?) I had an epiphany.

I downloaded the *.aspx pages and the site dll - I then used Reflector to disassemble and - I kid you not - 15 minutes later the client was up and running.

And yes, I kept the source...

}

Monday, June 25, 2007

Mac History

{

It's strange that I've had a long relationship to Apple's products - or perhaps not if you're a believer and consider their reach unremarkable...

Growing up in Nairobi, a missionary's kid next door had an Apple IIc he'd occasion to let me use (more often I'd simply watch him using it). A few years later, I spent time in my high school computer classes using Apple IIe computers - for the most part it was typing but I had moments of the extracurricular.

My freshman year of college (1993), after many months hovering around the computer store, drooling and daydreaming, a family gifted my sister and I with a Powerbook 160. The little Powerbook that could took us through the college years although by the end it was on its last legs -

... after which I took a long departure from the Apple universe. I began working with PCs and forgot how much fun it was to pick icons, leverage a trackball, and use the Finder.

After talking my boss into it, however, a year ago I got the priviledge of using Macs again with a company owned, David leveraged iBook G4. It's still a foreign environment but it's nice to return to - especially last week after my HP laptop needed to be reinstalled after catching a virus.

All this to post that there is this interesting graphic of Macs in time, with most of my old friends along the way.

}

Yegge, NBL

{

John Lam reports that Steve Yegge revealed a Javascript implementation of the Rails framework at this weekend's "Foocamp." Having just finished Yegge's most recent post Rich Programmer Food this weekend, and following his NBL (Next Big Language) post from a while back, the dots seem to be connected. It seems early even among technical blogs but I suspect information will start to seep out in the short future.

}

Thursday, June 21, 2007

NDepend vs Me

{

I didn't manage a blog post during TechEd but I'll take a stab at a few things that have swilled in my mind since then. The first thing I've been working on is understanding NDepend, the tool for static analysis. I went to a "Birds of a Feather" spearheaded by some folks from Corillian and had to keep my mouth shut tight so as not to look a fool. Luckily many of the folks there were like me: they knew about static analysis as a concept but were trying to figure out how they could make good use of it.

It will be quite some time before we have static analysis as a part of our build process but I'm most interested in using a tool like NDepend to take the emotion out of code reviews. That is to say that while I do love a vigorous discussion on style and preference, there are concrete measures one can look at objectively to evaluate the well being of software design.

While I'm shaky on the exact meaning of all the metrics (it was suggested to run repeatedly looking for trends) I ran it against a project that has pretty much taken my thirty first year on this earth. For a while that's been on my "to do" list but I think there's always a bit of hesitancy on my part when I'm about to be brutally honest with myself; I designed this software and wrote quite a bit of the code.

The results weren't great, but they weren't horrible. When I used it on the libraries by themselves, the visualizations of the dependencies seemed clean and tidy, and many of the metrics weren't too badly outside of some of the pointers in the cheat sheet we got.

However.

There are some obvious weaknesses that came to light. First and foremost, we were solidly in the zone of instability for most of our assemblies. There are two things that were suspicions now confirmed: first, we didn't have a very formal design process. I need to get better at perceiving my job at an architect level versus as a coder. The second is that we rushed. The rush was not just a schedule thing, it can also be attributed to our short release cycles. The agile folks recommend these, but it should be balanced with a period of silence at the beginning when overall design decisions are being made. The final item, which NDepend would have helped us with in a continuous integration cycle, was showing unused code. After a year's worth of work it's hard to look at so much and except oneself to clean it up, but as a weekly task it would be an easy way to keep things healthy and tight.

Final note: running NDepend is ridiculously easy. The hardest thing besides looking at metrics and trying to understand them is having the courage to look objectively at what you've done.

}

Slowly Back

{

After a weekend with a virus, and a horrible waste of time, I've got a clean installation of XP. The upside was that it forced me back to the iBook G4 that's been a little lonely without me.

}

Wednesday, June 06, 2007

Programming Personality

{

This programming personality test was interesting.

Your programmer personality type is: PLSC

You're a Planner.You may be slow, but you'll usually find the best
solution. If something's worth doing, it's worth doing right.

You like coding at a Low level.You're from the old school of programming
and believe that you should have an intimate relationship with the computer.

You don't mind juggling registers around and spending hours getting a 5%
performance increase in an algorithm.

You work best in a Solo situation.The best way to program is by yourself.
There's no communication problems, you know every part of the code allowing you
to write the best programs possible.

You are a Conservative programmer.The less code you write, the less chance
there is of it containing a bug. You write short and to the point code that gets
the job done efficiently.


}

Tuesday, June 05, 2007

Free Powershell Book

{

All I can say is that I'm loving powershell right now. Hopefully some more goodies will ensue upon this blog but if you're learning like me you can get a free book by leveraging the full length help that is offered on objects. You can print in the following steps:

Get the cmdlets and send the documentation of each to its own file:
get-command % {man $_ -full >"C:/Power/$_.txt"}

Now make an index page so you can navigate to the individuals:
$cmd = get-command % {write-output "<a href='$_.txt'>$_</a><br>"}
"<html>$cmd</html>" >C:/Power/index.html


}

Sunday, June 03, 2007

Partying with Palermo

{

Going to Party with Palermo tonight. Looking forward to meeting the jedi and getting TechEd started right!





}

Monday, May 28, 2007

Quality

{

Via Mads I watched Douglas Crockford present on quality in software development. I posted before on some of his excellent javascript tutorials, this is on par with them. While he's done a good job of granting some ideas in making software quality better, my train of thought goes towards my own workplace and how we can make information like that actionable.

}

Wednesday, May 23, 2007

Visibility, Alpha Geeks

{

Who are the alpha geeks out there? According to many, there are none outside of Microsoft using Microsoft tools. Ergo, I must be excluded unless my night sessions with perl in Komodo somehow grant me reprieve... very doubtful... but rather than bristle and come up with examples of people who are accomplished and effective while not being on Microsoft's payroll I'm prompted on a different question: how do we define "alpha geek" especially in a world where so many of us don't know if we're good or not?

I'll answer in the negative because the blogosphere seems to taint judgement in one respect: visibility. There are quite a few people who maintain a loud profile and acquire a status as "expert" and yet when you look more closely at the body of work it doesn't reconcile itself with the status their profile seems to afford them.

I respect people like Hanselman, Haack, Moise, Atwood, JLam, and so on - they seem to have jobs I can empathize with and still find time to be the large sounding boards online. Banking software is involved, complicated stuff, and not only that, it's the type of software that I write. When I compare the design goals of something like NStatic or RubyCLR to pretty web CRUD, I find myself with more respect for the former.

But these are people we all know because they are in our aggregators. They are good but for every one there are many silently effective "alpha geeks" that don't prioritize a web presence. Think game developers here... more specifically think of someone like John Carmack - not necessarily a Microsoft developer but neither a well dressed Web 2.0 pundit. These are people living a little lower level, cranking out stuff even as the blogosphere distends itself with opinions like my own.

So I keep going back to that wariness of visibility. For all the fashion against Microsoft, what makes or breaks my impressions are the body of work that accompanies the comments.

}

Sunday, May 13, 2007

RIA: Game of Thrones

{

Catching up on my aggregator yesterday I saw that Dare had posted about Sun's response to Silverlight: their own rich internet application (RIA) framework to supplant (though the politically correct answer is not that it would, it's just a "new opportunity") some of the Web 2.0/AJAXish things that have been popular of late. Mary Joe Foley presents a noncommittal analysis and Sam Ruby points to a few resources.

I went to Sun's page and although it seems like a real enough project the fact that it's applet based right now (and far slower than the Silverlight beta in installing) seems to point to it as an unfinished thought. Their demos at this point are not just slow, but rather underwhelming - compare that with the MLB demo at Silverlight and it's quite a contrast.

But I'm willing to assume that Sun is serious and that their technology has a lot of appeal, especially to many people who live on the "Not Microsoft" koolaid. If that's the case there is a three way battle going on between Adobe, Sun, and Microsoft for how RIAs will be developed.

I wonder if it's wise in a situation like this to hope for a clear winner; competition should hopefully produce the best technology out of each company. Although there will doubtless be compatibility questions that come up, but because each seems to be plugin/runtime based, it seems like developers will have an opportunity to choose a target and build with/for it rather than some of the monkeying around that needs to be done to make a web application work on multiple browsers.

}

Saturday, May 12, 2007

The Mighty DLR sans Perl

{

It wasn't until this morning that I had a chance to look at John Lam and Jim Hugunin present on the DLR at Mix. My response is a mixture of giddiness and shock - appropriate I hope for a programming language geek like me. Lam begins the presentation by writing a "simple" application with a mixture of C# (an onscreen button), with its click event handled in Ruby, obtaining parameters from Visual Basic and making a call to a Javascript function. Hugunin is not to be outdone: he follows up with an animation library he has written and his own mixture of onscreen manipulation with a mix of Python, Visual Basic, Javascript, and Ruby.

This is the part of Silverlight that I can grok as a developer of nary so flashy (pun intended) as much as practical pieces of software. The ability to put so many languages in concert, the development experience as text-based and interactive (edit text and refresh just like you do with HTML), and the cross platform support make my mind swim with potential uses. The fact that their demonstration was on a Mac was a brash in the best sense: it's a level of confidence that's not based on arrogance, but preference (Lam presented on a Macbook pro at Teched last year).

I was fortunate enough to meet John Lam at TechEd last year (I have this problem of "freezing up" when I meet people I respect as much as that - all my questions/ability to speak vanishes) and had I the foresight I'd have asked what his thoughts are on Perl. The dynamic languages Microsoft is supporting initially seem like smart choices and certain languages like Smalltalk may not be popular enough for them to justify an implementation. But Perl? I would have thought it would make the cut. I understand that it could be a syntactically difficult language but there are features in Javascript such as handling parameters on functions that seem to be on that order of magnitude in difficulty.

Although the Perl community is tremendous, it seems as fractured as 3rd century Rome. But that being said it's possible that either one of the monks or a clever company will start a project that makes it another language in the DLR family.

Or maybe I'll start a PerlCLR project and get hired by the b0rg. Not even in my dreams do I have skills like that ...

}

Sunday, May 06, 2007

What Is Silverlight - The Poster

{

Yeah, there felt like a little impedence mismatch in Scott Hanselman and the Mike Harsh describing Silverlight - ironically Scott being more excited than Mike who actually worked on the project. Let's allow for Mike just not being a visibly enthused sort of person -

Microsoft posted a graphic that is meant to be a resource on understanding what we're dealing with - sans (screen|pod|video)cast it's still not quite the nuts and bolts. Fortunately there are annotations and an entry Scott posted.

}

Monday, April 30, 2007

Mix Has Begun

{

I'll catch up with the keynotes later, but I'm monitoring the blog which seems to have a lot of good stuff.

}

Monday, April 23, 2007

Dreaming in Code

{

Dreaming in Code author, Scott Rosenberg is interviewd on IT Conversations here. You can impress your friends that you "read" his book even if you've only heard a few ideas. A recurring theme is just how hard it is to write software - a good reminder for me since I have frequent bouts of self doubt that is unwarranted. It's not just hard for me, it's hard for everyone.

}

Monday, April 16, 2007

Microsoft Silverlight

{

John Lam has let part of the cat out of the bag - the "new" thing he alluded to a while back appears to be linked to Microsoft Silverlight, what seems on the face of things to be a rebrand of WPF/E, an attempt at a Flash killer.

The programming details will have to wait for Mix 07, but for now the buzz should start. It's ironic that a matter of days after Paul Graham declared Microsoft "dead like IBM" that something like this should be announced.

It will be interesting to see how this fits into web development with Adobe's Apollo. Adobe has played a masterful first hand by making Apollo open source. It will be interesting to see how Microsoft responds.

The good news is there is a CTP for download, so for those of us who won't get to Mix, there is room to dig around.

}

Sunday, April 15, 2007

How much code do you write?

{

I've previously identified perl as my "night language." In other words, I'm hacking away at it in the off hours trying to get better. Maybe, just maybe, I will find a way to get paid for writing perl code. As of now, however, I write C#/.NET code to put food on the table.

As an exercise in perl, in order to demonstrate how fast it is, I wrote a small script that would count the number of lines of code I was responsible for last year. That's an easy task; I keep all the code I am working on for a given year in the same directory. There are a few projects that span a year's end, but it's okay since there's a lot of code that is written that doesn't make it to my directory, and there is a lot of code I write that isn't C#, which is all I was counting in this instance.

After a little tweaking, I had a script I felt happy enough with to point at my CODE06 directory. I was fairly curious - the folder is about 650MB but a lot of that is binary stuff, everything from installers to compiled bits of projects. My script - or perl, I should say - is unbelievably fast; when I changed output to a file it was able to run in less than a half minute. The first run showed that there were ~160,000 lines of code in the directories *.cs files.

Interesting - not an accurate estimate of things but 438 lines of code per day (160,000 / 365) and if you consider only business days (251), that's on the order of 637.5 per day. I can hear the Herbert song playing Something Isn't Right in my head at this point.

I do use Visual Studio, and one of the points of interest for me was the difference in how much code I actually wrote and how much was generated. Again back to estimating I excluded Visual Studio generated files from my project and that cut the number down to ~30,000 lines of code.

This is very imprecise because there are some *.cs files which are generated but it still has the Something Isn't Right going in my head because a little bit of help and organization from an IDE is fine, but the cost of 84% of output being machine generated is steep.

It's an Ellen Ullman moment; the realization that there are so many layers of abstraction between you and your tool - that you're unaware of all the hiding it does for you. It's a reminder of a moment a while back when I was showing someone how dangerous letting a tool do something for you can really be.



}

Sunday, April 08, 2007

Proper 0.1

{


A while back I made a property code generator I called t3rse::proper. It was an exercise to solve a problem I'd had as well as write something useful entirely in javascript. I've added a few new features to it that will hopefully make it even more useful in future:

1. Custom Shortcuts
Proper allows shortcuts for common datatypes - for int you simly type i_ and the same is true for bool (b_), string (s_), datetime (dt_), as well as a few others. If you have a classname that you need to build properties on, you can add your own prefix and follow that with an underscore when you're defining your properties. You could, for example, use sq for SqlConnection.



2. DebuggerStepThrough
More often than not properties have a simple definition that needn't be stepped through when debugging. A while back I started adding the System.Diagnostics.DebuggerStepThrough attribute to pieces of code like this - I've added this feature to proper with a checkbox option.


Future features? Whenever I have time the following:
1. Ability to remove custom shortcuts gracefully
2. Settings and shortcuts stored in a cookie

One final thing I'm pondering is whether to try to implement The World's Simplest Code Generator as an exclusively javascript/ajax application. I thought about it as a newer version of proper but I like the idea of proper being so dead simple that it doesn't become unwieldy. Does it suck? Tell me why at proper at t3rse dot com. Want to make it better? It's all there as javscript, just send me an update and I'll see if I can include it in a newer release.

}

Tuesday, April 03, 2007

Best Of SQL Server PDF

{

For a while now I've been a subscriber to Simple Talk, an excellent magazine/website put out by the folks at red-gate Software. They are offering two incredibly dense PDFs with the best stuff from the SQL Server Central website for FREE. If you use SQL Server in any form, it's a great value for nothing.

red-gate makes excellent tools as well - we use SqlCompare to synchronize development and test databases regularly.

}

Saturday, March 31, 2007

Tufte Would Be Proud

{

PingMag again with something very interesting for all of us.

}

Youth Obsession

{

I read Paul Graham's essays out of habit these days; I loved the earlier gems concerning matters of being a Great Hacker and even though less and less of what he says is designed for people like me, I still read them hoping for something special. Something inspirational.

The current essay, Why To Not Not Start A Startup, is geared towards people considering as much. Among Graham's many ideals for the person starting a company, a recurring theme revolves around youth and freedom.

I caught a bit of it earlier in the week and one comment that stuck was in reference to people like myself, who also have a family life. I have no children yet, but even then I'm within the target zone albeit to a lesser degree.

"What you can do, if you have a family and want to start a startup, is start a
consulting business you can then gradually turn into a product business.
Empirically the chances of pulling that off seem very small. You're never going
to produce Google this way.
But at least you'll never be without an income."

The emphasis in the quote is mine because I think it struck at the heart of what bothered me - it seemed to go further than the notion of not starting a startup to what Google symbolizes in the social imagination: the Next Big Thing, the Brilliant Idea, the Company After Which To Model. It was the feeling a few weeks ago I got at the airport when I saw a young woman - a UCLA college student - with a Google backpack and I got a strange envy thinking "How'd she get that!?"

The quote remained in my head and last night while I was finishing the essay, my wife was watching the TLC show What Not To Wear and I began to connect the youth obsession from the show to the kind of youth obsession I recognize creeping into my own value system with the help of quotes like the above. It's the obsession that the good ideas - the potence as it were - is gone once a threshold of age or lifestyle is crossed. It's not unique to programmers or "techy" people; it seems that mathematicians can be plagued with the thought that Einstein and others resemble a universal truth: the best ideas are to be had in youth and from there you live in the afterglow of them.

I wonder about this. I grapple with the difficulty of truth generalized - I think Graham is in many ways right - and the desire to be an edge case of his statement. Two books I read recently come to mind: Masters of Doom, the chronicle of the founders of Id software, and Weaving the Web, Tim Berners-Lee's recollection of how the web came to be. In Masters of Doom, John Romero and John Carmack seemed to model the notion of Graham's thinking: youthful obsession, low budget living conditions, energy and the freedom to have fun. Tim Berners-Lee is a massive contrast - less a picture of overnight "hacking" and pizza, and more of thoughtfulness, patience, and the desire for his idea to be bigger - an idea that would prove its usefullness and universality. I don't remember the exact day, but on one important occasion Berners-Lee was absent, his son was born on whatever "special day" it may have been. Even though he could have monetized his work, his values seem shifted. And I find ironic the fact that the afterglow of the web is bigger than the afterglow of Doom.

I'd be interested in discovering some older founders - people whose paths were a little more thoughtful and wise. I'm sure there are some out there who break the age and family barriers to become successful as they've defined success. Although I'm pressed to think of them in technology, elsewhere they come to mind quite easily - the company I spend most of my time at, Daktronics, is just one such case.

I still love reading Paul Graham though - one thing he's written that I think I'll always remember comes from his essay Hackers and Painters where he described the attribute of relentless:

"This sounds like a paradox, but a great painting has to be better than it has to be. For example, when Leonardo painted the portrait of Ginevra de Benci in the National Gallery, he put a juniper bush behind her head. In it he carefully painted each individual leaf. Many painters might have thought, this is just something to put in the background to frame her head. No one will look that closely at it."

"Not Leonardo. How hard he worked on part of a painting didn't depend at all on how closely he expected anyone to look at it. He was like Michael Jordan. Relentless."

"Relentlessness wins because, in the aggregate, unseen details become visible.
When people walk by the portrait of Ginevra de Benci,
their attention is often immediately arrested by it, even before they look at
the label and notice that it says Leonardo da Vinci. All those unseen details
combine to produce something that's just stunning, like a thousand barely
audible voices all singing in tune."



I can walk away, a thirty-one year old married guy or no, as relentless as I can be. I'm off to paint some leaves. (But first I have to go home and do some yardwork.)

}

Thursday, March 29, 2007

Yagni

{

Tim posted about trying to explain Yagni on Twitter and after looking it up I realized it's something I've tended towards without having a vocabulary for it - you know that sense when something is so familiar that you think there's got to be a technical term for it.

And a person need not be an "Extreme Programming" proponent to see the truth; I have a Yagni moment almost each day when a person asks a question about how to do something and I'm more bothered with the question (why on earth would you do that???!!) than coming up with a solution.

}

Step In, Step Over, Step Out

{

Just a quick note from a late night's coding session, something that I sort of knew but finally got fed up enough to begin implementing everywhere. I'm working on a fairly large Windows Forms application and one library devoted to safe type conversion is filled with methods like this (yes, could've used Int32.TryParse, I'm not the original author though... ):

private int ToInt32(object val){
int ret = 0;
try{
ret = Convert.ToInt32(val)
}
catch(Exception ex){
// suppress
}
return ret;
}

It's nice to just attempt conversion and expect a zero for an invalid value, but it's annoying when you've got a method call like:

MyCall(SafeConvert.ToInt32(num1), SafeConvert.ToDecimal(num2));

The easy, clean fix is to apply the System.Diagnostics.DebuggerStepThrough attribute to your method. Any calls to that method are stepped over, making your life in debug mode that much easier.

System.Diagnostics has quite a few other debugger attributes, one of which allows you to mark code that came from a library you didn't write (DebuggerNonUserCode). Very useful indeed, especially when you've got unit tests that can assert something needs never be "debugged" again.

}

Friday, March 23, 2007

Tech Support

{

This spot about medieval tech support is hilarious.

}

Thursday, March 22, 2007

Beane's Programmer

{

I recently finished Moneyball, Michael Lewis's tale about general manager Billy Beane, the Oakland As, and the sport of professional baseball (note: I'm African and knew nothing about baseball for a long time - but after a few years playing fantasy online, I'm a major addict; it's hard to love math and hate baseball). What's special about the Oakland As is that as a small market team with nowhere near the financial resources of a team like the Yankees or the Red Sox, they do quite well in the major leagues - better than many of the money-rich competitors the play. What's special about Billy Beane is that he's been able to buoy the As performance by picking players that would have otherwise gone unnoticed for cents on the dollar.

Far be it from me to overextend the anecdotes of sport to something like software development but in this case I can't help thinking that a dominant culture of the development community online is obsessed with Fizz Buzz and functional programming languages in a manner similar to the way that old baseball scouts have an infatuation with high school standouts, good looks, and the Adonis body. I couldn't help but wonder about what was boring and yet obvious - the decisive factor between a good programmer and a bad one that was right under our noses but we miss because we're reading articles on the new shiny meme that is traversing the "blogosphere."

And then one thing came to mind... really a few weeks ago as I was reading Larry O'Brien's column in SD Times on estimation at a moment when my own lack of precision in the department had begun (and is still) eating at me. Estimation seems so pedestrian in comparison to Haskell, editors, language foibles, language pleasures, clever interview questions, and all the other things we look at for entertainment online. But I wonder if it isn't more important to be able to look at a project and give a relatively realistic guess at when you'll be finished - certainly in my case where the client is not going to notice my beautifully terse recursion inspired by Scheme under the covers, and they will become progressively discontented for each month that goes by when I'm still "working on things." I wonder that it isn't important enough for a guy like Atwood to call people unfit for programming over, or a major idea that sweeps across the net. Perhaps Agile methodologies fit into that, but more in the sense of philosophy than selection of team members and teammates.

What confirms this even more so is Steve McConnell's book on Software Estimation parked in the same spot it has been in our office over the last few years when we've rushed to everything (anything!) else: Fowler's Refactoring, C# References, Object Thinking, and the list goes on.

Estimation isn't exclusive to other traits that good programmers seem to have; in the same way that a person who happens to keep their On Base Percentage high doesn't necessarily do this at the expense of their Fielding capabilities. Indeed, a person who can reasonably estimate that a task will take them 50x longer than it would take others is probably in the wrong career to begin with, kind of like a baseball player who hits better than anyone else but is so phenomenally slow while making it around the bases.

Okay, that's all the sports and programming I have for a while...

}

Wednesday, March 21, 2007

Be The Editor

{

Derek Slager, whose background sounds a lot like mine, makes a case for using Emacs as an editor. It makes me think of two occasions: first, when I guffawed at James Gosling saying that his favorite IDE was Emacs, and then later on when I was teaching a .NET development class at Countrywide and a person sitting the class (graduate of UPenn) sneered at using Visual Studio .NET and instead opted for Textpad (he hadn't used it before but still leaned towards a simple text editor and his ability with the command line). Needless to say he put everyone to shame.

}

Tuesday, March 20, 2007

Foo, Bar, Monorail, and being Test Driven

{

People I work with are always amused by my excessive use of "foo" in naming things while I do examples or sketch out ideas. I was equally amused with Hanselminutes 55 which I can roughly quote here:

... so once you've got your foo class accepting a bar class
and more likely it's going to be accepting a IBar interface... foo depends on bar which depends on blah and yada ... your instantiation looks like new foo, new bar which takes new yada...


Fun stuff, but the real conversation was about Monorail, a piece of the Castle Project, a .NET web application framework I've been interested to look at for some time. The most interesting argument for the use of Monorail/Castle was the ability to have greater and more precise test coverage than with a typical ASP.NET application using Watir or an equivalent technology. All the buzz about being Test Driven usually breaks down for me when I'm looking at the kind of web applications we build. Even something like Watir is a frightening prospect on an ASP.NET page with several grids, in a masterpage, loaded with javascript - and has about 10 different "directions" that a tester could take. Extend that to about 100 pages, many of which support different "views," and you've got, well, a bit of a problem in being "Test Driven."

The conversants, besides Scott were Aaron Jensen and Jacob Lewallen.

}

Sunday, March 11, 2007

Beautiful Code

{

Here's something for the radar: Greg Wilson and Andy Oram have a forthcoming release (wow, I sound like a radio DJ) from O'Reilly entitled Beautiful Code: Leading Programmers Explain How They Think. If the title isn't seductive enough, a look at the essay authors should be - including Charles Petzhold, Yukihiro Matsumoto, Douglas Crockford, and Elliotte Rusty Harold amongst others.

}

Friday, March 09, 2007

Perlcast Interviewed

{

Josh McAdams, the guy behind Perlcast, is interviewed over at ClearBlogging. Buried in the interview is the answer to something I've always wondered: his mellow southern accent is from Arkansas.

}

Friday, March 02, 2007

Keyboard shortcuts with Javascript

{

Creating shortcuts on textboxes is none too difficult in Javascript, but (and don't get me wrong - I love Mr. Flanagan) the Rhino book is a bit abstruse. I was adding this functionality to my night project and pared it down to:

function handleKeyCommand(event){
var e = event window.event; // Key event object
var kCode = e.keyCode ¦¦ e.which; // What key was pressed
// I am trapping Ctrl+e (69) here
if(e.ctrlKey && (kCode == 69)){
var theButton = document.getElementById('actionButton');
theButton.click();
}
}

I'm calling that from the onKeyDown event of a TextArea the boring way; because I'm assigning it from the server side in ASP.NET, I have:

actionButton.Attributes.Add("onKeyDown", "handleKeyCommand(event);");

Which translates to onKeyDown="handleKeyCommand(event)"... the Web 2.0 kids would thumb this down since it's not an anonymous javacript function assigned after the page is loaded (I need to question that "inobtrusive javascript" ideology, but it's a post in the making), but this keeps it simple.

The main pitfall for me was in using onKeyDown rather than onKeyPress - the latter is more appropriate for obtaining ASCII related keyboard events, not special keys like shift, control, and so on. Another pitfall was browser compatibility; Flanagan also uses a nifty idiom when he allows the assignment of the event object occur with the operator. It returns the first true value and since an unassigned object returns false in javascript, writing the following assigns a reference to the event object based either on the parameter which would be passed by the browser (Firefox) or the built in window.event object (IE):

var e = event ¦¦ window.event; // Key event object

}

The FizBuzz Conundrum, Ramanujan

{

Imran observed not too long ago that one proof of the difficulty of finding "quality" developers was that he (or she) was encountering a shocking amount of failure among applicants to write code that solved even simple problems. This was picked up for comment by Raganwald, Atwood, and even Hanselman.

I resisted the urge to write up a solution but after that much buzz I thought there's got to be a catch. So this morning, before I "clocked in" from my basement (we're under blizzard conditions here in South Dakota), I wrote up the first thing that came to mind:

for (int i = 1; i < 101; i++) {
Console.WriteLine((i % 3 == 0 && i % 5 == 0) ?
"Fizz-Buzz":((i %3==0)?
"Fizz":(i%5==0)?
"Buzz":i.ToString()));
}


No catches, it seems. But after thinking about it, I thought that a lot of people I work with wouldn't be happy with my solution to that particular problem. It could come across as "convoluted."

The more I thought about it, the more I knew the more acceptable answer was:

// iterate given range
for (int i = 1; i < 101; i++)
{
string output;
// if the number I'm on is divisble by 3 or 5
if (i % 3 == 0 && i % 5 == 0)
{
output = "Fizz-Buzz";
}
// if it is divisible by 3 then set output to "Fizz"
else if (i % 3 == 0)
{
output = "Fizz";
}
// if it is divisble by 5 then set output to "Buzz"
else if (i % 5 == 0) {
output = "Buzz";
}
// if divisible by neither 3 or 5, output the number.
else
{
output = i.ToString();
}
Console.WriteLine(output);
}


And as I think about it, there may be more to this test than just the matter of output - you may be able to get a sense of what type of thinking a person employs in solutions and how their values mesh with them. Even if the answer is "right" it may not be right.

A while back I was feeling some angst toward my employer (when I used to live in California) and put my resume on Monster to see what I was "worth." The first party to express interest went under the guise of an actual company, but really they were just recruiters. They scheduled me for a "test" at 8:30 am in downtown Los Angeles.

At 8:30 am in downtown Los Angeles.

Traffic and personal discomfort aside, I made it to the office where a person who was obviously non-technical gave me a (photocopied?) sheet of paper and a number two pencil to write some javascript code that manipulated the DOM and XML.

I was a little green and was writing stuff like this:

document.getElementById("foo").appendChild(root.createTextNode((entry == foo)?"This":"That")...

You get the picture. I wasn't used to writing things on paper so I was erasing here and there, and because I tended towards multiple steps in one line, my lines were going across the page and I'd curve them upward so I could get it to fit. It was pretty messy, and I'm sure the recruiter picking up the "test" wasn't impressed with how disjointed it was.

And I can imagine the people at the software company, if it ever made it there, looking at smudges and pencil marks and an utter lack of comments on a piece of paper which they'd never be able to verify unless they entered it by hand. I doubt it made it that far but if it did, they might have thought the messy code was indicative of a "messy" mind that didn't write enough comments and consolidated steps too much. It would either go into the "Not a team player" or "Quixotic" pile before it was dumped to the trash.

In defense of myself, or if I may be bold enough to think of my ideals in this light, I keep thinking about Ramanujan, the brilliant Indian mathematician. As an autodidact, he was not familiar with protocol and convention and the step by step approach other mathematicians used... he would skip steps by presenting formulas without rigorous proof in order to arrive to his solutions. Of course this is an unassailable attribute if you're as smart as a Ramanujan and a death blow if you're not.

Now Hanselman has a podcast on the whole thing. I'm going to check it out.

}

Monday, February 26, 2007

What Set You Claim? (Server Software)

{

Royal Pingdom did an analysis of what "popular" sites are running beneath the hood (as easy as a query at Netcraft). Royal Pingdom reveal themselves as a certain "persona" (yeah, I'll overgeneralize for now) by their choice of sites: Technorati, Meebo, Feedburner and so on.

It probably isn't surprising that most of these sites run on Linux with Apache and MySQL involved somewhere on the back end. I'm surprised (of course I'm not in the LAMP game though) to see a bit of a surge in the use of Lighttpd - a more lightweight serving engine than Apache.

As a developer confined to the realm of Microsoft tools it's a bit disappointing albeit unsurprising. What lies beneath the statistics at Royal Pingdom is something bigger and more crushing: the people that seem to be at the forefront of thinking and building the web don't use our tools. Our tools are the favorite of the commoditized environment of your average big company - less thinking and less innovation.

In part I can see a chicken and egg scenario: people building startups and experimenting need a cheap platform upon which to do so. One doesn't license Windows Server, Visual Studio, SQL Server, and so on with a poor [wo]man's budget when comparable free tools exist. In other words, I would assume that some market economics are behind the choice of platform.

But if you're a person like me in the Microsoft space, perhaps a big part of the frustration of working within an environment that lacks passion and quirky inventiveness is that the birds of a feather live in a different place and use a different technology. Of course I work with a lot of people who are excited and innovative - and beyond my coworkers there are quite a few people pushing the envelope with Microsoft tools. But I'd say in general that a corporate developer has a different set of values and goals than the kind of person who would build at a startup. As time passes I see this less on a "success" angle - most types seem to do well enough for themselves - and more of a clustering of similar people.

The bright spark on Royal Pingdom's list is Alexaholic built buy Ron Hornbaker which follows a pattern I'd like to follow as an ideal - that a person can use Microsoft technology (with which I'm quite familiar) and implement any good idea. Beyond that, there is an advantage to a smaller pool of innovators - there is more room for folks like me who may not have the best ideas in the world, but who are good enough to perhaps take something from the startup/open source space and port it.

}

Monsterbugs: Any silver bullets?

{

A few weeks ago our client began to report errors with our Windows Forms (.NET 2.0) application when she'd retrieve certain records. It was a strange bug that would hang the program for about 60 seconds and then crash without reporting errors. We could reproduce it on the test machine, but in development even while pointing to the same database, everything worked. Perfectly.

I looked in the Event Log and noticed the following error:
"Faulting application epicenter.exe, version 1.0.0.0, stamp 45df84bf faulting module kernel32.dll, version 5.2.3790.2756, stamp 44c60f39, debug? 0, fault address 0x00015e02"
Really, really helpful stuff. And especially because this wasn't something we could get in development, on any of our boxes, it was confusing. Google searches weren't giving specific answers - the error seemed to general in the realm of .NET 2.0 to make much of -

So how do you pin something like this down?

My approach was as follows:

// code to load data
MessageBox.Show("Loaded data");
// code to display data
MessageBox.Show("Displayed data");

Our application is not small. The form that displays data contains 3300 lines of non-wizard generated code. Data is loaded from a set of methods in a separate library which itself may have upwards of 3000 lines, not to mention that that library references yet more libraries*... my point here is that it's not a small script to throw a dialog up after each line or call.

In the end I spent about 4 hours stepping through each of the major calls via dialog messages. I couldn't debug since our test machine doesn't have Visual Studio or other debugging tools on it (like all the other machines in their offices).

Although I think we've done a good job breaking the logic into pieces (ie. one method for getting data, one for display that is broken into methods for customizations on each object) it was still difficult to discover.

And in the end, of course, it was something small and subtle: calling the AutoColumnsResize method of a DataGridView can sometimes throw exceptions - because of the recursion of the resizing combined with the paint operation of the Windows Forms application. What was probably most annoying was that it wasn't even my code that was responsible for the hanging exception, it was the framework's inability to recover from an internal exception.

When I first started troubleshooting I thought I should have elaborated more on a "tracing" level in our application - we trace some exceptions but not all to the database. But when I finally found the bug, especially because it wasn't in the code we were responsible for writing, I doubt it would have done more than just save time. A stack trace would probably have helped as well, if caught at the point of the exception. But my big question is whether there are any well trodden techniques for finding and dealing with bugs like this, especially if they are in the framework and not in one's own code. How do you deal with stuff like this, or is it always a slog for which there is not silver bullet?

*I think the design of the application is okay (duh, I'm the one responsible) but it may sound more convoluted in that statement than it actually is. We've got a DataHelper library that is covered by unit tests which does all of our data access at the database level. It runs stored procedures, deals with parameters, and so on. One level of abstraction higher we've got a set of business layer objects for dealing with the entities related to our application: loans, disbursements, checks and so on. The Windows Forms application is what we use to let the user display/enter/modify data. We've got a few additional libraries for tracing, configuration, format, data validation, and Crystal Reports. Not so bad I hope...

}

Friday, February 23, 2007

Configuration Ammendment

{

// get calling assembly settings classstring
assemblyName = System.Reflection.Assembly.GetCallingAssembly().FullName;

I had used the above in my previous code sample to retrieve the assembly name before obtaining settings from the config file. It works only if you are attempting to obtain configuration information from a library that is called by an *.exe. But what if you are in a library (*.dll) and you are using another library to read configuration information as I'd planned? The Assembly.GetCallingAssembly().FullName returns the name of the library, which as I mentioned before is not where the Configuration class naturally looks for settings. Using the following modification:

// get calling assembly settings classstring
assemblyName = System.Reflection.Assembly.GetEntryAssembly().FullName;


Ah, much better. A subtlety worth remembering: Assembly.GetCallingAssembly() returns a reference to whatever the caller, whether it's a library or executable whereas Assembly.GetEntryAssembly() will give you the name of an executable responsible for making that first call to the framework.

Interestingly, in an ASP.NET 2.0 application where the runtime is processing libraries directly, Assembly.GetEntryAssembly() returns a null.

}

Thursday, February 22, 2007

Settings, Configuration, .NET 2.0

{

A while back I complained about configuration within Windows Forms applications, mostly because I lacked an understanding of the API. I hacked a simple xml file together wherein I could store simple name value pairs that we'd utilize for the application and surprisingly it's been the approach for quite some time.

I've been studying for the Microsoft 70-552 exam which would update my "MCAD" certification to "MCPD." I know, I know, certification is frown upon by so many people who think I should really be reading The Little Schemer to do cool parlor tricks. But this is a case where what I'd said earlier about certification rings true: it probes for weakness and exposes where you "fake it" with hacks without understanding the real structure and purpose of the technology. Case in point, configuration.

In my earlier post, I'd used Configuration.AppSettings which I now know as deprecated. Instead there's a nifty configuration/settings API one can leverage. What I've done here is based very heavily on Chris Sells's Windows Forms 2.0 Programming although I took liberty to modify some of the code to make it more reusable and generic (his intent was to show basics).

The first stop one needs to make is to add a Settings file to the project along with a reference to System.configuration (not sure why configuration is not Configuration).



Underneath the properties node if you "edit" the settings file, it's really a grid that allows you to enter settings with a key, datatype, scope, and value. The scope in here can be either as a user setting or an application setting - it's also possible to write your own section handler and extend the model.



After compiling this is converted into your app.exe.config file - the physical storage of your settings in the xml format well know to config files.



The code for retrieval is still, in my own view, a little verbose but it's easy to develop a simple accessor helper class. Even more slick in the design of the .NET Framework is that class library projects (DLLs) pull configuration settings from their hosted EXE so you the utility code here is from a DLL designed to be referenced and used from any application.

using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace SettingsGroperLib
{
public enum SettingType {
userSettings,
applicationSettings
}

public class ConfHelp
{

public static string GetConfSetting(SettingType settingType, string settingKey) {
// obtain current configuration
Configuration currentConfig =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// obtain section utilizing enumeration
ConfigurationSectionGroup group =
currentConfig.GetSectionGroup(settingType.ToString());
// get calling assembly settings class
string assemblyName = System.Reflection.Assembly.GetCallingAssembly().FullName;
// yah, it's ugly, but it works
string friendlyName = assemblyName.Split(',')[0];
// obtain section by combining friendlyname to settings class
ClientSettingsSection section =
(ClientSettingsSection)group.Sections.Get(
String.Format(
"{0}.Properties.Settings",
friendlyName
)
);
// get setting key
SettingElement element =
section.Settings.Get(settingKey);
// return settings value as
return element.Value.ValueXml.FirstChild.Value;
}

}
}

Sorry about the format; you can download a nice formated version here.

It all seems so easy once you take the time. I think the unlearning was a big obstacle for me since working with config files was something I did all the time in .NET 1.x and old habits die hard. Oh yeah, the retrieval:

string test = ConfHelp.GetConfSetting(SettingType.applicationSettings, "DBUrl");

}

Monday, February 19, 2007

Top Ten Mistakes of Web Design

{

Jakob Nielsen just updated his list of top ten mistakes a web designer can make. I've got no clout like he does but my number one annoyance in web design is when people work against the browser.

The best example of this in my mind is the back button. On so many projects I've had "issues" submitted related to the use of the back button and had to write code to try to cheat the browser into not allowing its use. But the back button is there for a reason and working against the browser is almost always futile: trying to prevent using backspace, alt+arrow, right clicks, programmable mouse buttons, pasting to multiple browser sessions... at what point do we just allow users to keep their control?

I like apps that tolerate issues related to browser control - they let you do it but when they croak, it's an edge case that they aren't willing to reprogram the entire system for. I wish more people would grok the fact that browsers simply aren't fat clients and they've got to share control.

}

Language and Thinking

{

I'm fortunate enough to be sitting in on some training and the ice breaker at the beginning was to say which language one liked the most. Most in the room went with what they use for work, C#, but of course I had to break the flow and say I prefer Perl and Javascript in terms of raw language more than anything at the moment.

Talking about it later I brought up the old Sapir Whorf notion of language affecting thinking and problem solving and it's funny how you have a thought and seems to start jumping out at you all over the place. Tonight I ran into (courtesy of Raganwald) the following quotes regarding that idea:

"The connection between the language in which we think/program and theproblems
and solutions we can imagine is very close. For this reasonrestricting
language features with the intent of eliminating programmer errors is at best
dangerous." - Bjarne Stroustrup

"The very fact that it's possible to write messy programs in Perl isalso what
makes it possible to write programs that are cleaner in Perlthan they could ever
be in a language that attempts to enforcecleanliness. The potential for
greater good goes right along with thepotential for greater evil." - Larry Wall

}

Wednesday, February 14, 2007

Wow

{

Microsoft's Vista Ad - quite a contrast to the Apple commercials. To the degree that commercials evoke a sense of a company's ideals, it's telling of something I've always thought of when comparing Microsoft to others - they are trying to solve harder problems than the home movie or virtual greeting card.

Of course, they could just be playing to my ideals and trying to make money out of it...

}

Saturday, February 10, 2007

Vote Hanselminutes

{

I'm just echoing the words of Chris Sells's post to vote for Hanselminutes on Podcast Alley. It's my personal favorite among technical podcasts.

}

Wednesday, February 07, 2007

Queues with SQL Server 2005 Service Broker and C#

{

I recently had to set this up and didn't find all too many resources online. I don't have time for a full commentary but suffices to say this: SQL Server 2005 has some excellent reliable messaging capabilities through what's called Service Broker. If you, like me, are a complete skeptic when it comes to new products, this is what I think of as a compelling feature. In the following example, I'm setting up a queue for FileIDs - assume these are identifiers for files that need to be processed asynchronously. After I created my database in SQL 2005, I opened up the query tool and went ahead with the following TSQL:

-- you can attribute an hour to finding this requirement :(
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Password1';
GO


-- message, contract, queue, service creation
CREATE MESSAGE TYPE FileIDForQueue
VALIDATION = NONE;
GO

CREATE CONTRACT FileQueueContract
(FileIDForQueue SENT BY INITIATOR)
GO

CREATE QUEUE dbo.FileIDReceiverQueue
GO

CREATE QUEUE dbo.FileIDSenderQueue
GO

CREATE SERVICE SenderService
ON QUEUE dbo.FileIDSenderQueue
GO

CREATE SERVICE ReceiverService
ON QUEUE dbo.FileIDReceiverQueue (FileQueueContract)
GO


In order to leverage the queue, I wrote the following stored procedures to enqueue, dequeue, and peek:

/*
STORED PROCEDURE RESPONSIBLE FOR INSERTING A QUEUE ITEM
*/
CREATE PROC spSendFileToQueue
@FileID INT
AS
BEGIN TRANSACTION;
DECLARE @conversationID UNIQUEIDENTIFIER
BEGIN DIALOG CONVERSATION @conversationID
FROM SERVICE SenderService
TO SERVICE 'ReceiverService'
ON CONTRACT FileQueueContract;
SEND ON CONVERSATION @conversationID
MESSAGE TYPE FileIDForQueue(@fileid);
--END CONVERSATION @conversationID;
COMMIT TRANSACTION;
GO

/*
STORED PROCEDURE RESPONSIBLE FOR RETRIEVING QUEUE ITEMS IN FIFO STYLE
*/
CREATE PROC spGetFileFromQueue
@FileID INT OUTPUT
AS
RECEIVE TOP(1) @FileID = CONVERT(INT, message_body) FROM FileIDReceiverQueue
GO

/*
STORED PROCEDURE RESPONSIBLE FOR "PEEKING" INTO QUEUE
*/
CREATE PROC spPeekFileQueue
@FileID INT OUTPUT
AS
SELECT TOP(1) @FileID = CONVERT(INT, message_body) FROM FileIDReceiverQueue
WHERE message_body IS NOT NULL
GO


Now that my stored procedures are in place, I can test in TSQL:

-- to send it to the queue:
spSendFileToQueue 45

-- peek into the queue
DECLARE @F INT
EXEC spPeekFileQueue @FileID=@F OUTPUT
PRINT @F

-- to get it back
DECLARE @F INT
EXEC spGetFileFromQueue @FileID=@F OUTPUT
PRINT @F


From here it's trivial to port the procedure calls to C#:

public static void RunActionProc(string procName, SqlParameter parm) {
SqlParameter[] parms = new SqlParameter[] { parm };
RunActionProc(procName, parms);
}

public static void RunActionProc(string procName, SqlParameter[] parms)
{
SqlCommand co = new SqlCommand(procName, GetConnection(true));
co.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter parm in parms)
{
co.Parameters.Add(parm);
}
co.ExecuteNonQuery();
}


public static void Enqueue(int value)
{
DBHelper.RunActionProc("spSendFileToQueue", new SqlParameter("@FileID", value));
}

public static int Peek(){
SqlParameter fileIdParameter = new SqlParameter("@FileID", SqlDbType.Int);
fileIdParameter.Direction = ParameterDirection.Output;
DBHelper.RunActionProc("spPeekFileQueue", fileIdParameter);
return Convert.ToInt32(fileIdParameter.Value);
}

public static int Dequeue() {
SqlParameter fileIdParameter = new SqlParameter("@FileID", SqlDbType.Int);
fileIdParameter.Direction = ParameterDirection.Output;
DBHelper.RunActionProc("spGetFileFromQueue", fileIdParameter);
return Convert.ToInt32(fileIdParameter.Value);
}


A sample project in C# can be found here.

}

Saturday, February 03, 2007

The Future of Programming Languages

{

Imagine being able to pull Anders Hejlsberg, Chief Architect of C#, Herb Sutter, Architect in the C++ language design group, Erik Meijer, Architect in both VB.NET and C# language design, and a programmer's programmer, Brian Beckman into a conference room and have an hour's worth of conversation on programming languages - to hear about composability and functional programming and abstraction from people whose decisions literally shake our world from the top.

This recent video on Channel 9 is just that.

At the end, when they are getting kicked out because someone else is scheduled for the room I can't help but laugh. Guys like Anders Hejlsberg get kicked out of conference rooms too eh? They must be human.

Here are some quotes:

Anders -

"language is like the color of your glasses... "

Beckman -

"Scheme is sort of God's Lisp with all the noise boiled away..."

Meijer -

"By definition you cannot have too much abstraction because abstraction means leaving out the unnecessary detail. So if details are unnecessary you can abstract... sometimes you abstract from necessary details but that isn't true abstraction because you've taken away necessary detail"

}

IDE Distrust

{

Some time back I read Charles Petzold's essay Does Visual Studio Rot the Mind which concerned itself with some of the negative aspects of how our tools drive us rather than us driving our tools. It's not just a handful of occasions where I've been called over to "troubleshoot" when a person's intellisense (or autocompletion) isn't popping up what they are expecting.

But Visual Studio does impress upon you the wrong ideas sometimes.



In this case it will show an error for a missing mime type on a script tag. Granted, this may be some part of XHTML validation but after listening to Douglas Crockford (and also, incidentally, running into it in the Rhino book), I discovered this type attribute isn't leveraged by any existing browsers.



If you give in for the sake of XHTML and supply this attribute, you'll notice that Visual Studio suggests text/javascript which is actually incorrect. It should be application/javascript.



Here is something even more concerning - Visual Studio is suggesting two parameters for a method that actually only requires one (I looked in the Rhino book).

Visual Studio is a great tool, don't get me wrong - as much as I'd love to be an Emacs junkie and do my demonstrations in it while showing off my profficiency, I like how effecient Visual Studio is at allowing me to focus on my code - not my libraries, or my classpath, or anything else.

With that said, it's important to master the tool, as opposed to being mastered by the tool. A healthy amount of distrust seems necessary to get the best out of it.

}

Thursday, February 01, 2007

Founders At Work

{

I'm looking forward to reading Jessica Livingstone's book, Founders At Work, which consists of interviews with various techie entrepreneurs. Joel Spolsky's interview, however, is available as a freebie and makes for some interesting reading. I've been a Joel "fanboy" for a while but it still impresses me how each time he writes (or comments) at length there's so much truth from which to learn.

There are several other interviews I'm looking forward to reading, particularly Philip Greenspun's on the making (and possibly breaking) of Ars Digita. A few years ago Philip did an interview on IT Conversations that impressed a lot of "lessons learned" upon me.

But back to Joel, the interview is insightful and there are many gleanings on consulting, founding, competition, learning, and making good software.

I'll get to the Woz interview this weekend.

}