Google gets it right a lot of the time, including bringing back what Im looking for as the first result. I might be one of the few people who actually use the Im Feeling Lucky button on the Google Search page, but I do it in a sneaky way.  I do it from my omnibox in Google Chrome.

If youre not using the omnibox to search in Chrome, youre not one of the cool kids in my book.  Just type what you want and hit enter to search your default search engine.

What you might not know is you can search other sites as well. Type the domain, press tab and if youve already searched that domain, chances are Chrome will help you out.

image

Type your search results and press enter and abracadabra, youre searching Wikipedia. This is very useful as I usually want to search a specific site for my information.

What I also like to do is skip my search results page and follow the Im Feeling Lucky first result. A lot of times Ive already searched for it, or am pretty sure the first hit will get me what I want. To do that setup a new search engine with whatever keyword you want. I picked L, but it could easily be lucky or whatever.

image

Here is the full text of the URL.

http://www.google.com/search?hl=en&q=%s&btnI=I%27m+Feeling+Lucky&aq=f&oq=

 

Now just press L, plus maybe a space, then tab.

image

True, the page youre going to end up on is the link below , but it takes less time to just type it and press enter than to see if that is what you want, press down and then enter. Also that link isnt always the same location.

Anyway, I hope youre feeling lucky punkAre yafeeling lucky. (you know that was coming)

I'm really excited about using Cucumber. There has been a desire to get to that level of BDD-ish style tests ever since I first saw how readable they were. We're ready to make that next step. Let's pretend we have the following set of pages.

Pretty straight forward. We should be able to write a pretty simple Cucumber feature.

Feature: Add Foos
  In order to keep track of foos
  As a person who enters foos
  I want to be able to add a foo

  Scenario: Adding a foo without searching
    Given I view the welcome page
    When I click the Add New Foo button
    Then I'm taken to the Add Foo page

  Scenario: Adding a Foo
    Given I've searched for a foo that doesn't exist
    When I click the "save" ...that should say "Add"
    Then I'm taken to the Add Foo page

Simple enough. I'm not going to walk you through how to write the steps for that. I'm more interested in how you organize the pages into page modules inside a static language. In Ruby you could do something like

class WelcomePage
  def intialize(browser)
    @browser = browser
    self.goto
  end

def goto end

def addFoo @browser.click '#add' AddFooPage.new(@browser) end

def searchForFoo(query) @browser.type(query).into('#t') # made up syntax @browser.click '#b' SearchResultsPage.new(@browser) end

end

class SearchResultsPaage def initialize(browser) @browser = browser end def addFoo @browser.click '#add' end end

That isn't WatiR. It's totally made up. I'm a Ruby Newby too so told shoot me for any syntax errors.

You can drive it with something like this.

Given /I view the welcome page/ do
  @page = WelcomePage.new(browser)
end

Given /I search for (.*)/ do |q|
  @page = page.searchFor(q)
end

Given /I click on the add button/ do
  @page = page.addFoo()
end

Pretty straight forward huh? Well how I do that in C#? All of those Navigate methods will either return a specific page type or a base type that will make it impossible to call the subsequent specific steps.

public class WelcomePage{
  public SearchResultsPage SearchFor(query){
    _browser.Type(query).into('#q');
    _browser.Click('#btn');
    return new SearchResultsPage(_browser);
  }
}

public class SearchResultsPage{
  public AddFooPage AddFoo(){
    return new AddFooPage(_browser);
  }
}

Then drive it with this.

var welcome = new WelcomePage(_browser);
var results = welcome.SearchFor('bar');
var add = results.AddFoo();

Doesn't that feel messy? Luckily, I think a feature of .Net 4.0 might save the day!

dynamic page = new WelcomePage(_browser);
page = page.SearchFor('bar');
page = page.AddFoo();

Three cheers for dynamic!

I really like learning new languages. It's a challenge and the change in perspective is refreshing. We spend all day trying to solve a problem with the tools our employers pay us to use. Sometimes we have tunnel vision on the means to solve the problem. Some of the things we pick up along the way are language features that give us a new understanding of what is possible.

    5.upto(10) { |i| print i, " " }

