August 2006

Ruby On Rails - Part Four - Rake

I have always been interested in automating common development tasks. I have used Ant, Maven, and Nant pretty extensively and now I’m learning the details of Rake. There’s something special about seeing messages fly by in a command shell, and know that the computer is doing all these repetitive tasks — not you!

What is different about Rake then any of the others build tools mentioned is that you create a Rakefile by writing Ruby code, instead of using xml. There is a

I would recommend you read this excellent article on defmacro.org (take your time and read through it — it’s really worth it) that does a good job of explaining the benefits of Lisp. A cool thing, since we’re talking about build automation, is one section, titled “Ant Reloaded”, talks about how Java could have been used instead of XML. In our case it’s Ruby being used in a Rakefile.

This tutorial is written by the developer of Rake, and is a good tour through the main features of Rake. I would suggest you read it first, followed by this article by Martin Fowler which reviews some examples of interesting things you can do with a Rakefile.

I created a simple example Rakefile. I’m sure no one would actually need a script like this, but the simple scenario was good for an example of how to use Rake.

I’ve included the code below, the formatting is off because I pasted it in my blog editor, but I hope it will be a good example to someone just getting started with Rake. If you have any suggestions on how to improve this simple Rakefile example, please add a comment to this post.

# ———————————————————-

# This is just an example to illustrate how to use Rake

# By Rob Herbst

# ———————————————————-

# Require rake/clean to get the built in clean task

require ‘rake/clean’

# Require ftools to get File.copy

require ‘ftools’

# Define constants we’ll use later

HTML_SRC_DIR = “html”

WEB_DEST_DIR = “website”

IMAGES_DIR = “images”

SITE_MAP = “sitemap.html”

