Archive for the ‘Introspection’ Category

Introspection – May 2009

Wednesday, May 20th, 2009

Checking in

As predicted in February’s introspection, change is here and it is happening. I am embracing it as best as I can. It’s kept me busy and I haven’t posted an introspection since March. It’s more to than time to check in on my goals for the year.

Progress

  • Spend more family time – With the exception of the last week or so, I’ve been making time to spent outside with my kids. My wife and I have had more together time as well. It’s been rewarding and I’m glad I’ve been doing this.
  • Quit smokingStill smoke free As of last week I fell off the wagon. It was a good run, but the pressure got me.
  • Continue learning in Ruby and .NET – On the .NET side, I’m working on putting a second Monorail app into production, this time using Brail rather than NVelocity. As for Ruby, I’ve been actively using it and finding more and more projects to work on. Unfortunately, many of the personal projects get started and left for the next project that strikes my fancy. Still the continued use has improved my knowledge of the language and programming overall.
  • Learn Ioke – I have finally started this and once I got over my fear, I played with ISpec here and here
  • Exercise frequently – The last few weeks have killed this, but before that I was walking daily and it was great.
  • Stop trying to organize, and start simplifying – Falling apart here. I guess something’s got to give. I’ll get to this on the weekend, maybe.
  • Become financially stable – Not as far as I want to, but far better than previous years.
  • Teach – Not much progress here. Bought an interesting book called Hello World. Started KungFuTees with my kids. I’m interested in Railsbridge, maybe I’ll find some good resources here.
  • Enjoy the journey- Up and down here, some times are better than others. Working to maintain a positive perspective.
  • Blog!- Added this. I’ve been trying to post a minimum of 3 times a week. Happy about this.

Introspection – March 2009

Tuesday, March 3rd, 2009

Following up last month’s big victory over smoking, this month’s strategy was more fortify and persist than big victory. Without further ado, here is my current progress.

  • Spend more family time - Improved, but not where I want it to be.
  • Quit smoking - Still smoke free, with with only a few temptations. /li>
  • Continue learning in Ruby and .NET – I didn’t do much with Ruby in this past month, however on the .NET side of things I put a Monorail site into production. This was exciting and I used a number of great tools along the way including ReSharper (I finally caved), Windsor and RhinoMocks.
  • Learn Ioke – I’m losing ground on this one, need to make a push forward on this soon to meet this goal.
  • Exercise frequently – I’m out walking more sometimes taking a few short trips a day to stores, etc.
  • Stop trying to organize, and start simplifying – Picking back up on this finally, I’ve collected the best desktop bits of the two computers I had lying around and combined them into 1 fast, dinosaur of a Linux box for the kids.
  • Become financially stable – I paid off a largish debt and continued to grow my emergency fund. So I’m doing pretty well here so far this year.
  • Teach – No progress here.
  • Enjoy the journey- My biggest failure this month. I’m really not loving the journey. Not sure what has got me feeling this way, but I’m hoping that I’ll be shaking this off as Spring comes around.

Introspection – February 2009

Thursday, February 12th, 2009

2009 is shaping up to be a year as full of change as 2008 was, if not more so.  The primary difference is that this year I’m ready for it, or at least ready-er(?).  It’s mostly a state of mind that I’m working to maintain.  This year my mantra is:

Change is good, it brings opportunity.  Be ready for anything.

Being ready for anything is not as easy as it sounds when you have spent a good part of your last ten years trying to settle into a comfortable routine.  This plan has, by the way, failed me in each of the last ten years.  It simply isn’t maintainable.  Life has had a way of shaking me up when I get too settled in.  Either that or I have an evil twin that is working diligently to make sure that I am constantly struggling.  Personally, I prefer to believe the first option since it makes me feel a bit less like a paranoid psychotic.

In the midst of my readiness, I have set a number of goals for myself to achieve in 2009.  These are generally in the category or personal improvement and more specifically intended to keep me from becoming a big, fat, coughing wannabe programmer sitting around all day wondering why life is passing him by.

So without further introduction, here are my goals for 2009 and how I am doing with achieving them.

  • Spend more family time - I’m continuing to fail here.  Need to improve quickly.
  • Quit smoking - Funny that this goal was the one I thought that I would ignore throughout the year, but I’ve done it.  It’s been over a month since I quit smoking cold turkey.
  • Continue learning in Ruby and .NET – While I went through a stretch of good growth here, the last week or two have brought a loss of momentum and motivation, hopefully this is a temporary bit of downtime.
  • Learn Erlang Learn Ioke – While I would still like to learn Erlang, I’ve officially jumped ship to Ioke on this one.   I have the ‘S’ release installed on my new laptop and I just need to start using it.
  • Exercise frequently – Quitting smoking has had me putting on the pounds, primarily because of energy drinks.  I’ve now switched to coffee and tea and, now that the weather is warming up a bit, I am walking on most days.
  • Stop trying to organize, and start simplifying – Completely derailed on this after a minor victory involving a trip to storage and the goodwill donation station.
  • Become financially stable – I’ve started an emergency fund, which is really not all that exciting.  Except for me, since I’ve never had one and in this case, my opinion is the one that counts.
  • Contribute – No progress as of yet.
  • Teach – No progress here either.
  • Enjoy the journey- A mindset that I need to continue to nurture, because I haven’t really done this, at all.

