July 2006

My Journey to Ruby On Rails - Part One

I’m going to begin a series of posts on my journey to learn Ruby On Rails. My professional experience has been primarily as a C++, Java, and C# programmer. I’m totally new to Ruby the language, and the Rails framework.
I have read and created the sample application described in the following tutorials by Curt Hibbs on Oreilly’s OnLamp site:

Very nice job with these tutorials Curt, I think they are a great introduction to Ruby on Rails!
I really enjoyed the book The Pragmatic Programmer: From Journeyman to Master by the Pragmatic Programmers, so I went ahead and ordered the following

I’ve found that I don’t really learn a programming language or new framework until I try and apply it to a real world problem. So, what I’ll be doing is creating a simple public web application that will be modified in sync with my blog posts.

What I was thinking of creating would ultimately be an AJAX style web application that would allow users to enter in url’s to Ruby or Rails tutorials, tag and rate them.
The web application probably won’t be useful for anything else except as a complement to this blog post series, but I think it would be very useful for someone else with a similar background to me to be able to read through my posts, and follow along and see the web application develop.
A good friend of mine, Pete, had a cool idea; he suggested that along with the public web application, I should publish a page with the results of the rake stats output, so the total lines of code in the application are available at a published url.
What I’m looking for help with right now is any Ruby or Rails tips or links to good tutorials that people would be able to share by commenting on this post. What I think would be cool as the application develops would be to review any comments posted for suggestions as to better ways to approach what I’m doing in the application or what new features we could add to the application to show off Ruby On Rails.

ruby
rails

Comments (0)

Permalink

Search Engine for Code

If you write code, you have to check out Krugle! It’s a search engine for code. Let’s take it for a test drive.

  1. Go to http://www.krugle.com/
  2. In the Search box enter Activator.CreateInstance
  3. Select C# as the language
  4. Click the search button.

Pretty cool. But wait, there’s more!

  1. Click on the ActivatorFactory.cs from the Apache ibatis project. This came up as the first result when I searched.
  2. You’ll see a tab open, that contains the source file, and a tree view of all the files in the project on the right. It would be even better if the code was syntax highlighted.
  3. From there you can save the file locally, or browse the project in the tree view.

tools

Comments (0)

Permalink

Great HTTP Debugging Tool

Fiddler is my favorite HTTP debugging tool. It shows you performance statistics, multiple views of the HTTP request and responses, and even an HTTP request builder.

This MSDN article will help you get started.

tools

Comments (0)

Permalink

The NotImplementedException

The NotImplementedException is a very simple, but useful class. It’s intent is to indicate, obviously, that a method is not implemented yet. This is very simple to search for while editing code and also something you can’t miss at runtime.

Okay, let’s give it a try. Open up any C# project, move inside any method, and type a call to a method that you are sure does not exist. For example:

TestNotImplementedException();

Select the above text, right click and choose “Generate Method Stub”. If you were surprised as I was that instead of generating:

throw new NotImplementedException();

Visual Studio generated:

throw new Exception("The method or operation is not implemented.");

Read Anson Horton’s blog post that describes why the decision was made, and how by editing a snippet file you can change the default behavior.

c#
.net

Comments (0)

Permalink

A tool all .NET developers should have - Reflector for .NET

Lutz Roeder’s Reflector for .NET is a tool that I think every .NET developer should have in their toolbox.

It’s a great class browser. It has an analyzer feature to show you what each type depends upon, and what other types it’s used by.

It also contains a dissasembler, which is very helpful when you are trying to debug tough problems.

Reflector also support an Add-In model. There are a bunch of Add-In’s available - everything from code metrics, to code coverage to dependency graphs.

tools
.net

Comments (0)

Permalink

Visual Studio Keyboard Tip #4 - Outlining

Wouldn’t it be great if you had the ability to make all the other code in the text editor disappear, so that you could just focus on the one method you are working on?

That would be really cool. Unfortunately I have no idea how to do that. But I can show you the next closest thing….outlining!

Open up Visual Studio 2005, and create a brand new Windows Application Project.
Expand the Form1.cs file in the Solution Explorer, and open up the Form1.Designer.cs file.

You’ll see there is some grey text at the bottom of the screen “Windows Form Designer generated code.” Hmm, let’s see what type of code was generated.

CTRL + M, then CTRL + P

You should see that the whole file is now visible — all outlining has been removed. Cool. Next let’s collapse the whole file down.

CTRL + M, then CTRL + O

That’s a letter O by the way. Now you should see a very clean higher level view of what’s contained in the file. Next to each region you’ll see a + that you can use to expand the region. Don’t reach for the mouse yet. Since this is a keyboard tip, we should really review the keyboard shortcut to expand and collapse a region.

Move to line 23 (CTRL + G, then enter 23). You should be on the “Windows Form Designer generated code.”

CTRL + M, then CTRL + M

That region should have expanded. Now move to line 29 (CTRL + G, then enter 29). You should now be on the InitializeComponent method.

CTRL + M, then CTRL + M

The region expands. If you enter the same keyboard combinations again, the region collapses.

One last tip. Let’s expand the whole document again.

CTRL + M, then CTRL + P

Move to line 32 (CTRL + G, then enter 32). Select the text on line 32 and 33.

CTRL + M, then CTRL + H

Pretty cool, huh? Those two selected lines have now been collapsed inside the method down to an ellipsis. This only works in C#, there is no other outlining being done in the whole file, and text is selected.

visual studio
keyboard

Comments (0)

Permalink

WeakReferences

A WeakReference allows you to hold a reference to an object while allowing the garbage collector to reclaim it.

What ??

Sounds strange at first, but it can be very useful. For example, you could have a rather large object created to present data to a user. You might keep a WeakReference around after you set the “strong reference” to the object to null when the user cancel’s out of the screen.

If the user were to open that screen up again, you could check the Target property of the WeakReference to see if the large object has been garbage collected yet. If the Target property is not null, you can create a new “strong reference” by setting a normal reference type variable to the WeakReference.Target property.

Since there is now a “strong reference” to the object, it will not be reclaimed by the garbage collector.

Here’s a great WeakReference blog post by Brad Abrams, which includes comments from a developer on the Microsoft CLR team.

This article Using Weak References provides details on the difference between a long and short weak reference.

c#
.net

Comments (1)

Permalink

ReaderWriterLock Synchronization Class

The ReaderWriterLock class is a great alternative to other sychronization methods when you have situations where you have infrequent short duration writes, and a high frequency of reads.

This class is designed to allow concurrent access for multiple readers threads, or write access for a single thread.

The msdn help article provides a good example to demonstrate how it can be used.

c#
.net

Comments (0)

Permalink

My new coding font for Visual Studio

Microsoft released Consolas which is now my coding font of choice. It’s very clear and easy to read.

I found that I had to increase the font size to 11 which I didn’t have to do with other fonts. Overall, it’s a great coding font.

visual studio

Comments (0)

Permalink

Visual Studio HTML Editor Navigation

If you code ASP.NET websites, you need to read Scott Guthrie’s Blog.

In this post Scott demonstrates a great feature of the HTML editor in Visual Studio. When you switch from design to source view the editor keeps the same position.

For example if you select some text that appears in the design view, then switch to source view the selection will automatically be set to the same text.

This feature can help save lots of scanning around an html file.

visual studio
keyboard

Comments (0)

Permalink