Friday, August 04, 2006
Tuesday, August 01, 2006
My Journey to Ruby On Rails - Part One
I have read and created the sample application described in the following tutorials by Curt Hibbs on Oreilly's OnLamp site:
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 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.
Search Engine for Code
- Go to http://www.krugle.com/
- In the Search box enter Activator.CreateInstance
- Select C# as the language
- Click the search button.
- Click on the ActivatorFactory.cs from the Apache ibatis project. This came up as the first result when I searched.
- 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.
- From there you can save the file locally, or browse the project in the tree view.
Sunday, July 30, 2006
Great HTTP Debugging Tool
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:
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.
Saturday, July 29, 2006
A tool all .NET developers should have - Reflector for .NET
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.
Visual Studio Keyboard Tip #4 - Outlining
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.
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.
ReaderWriterLock Synchronization Class
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.
Friday, July 28, 2006
My new coding font for Visual Studio
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.
Thursday, July 27, 2006
Visual Studio HTML Editor Navigation
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 Tip #3 - Formatting
Format Document: CTRL + E, then D
Format Selection: CTRL + E, then F
If you have any syntax errors in your code then the formatting features do not seem to work. So, if you are trying to use the keyboard shortcuts to format a document and it doesn't seem to be working, then check your code.
The formatting engine is great. You are also able to customize what the format style you want to use for each language you work with. Go to the Tools menu, click Options. Select Text Editor, then the language, for example C#. Expand the node in the tree (C# in this case) and you'll see either a Format or Formatting child node. Once you select that you'll see the options available to you.