Next month I’ll check back in an see how I’m doing with these goals.  Good luck with all of yours.

Chores: A test driven website, part 2

Friday, January 9th, 2009

This is part of the Chores series of posts

In which I continue to build the chores website and demonstating how simple it is to use a test first methodology. To follow along, please see my previous post.

Doh! I forgot to commit!

When I left off, I had come to a natural stopping point. A place where I was shifting focus from features to unit testing. I like to make my commits when my tests are all passing, however if I’m implementing a new feature, I don’t apply this hueristic since completing a feature will span multiple units of work. So let’s commit this. First let’s see where I am:

$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       features/
#       lib/
#       script/cucumber
nothing added to commit but untracked files present (use "git add" to track)

Ok, git sees that I’ve added cucumber to my rails app and that I have added a feature. Let’s add these changes to our commit.

$ git add .

and commit them

$ git commit -m "added feature to create chores"

and finally push a copy out to the repository I set up on my shared host.

$ git push origin master

there all set.

Routing to home

At this point I’m a little confused as to how to proceed test first. We have a failing feature. When I have a failing feature I like to start by making a test to simulate the same error. However in this case, that is difficult at best, and the failing feature has already told me what I need to do, which is create a home_controller

$ ruby script/generate controller Home
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/home
      exists  test/functional/
      create  app/controllers/home_controller.rb
      create  test/functional/home_controller_test.rb
      create  app/helpers/home_helper.rb

.. and map a route to it. To do that I open up my ./config/routes.rb file and add the following route. I like to get rid of the legacy routes so I’ll replace the entire text of the file with the following

[sourcecode language="ruby"]
ActionController::Routing::Routes.draw do |map|
map.root :controller => ‘home’
end

So what are these controllers and routes?

If you are new to Rails, you are probably wondering what we just did. The controller is the C in the MVC pattern that Rails uses. It's role is to handle web serving of the application. It's kind of like an office assistant for your application. It be able to handle frequent requests and delegate them to the proper subject matter expert. When a request comes in for a list of Widgets, it will go to the Widget model and ask it for a list of widgets and then pass that off to the user interface (view) to display in the browser. When the user interface passes it a bag of information and asks it to save the information, the controller will create an instance of the appropriate model from the bag of information and then tell the model it should save the information.

Controllers really shouldn't become too involved in the details, but should delegate well to the objects that know what they are doing. Rails have a nice script to generate controllers, which we used above. In this case we generated a home controller which we will use to handle requests for the application's home page or root.

The second thing we did is define a route. Routes are related to controllers, in that they show the framework how to translate a request such as http://www.exmaple.com/sprocket/new into a method call on a controller. In the case of the above url, it would call the method new on the sprocket controller. You can find your routes in config/routes.rb and view all of your current routes with the rake task

rake routes

On with the show!

Now let's go back to cucumber and see where we are.

$ cucumber features
Story:  Define chores  # features/define_chores.feature
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore       # features/define_chores.feature:6
    Given I am on the homepage    # features/step_definitions/chores_steps.rb:1
      No action responded to index. Actions:  (ActionController::UnknownAction)

Ok, our route is now wired up nicely to the controller, but the home controller does not respond to index. Lets add this to the controller

[sourcecode language="ruby"]
class HomeController < ApplicationController
def index

end
end

and try cucumber again

$ cucumber features
Story:  Define chores  # features/define_chores.feature
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore     # features/define_chores.feature:6
    Given I am on the homepage   # features/step_definitions/chores_steps.rb:1
      Missing template home/index.erb in view path c:/rails/chores/app/views: (ActionView::MissingTemplate)

Ah ha! We are making progress. Our request has passed through the controller and is now looking for a view to render. One thing that I would like to point out is that doing the development in this way really lays out how the pieces of Rails all fit together. Something that we wouldn't have seen if we had chosen to generate a scaffold or we built it piecemeal without the tests metering our pace.

Views

Views are what end up being displayed in the web browser, they are a sort of template. By default, erb will process the template in the context of your request and output the dynamic content. Pretty cool stuff, and it gives you great control over your output.