HTML_SRC_FILES = FileList[“#{HTML_SRC_DIR}/*.html”]

IMAGE_SRC_FILES = FileList[“#{HTML_SRC_DIR}/*.jpg”]

# Add the WEB_DEST_DIR to the list to get cleaned

CLEAN.include(WEB_DEST_DIR)

# The default task depends upon the package task

task :default => [:package]

# The package task depends upon clean, create structure, and the task to create the site map file.

task :package => [:clean, :create_structure, :sitemap] do

     puts “The package task was called.”

             # Copy over the html files

     HTML_SRC_FILES.each do |f|

          File.copy(“#{f}”, “#{WEB_DEST_DIR}”)

     end

             # Copy over the image files

             IMAGE_SRC_FILES.each do |f|

          File.copy(“#{f}”, “#{WEB_DEST_DIR}/images”)

     end

end

# Utility task to create the structure of the website

task :create_structure do

     puts “The create_structure task was called.”

     Dir.mkdir(WEB_DEST_DIR)

     Dir.chdir(WEB_DEST_DIR)

     Dir.mkdir(IMAGES_DIR)

     Dir.chdir(“..”)

end

# Task to create the sitemap.html file

task: :sitemap do

     open(“#{WEB_DEST_DIR}/#{SITE_MAP}”, “w”) do |outs|

          outs.puts “<html><head>Site Map</head><body><ul>”

          HTML_SRC_FILES.each do |f|

               file_name = f.sub(HTML_SRC_DIR + “/”, “”)

               outs.puts “<li><a href=\”#{file_name}\”>#{file_name}</></li>”

          end

          outs.puts “</ul></body>”

     end

end

ruby
rails

Comments (0)

Permalink

Team Foundation Server Project Guidance

Eric Lee’s blog post provides some guidance into how Microsoft sets up the Areas for a Team Project in Visual Studio Team System.

I know this has been a source of a little bit of confusion for TFS users, so it’s nice to see an example of how Microsoft is using the feature internally.

Thanks for the post Eric, would it be possible for you to show us an example of how you setup the Iteration tab too?

visual studio
c#
.net
tfs

Comments (0)

Permalink

Google Rss Reader is very cool

I have recently switched my RSS aggregator to Google Reader. This app is still officially in the Google Labs environment, so once in a while there will be a slight hiccup. But, overall I have found this to be a great rss reader.

It has full keyboard support!

  • J to move down article list
  • K to move up article list
  • SPACE to page through a long post, then when the end is reached it moves to the next unread item in your list

It also has support for tags or categories, or labels as Google calls them, which comes in handy if you want to categorize your feeds. You can also share your “starred” items, this feature I have not checked out yet, but it seems interesting.

If you go to the familiar Google search box at the top, it allows you to search for new blogs on a topic. For example, go to the search box at the top, enter “Rob Herbst”, then hit the button labeled “Search for new content”. Now click on the subscribe button….only kidding.

Google Reader also supports mobile devices, which is great if you have to catch up on your feeds on the go.

This post on the Google Reader Blog reviews a sample of what the top errors in the xml feeds that the development team sees. Pretty interesting to see the number two is mismatched tags!

Overall, I think this is a great rss reader that is definitely worth checking out.

Update 8/11:

My friends Pete and Nick don’t like Google Reader. I guess it all comes down to your personal workflow. I used to read my blogs in a similar fashion but that just didn’t work for me. I realized that I had subscribed to way too many blogs, and there was no way I was ever going to have time to read them all. I’m glad that method works for Pete & Nick.

Actually, looking at all those unread items in my Newsgator/Outlook newsreader made me feel like I wasn’t able to keep up — very unmotivating for me. So what I did was to radically trim down the number of feeds that I read. It was difficult to do, but I tried to look at each one and really determine if I was really getting any value from it.

I was able to cut my subscribed list down to just a handful, so the approach that Google Reader takes works perfectly fine for me. I only get about 15-20 new posts per day, so cruising through them in the one place is okay with me. I guess, it also resonates with my Getting Things Done experience. With this approach I have an inbox, where I process the items one at a time. I understand that if you have a much larger & varied subscription list this approach doesn’t seem to work well.

As for keeping entries for future reference, you can either “star” them, or inside the view when you are reading the item, you can check the “keep unread” and it will be displayed until you manually clear it.

I do have to say I was on the train today and I was very happy being able to read my blog entries on my smartphone (which is true of any server based aggregator). That was very cool!

Anyway, Pete & Nick, I’m sorry you guys don’t like Google Reader, but like I mentioned at the top I think it all comes down to personal workflow in how you read your feeds. Both of you seem to have a similar approach were a tool like BlogLines or Newsgator is a better fit.

web

Comments (2)

Permalink

If you want to create better software….

If you are interested in creating better software, you should subscribe to the “Creating Passionate Users” Blog right away!

I have found almost every post to be thought provoking and very insightful.

Read this post Are your users stuck in “P” mode, then come back. I’ll wait right here.

Ok great, your back!

As a developer myself, I know that finding the right size of both the green and purple circles requires a lot of hard work. (You did read the article…right?)

There is a great deal of complexity and context that any developer has to keep in their head in order to write code effectively. It’s hard for a developer to step back sometimes and see the bigger picture. Yes, we as developers might think a feature is very cool, but is the user really going to care?

It is much easier for a developer to provide a bunch of options on what the user could do and let them figure it out, instead of focusing on the much harder problem of what the user is really interested in doing, and how can we streamline that as much as possible.

In order to get that kind of feedback, you really need to do usability testing. Watch users trying to use your application, and see what they are having trouble with. Refine and simplify your user interfaces until they feel natural, and don’t require you to review the online help.

I also think once users figure out a way to do things — even if it’s very time consuming, they sometimes don’t take a step back and explore the other features offered in a program that might make their task easier.

We as developers need to make this an easier and less scary thing for the users to do. And users, some of us developers have really been trying, have some of our approaches been that great, no not really, but the thought is there.

The one area currently that I see that seems to find a good balance is the use of screencasts. This gives the users a very low stress way of having new features demonstrated to them. It’s just watching a movie, there’s no way that could do anything bad to the users data. I think a well produced screencast demo, with an underlying voice track that guides the users through the process should be used for each critical feature in an application.

I have seen some progress being made in the new generation of web and desktop applications, but we as developers still need to do more.

programming

Comments (0)

Permalink

Host the CLR in C++

Calvin Hsia’s blog post provides a pretty neat example of hosting the CLR in C++, which then calls a VB.NET object that emits a new type into the runtime, then invokes its Main method — which includes dynamically generated code passed in as a parameter from C++.
Obviously, this is not the recommended method to show a message box. :-)

But it does give an interesting example of different ways to interop between managed and unmanaged code.

Thanks for the cool example Calvin!

c#
.net

Comments (0)

Permalink

MSDN Wiki!

I don’t know how long this has been available, but MSDN has a wiki!

I read about it first in Shawn Steele’s Blog. What is very cool is there are a number of Microsoft developers that are adding comments.

Here are some helpful entries I’ve found:

  • David M. Kean’s post: breaking changes to System.Uri.
  • Adam Nathan’s post: details of the Type Library Exporter.
  • Craig Skibo’s post: Visual Studio Automation object oversight.
  • Ken Cox’s post: details on encrypting connection strings in your web.config file.

There was a very minor positioning issue when using FireFox, the header for each content submission was aligned incorrectly.

Overall a very good resource that I’m going to be checking out more often.

visual studio
c#
.net

Comments (0)

Permalink

Ruby On Rails - Part Three - The Ruby Language

I like to dig in and learn the details of any programming language that I’m working with.

Here are some of my thoughts from my first read through of some of the Programming Ruby book. You can read the first edition of Programming Ruby The Pragmatic Programmers Guide online at RubyCentral.com..

Things I like about Ruby:

  • No explicit self. I really liked the Python language, but there were two things that got to me, the explicit self, and the __.
  • Overall, syntax seems very clean.
  • Builtin string expression interpolation using the #{name} syntax.
  • Good regular expression support.
  • Code blocks, closures and the yield statement.
  • printf
  • mixin support through modules
  • here document support
  • operators as methods you can override
  • parallel assignment
  • good class library
  • built in threading support (Ruby threads)
  • simple interop with C code

Things I’m not so sure of yet:

  • Coming from the statically typed world of C++/C#, a dynamically typed language takes a bit of getting used to. I am familiar with the concepts from using Python, but it’s something that I’m still not completely used to.
  • There are probably a whole lot of semicolons that I’m going to be deleting from the end of each line of my code. :-)
  • $, @, @@ used to indicate the type of variable. The development teams I’ve worked on have standardized on a variable naming convention, for example a leading underscore to denote member variables. In Ruby, it looks like this decision was made once for the language, which is good — I’ll just have to get used to the symbols used.
  • rescue instead of catch & ensure instead of finally is going to take some getting used to, with catch and throw meaning something a little different.

It’s a pretty short list of things I’m not sure of, and most of them are just observations on how things are different that what I’m used to. I’m looking forward to working more with Ruby, and I’ll come back to this list at the end of this blog post series.

ruby
rails

Comments (0)

Permalink

Visual Studio Keyboard Tip #5 - Code Snippets

When I first saw code snippets in the Eclipse IDE a few years ago, I thought it was a great feature. It’s nice to see it included in Visual Studio 2005.

Let’s take a quick tour.

  1. Open up visual studio, and go to any C# code editor window.
  2. Position the cursor inside a method and enter CTRL + SPACE

Code Snippet Dropdown

In the dropdown that appears, look at the icon next to the #if or #region — that icon indicates the entry is a code snippet. Ok, next step:

  1. Type for
  2. This should set the selected index of the dropdown to the entry for.
  3. While for is selected enter TAB, then TAB again.

You should see this:

For Code Snippet

The caret is positioned on the i. Type the following word - index. Then hit TAB. You should see that all instances of i are replaced with index. Pretty cool.

Even better, all code snippets are defined in an xml format that you can edit.

  1. Enter the following keys CTRL + K, CTRL + B. This should bring up the code snippet manager.
  2. Expand the Visual C# node, then select for, in the location label right between the Language dropdown and the treeview gives you the location of the xml for the code snippet.
  3. Select and copy the path, then enter CTRL + 0 (that’s not a zero), and paste it into the filename, hit enter, and now you’ll see the xml for the code snippet.

This post on the VSEditor blog provides some details on the schema used to create a code snippet file.

I hope you are enjoying this series of visual studio keyboard tips. If you have any editor/keyboard topics that you would like to see, please feel free to comment on this blog and I’ll try and create a new post covering it. Thanks for reading!

visual studio
keyboard
c#

Comments (0)

Permalink

Ruby On Rails - Part Two - Setup & Configuration

I started reading the Pragmatic Programmers - Agile Web Development with Rails. I haven’t read very far into the book yet, but so far it’s as good as I hoped it would be.

I’ve also moved my blog to a new host. They have support for Ruby On Rails built right into the hosting package!

I downloaded and installed RadRails which is a very cool Ruby On Rails IDE built on the Eclipse framework. I’m actually pretty comfortable at either the command line or in an IDE. So you’ll probably see me switching back and forth throughout this blog post series.

I ran the following command on my web host:

rails railsblogjourney

which instructed rails to create a basic application for me. Pretty cool.

After that I wanted to continue validating my workflow and ensure that Rails was functioning correctly on my web host, so I generated a new controller:

ruby script/generate controller HelloWorld

and then added an index method

def index
render :text => "Hello World."
end

If you browse to http://www.robherbst.com/railsblogjourney/HelloWorld
you too can experience the awe inspiring demo. Uh…. right.

Basically today’s goal was to setup a functioning environment for the demo application and to make sure we are able to execute, some extremely basic code.

So far so good.

ruby
rails

Comments (0)

Permalink

Rewriting

I think this post on the 37signals blog really makes a good comparison between the importance of rewriting text and software until you get it right.

What’s really important is to start getting the ideas out of your head, and then working on them relentlessly until you can’t remove anything else, each idea is expressed as concisely as possible.

It made me think about Martin Fowler’s great book Refactoring: Improving the Design of Existing Code. This book gives you a clear guide on how to identify “code smells” and how to use refactoring to fix them. If you haven’t already read it, I would highly recommend it.

programming

Comments (0)

Permalink