Some language features, such as Ruby's method_missing features that aren't possible in my benefactors language of choice. It's not only new language features, but new ways to solve problems. For example, the way Ruby on Rails versions the database and provides the ability to version up and version down the database is impressive.

My newest journey is Google App Engine and Python. GAE supports both Java and Python, but being familiar with Java and it being so similar to C#, Python sounds more fun. Python is a dynamic language, like Ruby, and offers value as a scripting language outside GAE.

So far both Python and GAE have proven very approachable. The app engine is very well documented and the examples are clear and useful. Python is sexy. It's all that you really need to say. I am not that familiar with it yet, but its string manipulation is very powerful. Take this example.

"something cool"[-4:]

In C# it would look like this.

var s = "something cool";
var c = s.SubString(s.Length - 4)

There's no denying Python is sexy. You could argue that it is cryptic, but even in this simple example, I believe it's more readable than the C#.

I have an idea for a pet project in GAE. Hopefully in the next few weeks I'll have some updates. I'm excited to see how things go.It will not only be an exercise in Python, but also HTML, CSS, usability, UI design. On a day to day basis I rely heavily on our talented designers to make my markup looking great. This is an area of my expertise that needs to improve.

Anyone whom has read any of my recent code knows I love lexical syntax. I really love it when anyone, even our HTML designers, can read our code and understand exactly what is going on. Im not the only one either.

@MarkBorcherding amen, fellow believer in functionNamesShouldSayWhatTheyDo(AndParameterNamesShouldReflectWhyTheyAreNeededByTheFunction)!

@noelweichbrodt

A great example is the terrible Selenium API. It is confusing to even me, at firstonly for a second. Take a look at the following example.

_selenium.Open("some.url");
_selenium.Type("css=id$=_username","homer");
_selenium.Type("css=id$=_password","beer.is.yummy");
_selenium.Click("css=id$=_submit","LoginButton");
_selenium.WaitForPageToLoad("30000")
Assert.Equal("Homer Simpson",_selenium.GetText("css=id$=_userFullName"));

 

Now that's not terrible. I would even lean to say anyone would know what that does, but what is the css=id$=_username? That looks goofy.  Why do we do that? Take a look at our extensions on top of the Selenium API.

_theBrowser.Types("Homer").IntoAspNetControl("username");
_theBrowser.Types("beer.is.yummy").IntoAspNetControl("password");
_theBrowser.ClicksOnAspNetControl("LoginButton");
_theBrowser.WaitsForThePageToLoad();
"userFullName".AspNetControl().TextIn(_theBrowser).ShouldBe("Homer Simpson");

 

It wouldn't be hard to argue the second example is not much more clear. You dont have to remember that CSS selector or why we did the $=_ instead of just =. Overall, Im pretty happy with our API. There is a valid argument that this syntax will take time to learn since any developer reading it will have zero experience with it or know what calls are available, but over time, I think the benefit of its readability out weight its learning curve.

So here is where I am today. I dont like the following code.

<input
    type="text"
    id="<%=Html.IdFor(x=>x.CustomDomainName) %>"
    style='<%= !Model.HasCustomDomainName ? string.Empty : "display:none" %>'
    />

 

Its a pretty typical ternary operator. In this case though, I have to explain to our designers what that actually means and how to read it. Im really tempted to create the extension methods I need to have this syntax.

<input
    type="text"
    id="<%=Html.IdFor(x=>x.CustomDomainName) %>"
    style='<%= Model.HasCustomDomainName.IsFalse().Then(()=>"display:none") %>'
    />

 

Again, much more clear, but it feels like Im starting to abuse the extension methods and making a mess of the languagebut it reads so much nicer.

Lets say you were designing a tool to generate code from a diagram. If you were try to generate code for a situation where you expect there to be a primary key on a table, and there isnt, would you:

a) assume you dont need the PK and work around it.

b) throw an error dialog to the screen with a nice error message

c) just skip generating the functionality they were expecting and go on like they really never needed it

If you were the LINQ to SQL team, you would have picked c. I realize tables need PKs and that trying to find an row when there is no PK might be a tad difficult, but at the same time a little help would be nice. A simple dialog No PK found on table Moron would have been all I needed.