Well what are we waiting for, let's make a view.

$ touch app/views/home/index.html.erb

In windows you can use your IDE or folder browser to create the file.

$ cucumber features
Story:  Define chores  # features/define_chores.feature
Story:  Define chores
As a parent
I want to define chores
So that I can assign them to my children
 
  Scenario: Creating a chore                          # features/define_chores.feature:6
    Given I am on the homepage                        # features/step_definitions/webrat_steps.rb:6
    When I follow "Add Chore"                         # features/step_definitions/webrat_steps.rb:18
      Could not find link with text or title or id "Add Chore" (Webrat::NotFoundError)
      (eval):2:in '/^I follow "([^"]*)"$/'
      features/define_chores.feature:8:in 'When I follow "Add Chore"'
    And I fill in "chore[name]" with "My first chore" # features/step_definitions/webrat_steps.rb:22
    And I press "Add"                                 # features/step_definitions/webrat_steps.rb:14
    Then I should see "Chore added."                  # features/step_definitions/webrat_steps.rb:93
    And I should see "My first chore"                 # features/step_definitions/webrat_steps.rb:93
 
1 scenario
1 failed step
4 skipped steps
1 passed step
rake aborted!

Hey look! Our first step has passed! Let's give ourselves a pat on the back. We have a website with a dynamic (albeit blank) homepage, that is tested.

Not all quotes are equal

I had an issue with my feature where the double quotes in my feature were translated automatically to open and closed style quotes. This was causing my steps not to match. If you find that you have a bunch of steps that are undefined at this point, that may be the issue.

Catch the passing step fever

The next step is one that is generated by webrat. It is looking for a link to follow called "Add Chore". The problem is that we didn't actually add the link, or anything else to the view. So let's update the view to read

[sourcecode language="ruby"]
<%= link_to "Add Chore", chore_path %>

and fire up cucumber

$ cucumber features
Story:  Define chores  # features/define_chores.feature
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore      # features/define_chores.feature:6
    Given I am on the homepage    # features/step_definitions/chores_steps.rb:1
      undefined local variable or method 'chore_path' for #<actionView::Base:0x4baf67c> (ActionView::TemplateError)
      On line #1 of app/views/home/index.html.erb
 
      1: <%= link_to "Add Chore", chore_path %>
 
      app/views/home/index.html.erb:1

ok, we need to define resource for this, let's add a route and controller.

[sourcecode language="ruby"]
ActionController::Routing::Routes.draw do |map|
map.resources :chores
map.root :controller => 'home'
end

and

$ ruby script/generate controller Chores
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/chores
      exists  test/functional/
      create  app/controllers/chores_controller.rb
      create  test/functional/chores_controller_test.rb
      create  app/helpers/chores_helper.rb
$ cucumber features
Story:  Define chores  # features/define_chores.feature
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore    # features/define_chores.feature:6
    Given I am on the homepage   # features/step_definitions/chores_steps.rb:1
      chore_url failed to generate from {:action=>"show", :controller=>"chores"}
 - you may have ambiguous routes, or you may need to supply additional parameter
s for this route.  content_url has the following required parameters: ["chores",
 :id] - are they all satisfied? (ActionView::TemplateError)
      On line #1 of app/views/home/index.html.erb
 
      1: <%= link_to "Add Chore", chore_path %>

Dang it! still getting an error. Hmmm.. wait a minute. chore_path is generating a show action. That's not what we want to do. We want a new action to be RESTful or maybe an index action if we don't see REST in the future for this app. A quick consultation with the domain expert (me) says that there is no valid reason not follow the RESTful guidelines at this point so let's fix the home/index view to read.

[sourcecode language="ruby"]
<%= link_to "Add Chore", new_chore_path %>

cucumber says...

$ cucumber features
Story:  Define chores  # features/define_chores.feature
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore   # features/define_chores.feature:6
    Given I am on the homepage   # features/step_definitions/chores_steps.rb:1
    When I follow "Add Chore"   # features/step_definitions/webrat_steps.rb:8
      No action responded to new. Actions:  (ActionController::UnknownAction)

Great! That fixed it. Now we need to make sure there is a new action on the chores controller.

class ChoresController < ApplicationController
  def new
 
  end
end
$ cucumber features
Story:  Define chores  # features/define_chores.feature
As a parent
I want to define chores
So that I can assign them to my children
  Scenario: Creating a chore    # features/define_chores.feature:6
    Given I am on the homepage    # features/step_definitions/chores_steps.rb:1
    When I follow "Add Chore"      # features/step_definitions/webrat_steps.rb:8
      Missing template chores/new.erb in view path c:/rails/chores/app/views: (ActionView::MissingTemplate)

