T4 Slays Spaghetti Monster

My client wanted a list of all of the tables and their respective columns in a given SQL server database.  My first instinct was to get Visio to create an ER diagram by reverse engineering the database. However, with dozens of tables in this database, the diagram that Visio spit out looked like spaghetti and meatballs, and would have printed across 36 8.5″x11″ pages. That said, Visio did a better job laying out the diagram than I would have by hand.

Then I thought, what if I had an automated way to create a document that listed the tables in alphabetical order, showing all of their columns? This list would be something that the client could cross-refrence against the spaghetti monster. Well, thanks to T4, I do have such an automated way. I spent my lunch break hacking away (it’s scary to see how much you rely on Intellisense once you don’t have it) at this simple template that will iterate through all the tables in a database and output all the columns for each as a text file. To get it work,follow these steps:

  1. Download the template file (all_table_columns.tt).
  2. Copy it to any Visual Studio 2005/2008 project.
  3. Open it, replace “[your connection string here]” with a valid SQL Server connection string (ideally to a database with a limited number of tables), and then save the file.

Visual Studio attempts to generate the output whenever you save the template file, so the new text file should already be generated.  To view it, go to the Solution Explorer window and expand the node for all_table_columns.tt and you will see a file named all_table_columns.txt. Open that text document and you should have a list of all tables and columns!

For more on code generation via T4, see Scott Hanselman’s link-fest of a post.

Baby Steps to Code Generation

Write code snippets today and you can roll them into more robust code generation templates later.

Goal: get to the point where you click one button and the code for your whole app is written for you automatically.

Reality: Most business problems are more complex than just performing CRUD operations on a single table at a time, and I haven’t found a solution that can autogenerate such complex logic.

In the mean time, I’m finding the Code Snippets feature in VS 2005 to be a step in the right direction. The best part is that there is little to no effort lost in creating snippets as you go. If you later decide to go with a template-based code generator like CodeSmith.  When that time comes, you can use a little regEx magic to roll up those snippets into more robust templates.

Web-Based Productivity Tools

This post goes out to my friends Brian and Jeremy who endured a lengthy discussion with me last night about web-based productivity tools. It’s also a follow up to my earlier post on Web-Based Project Management Tools.

First thanks to Jeremy who told me about Google Notebook, which allows you to copy text and images from any web site to a “note” that lives on Google’s servers and is accessible via your Google login. So far I can see using this like an extension of my backpack account which doesn’t allow me to upload images.

It just so happens that after last night’s discussion, this morning I listened to a Hanselminutes podcast about micro-increases in productivity (like when it takes too long for the start menu to come up) and he mentioned the TiddlyWiki. This has been blowing my mind all day. Essentially it’s a wiki that you can run anywhere (at home, at the office, on your web site if you have one) because it’s just an HTML page with embeded javascript code that does all the work. I’ve been tiddlyWiking all day and comparing it side by side with my backpack pages to see which is better at managing my project data.

Some TiddlyPros:

Some TiddlyCons:

  • There’s no database – and you know javascript is going to bail while trying to save a file on your local machine at least once (esp. as those files get large).
  • It’s not a great tool for more than one user, or for publishing data publicly.
  • It’s best suited for tech savvy folks who can handle any issues that come when, say, you want to upgrade or extend your page and all of your data, business logic, and presentation settings are stored in a single file.

So far, I’m impressed though. The TiddlyWiki is truely a software revolution.

Ruby on Rails in 5min

Using an unbelievable RoR environment for PCs called InstantRails I had created my first RoR app in just a few minutes.

As the majority of posts on this blog will tell you, I’m a .Net guy, but some recent experiences working on web sites I created a while back in PHP have left me with some second thoughts about the universaility of ASP.Net as a web development tool. Couple that with the recent Hanselminutes podcast on RoR, and the fact that my PHP hosting company just started fully supporting RoR, I decided to write my very own RoR “Hello World”.

Turns out I didn’t even need to wait for my hosting company to come around, since there is an unbelievable environment for PCs called InstantRails, which installs not only Rails and Ruby, but MySQL and Apache! With the help of Matt Griffith’s screencast on how to install the environment I had created my first RoR app in just a few minutes. The only glitch I ran into was not having Ruby’s bin folder location in my PATH variable – do that before walking through the screencast and it should work like a charm.

Next you’ll want to check out these screencasts from 37Signals. They illustrate how to take advantage of RoR’s built-in features like ActiveRecords, scaffolding, and migrations – the reason for using RoR in the first place. They even have a screen cast on how to consume the Flikr API w/ Ajax.

All in all, I can’t believe how quickly I was able to get something up and running, especially considering how daunting the installation instructions from my hosting company were.

Web-Based Project Management Tools

activeCollab vs. Basecamp and Backpack

I’ve been using Backpack from 37signals to keep both my personal and professional lives organized. Right now, my backpack is bursting at the seams as I’m pushing it to the limits of what it was intended to do, so I’ve been considering moving to 37signals‘s full-fledged project management tool, Basecamp. Then I found out my hosting company already provides the open source port of Basecamp, activeCollab for free.

I’ve been giving activeCollab a test drive, and all in all, I’d have to say it’s OK. I think they got the big stuff right: managing projects, clients, users, milestones, and lists is straightforward enough. What activeCollab is missing is the warm and fuzzy, ajaxy features that make 37Signals a hit with non-technical users (including my wife and mother-in-law). Since that set of users includes my clients, I won’t be switching over activeCollab yet.