cucumber likes it! But we still have an error. Let's create ./app/views/chores/new.html.erb as:

<% form_for(@chore) do |f| %>
  <%= f.error_messages %>
 
  <p>
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </p>
 
  <%= f.submit "Add" %>
  </p>
<% end %>

Hmmm.. wait we are getting ahead of ourselves. We need a model to be able to pass it to our view. We will have to generate that next.

Well we didn't get to Test::Unit this time around, but with a model in sight it's sure to be right around the corner. Until next time..

Perspective::2009

Monday, January 5th, 2009

Today was a humbling experience, but it highlighted the reasons for my goals for the year.   I have a project in it’s early phases that I can’t decide on a path forward for.   The problem is Ruby on Rails, it must be.  Shifting gears between Ruby on Rails and ASP.NET WebForms is like night and day.   I have a number of these WebForms projects on a common codebase.  The codebase is my own, I hesitate to call it a framework, but it is in production and working well.  It has tests covering the interesting bits of code and it’s built in a more traditional data-layer, business-object-ish layer and you can set WebForms on top of it all.

Writing it was a good learning experience.  I got to know Generics, Dependency Injection / Inversion of Control, and some interesting aspects of designing re-usable code.  However, there is one major problem with it.  I hate it.  Well that’s not 100% true, I’m proud of having written it and that it works, but I don’t enjoy using it.  There is 0 Rails MVC goodness in it and I feel like I am constantly violating the DRY principle despite my best efforts not to.

Back to my project.  I originally decided to to write it in Castle Monorail.  I was excited but a bit puzzled by the “distributed” documentation and the variety of options available to me, but I took it in stride as Ruby on Rails seems to have a new improved way to do things every week or so.   I settled on using MicroKernel with Brail as my options with trusty NUnit as my testing framework.   Before long I made a complete mess of everything and had to rewind.  Take two turned out a little better, but fizzled out as well. 

After a while, I really didn’t want to work with it anymore since I had begun to equate working in Monorail with being confused and frustrated and doing sub-standard work.   I decided to go back to WebForms since that is a known quantitiy but after doing some fairly interesting work and spending a couple weeks on it, I realized that I had done fairly little on the project itself and a large amount of work trying to bend my codebase to do some Railsish things. 

Then came the Holidays, and my family was kind enough to let me feverishly hack at Ruby among other things.  I learned to use Cucumber and touched on Shoes.  I played with Webrat and Machinist and it was all good.  That was when I decided to give Monorail another try.  Which leads me to today….

I started out by signing up for an account at Codeplex and looking around there to see if there was anything of interest brewing in the .NET community.  I found two interesting projects, Faker and FluentSpec and set in to making an Castle ActiveRecord assembly for my domain.   Before long I was floundering,  without the flow.   I spent hours tinkering and researching until finally I came across the following two posts.

  1. Advanced Mocking Senarios with Active Record and RhinoMocks
  2. TDDing Controllers

That was when it all started coming together and after hours of feeling like an idiot, I ended the day feeling like I had accomplished something.  That is the feeling I want for 2009.  The feeling of stepping out of confusion and self-doubt into the satisfaction of accomplishment.    The exhilaration of seeing it all come together.  

Now that I have completed my rather circuitous route to the goals portion of this post,  let me move on without further ado to listing out my goals for 2009.

  • Spend more family time - My obsession for all things technical often shrinks family time.  I must find a better balance here.
  • Continue learning in Ruby and .NET – I made great strides in both of these areas in the past year.  That is no reason to let dust settle on my skills.
  • Learn Erlang – I chose this functional language to learn in 2009 because of it’s distributed nature and it’s threading ability.
  • Exercise frequently – I’m not looking to go out and run a marathon, but if I can walk or drive somewhere, I need to take the walking option.
  • Stop trying to organize, and start simplifying – I think that the clutter is what is sapping my time and energy, and diverting me from my goals.
  • Become financially stable – I will have an emergency fund and know where all my money goes by the end of the year if not sooner.
  • Contribute – I would like to become involved in open source projects of my own or others.
  • Teach – My kids think that most of what I do on the computer is magic.  I would like to teach them how if they want to learn.  Hackety.org and Shoes is looking like a great place to start.
  • Enjoy the journey- Funny that I read that post after the day of frustration that I had.  Thinking back, the figuring it out is as fun as the accomplishment of having done it, if I allow it to be.
  • Quit smoking – There I said it, though my heart is not fully in it yet.

That is a tall list of goals; can I do it all in 2009?  I am not sure.  If I keep plugging away at it day after day, I might.  Regardless the effort put into it will be rewarding, as I will definately make significant strides toward these goals and (hopefully) learn to enjoy the journey.