May 9, 2008

The Tao of Programming

An excerpt:

        There once was a man who went to a computer trade show.  Each day as
he entered, the man told the guard at the door:

“I am a great thief, renowned for my feats of shoplifting.  Be
forewarned, for this trade show shall not escape unplundered.”

This speech disturbed the guard greatly, because there were millions
of dollars of computer equipment inside, so he watched the man
carefully.  But the man merely wandered from booth to booth, humming
quietly to himself.

When the man left, the guard took him aside and searched his clothes,
but nothing was to be found.

On the next day of the trade show, the man returned and chided the
guard saying: “I escaped with a vast booty yesterday, but today will
be even better.” So the guard watched him ever more closely, but to
no avail.

On the final day of the trade show, the guard could restrain his
curiosity no longer.  “Sir Thief,” he said, “I am so perplexed, I
cannot live in peace.  Please enlighten me.  What is it that you are
stealing?”

        The man smiled.  “I am stealing ideas,” he said.

And another:

    A master was explaining the nature of Tao to one of his novices,
“The Tao is embodied in all software — regardless of how
        insignificant,” said the master.

“Is the Tao in a hand-held calculator?” asked the novice.

“It is,” came the reply.

“Is the Tao in a video game?” continued the novice.

“It is even in a video game,” said the master.

“And is the Tao in the DOS for a personal computer?”

The master coughed and shifted his position slightly.  “The lesson is
        over for today,” he said.

April 15, 2008

Selenium RC Cookbook, Part 1

(This cookbook assumes you know the basics about how to get started with Selenium RC. These examples are also in Java, but should be pretty much consistent for any language)

Finding text in a certain place on the page:

Use XPath, treating the HTML of your page as well-formed XML.

browser.getText("//div[@id='content']/table/*/tr[2]/td[1]")

(In English: at any level of depth, find the div where the id=”content”. Then find the table element under that, and then give us the text of the first cell of the second row.)

Finding text anywhere on the page

browser.isTextPresent("Your Text Here");

Get the text of a URL link

Assuming you have text like: <a href=”…” > your link text here </a>, you could consider:

browser.getText("//a[@href='...']");

Note the consistency with the other example above - anytime you have an opening and closing <element> </element> tag, you can use getText() and XPath to find it.

Get the href of a URL link

Again, assuming you have text like: <a href=”my_link_here” > your link text here </a>, you could consider:

browser.getAttribute("//a[1]/@href");

which would return: my_link_here

Note the slight differences with getText() above, but the idea is generally the same.

How do I find what’s in my Select menu?

String[] options = browser.getSelectOptions("//form//select");

This would return an array of the option text from the only <select> element inside the only <form> element.

If you had more than one form, or more than one select:

String[] options = browser.getSelectOptions("//form[1]//select[1]");

This would return the options listed in the first select of the first form on the page.

April 10, 2008

BFD!

If Test-First Development (TFD) is a specialized subset of Test-Driven Development (TDD), then surely the equivalent specialized subset of Behavior-Driven Development is Behavior-First Development.

Today I had my first experience in developing BFD.

I know what you’re thinking:  BFD.

But it’s a BFD to me.  Using a rather exotic concoction of DBUnit, HSQLDB, Selenium, Cargo and EasyB, I was able to write a story  to describe some new functionality for a web application, and run that story as a test (via EasyB/Groovy), before I wrote any of the code to implement the functionality.

Other ingredients in this concoction:  Tomcat, Ant, Junit, Struts2, Spring, Cobertura and four or five different logging frameworks.

Observations:

  •  It is difficult to see what is going on when your story fails - the story failure is often fairly far away from the  code failure.
  • DBUnit throws multiple exceptions as part of normal operating procedure.  That is a crime against humanity.

Latest Cool Tool

I’m sure everyone else in the world found and mastered  XPath Checker long ago, but for those of you who haven’t, it is a fantastic Add-on for Firefox that lets you practice XPath expressions on real, live web pages.

Why would you want to do that? 

If you want to write Functional webapp tests via Selenium, a good, solid working knowledge of XPath is essentially mandatory for all but the most trivial of tests.

What about Selenium IDE? 

The Selenium IDE is incredibly helpful for navigating your pages, but it is not help at all with testing the content on those pages.

In other words, if you want to register a new user, add four things to your cart, visit your recommendations page and then check out, Selenium IDE will properly structure your clicks and everything else.

But if you want to find out if your checkout page lists your four items, and you need to be specific about where on the page  those items show up, you have to use XPath with Selenium to get to the correct table, div, what-have-you.

Enter XPath Checker.  During your Selenium IDE-driven  recording session, control-click on the page, and experiment with the correct XPath query to get to the cell/row/etc you want to see.

April 4, 2008

Recent Impressions

Hudson

Good Continuous Integration tool. Nice charts, easy to use, fairly flexible out of the box.   A _lot_ less setup work than CruiseControl.  And the plugin system is well done, and pretty nifty.

Struts2

An incoherent mess.  Documentation is spotty, uses a lot of contrived toy examples that blow up on anything more complex than hello world.  Documentation is also simply wrong in some cases (for example, the ‘var’ attribute on the iterator tag is not valid according to the TLD).  Namespaces are nice in theory, but frustrating in practice.   I can’t get the wildcard action management to work reliably, although this may just be pilot error.

Good things: 

The integration with Spring is nice, and I haven’t seen a web framework yet that is more friendly to unit testing.  When it works properly, the wildcarding is very nice.   The Action.execute() model is useful, and easy in concept.

March 24, 2008

Best Practices

An oldy, but a goody, one that I haven’t seen before.

One comment I saw recently was “it means ‘practices of the best’” - as in “the things that the best software developers/consultants do”.

I don’t find that argument particularly persuasive.  For several reasons:

  1. No one knows who the very “best” software developer is.
  2. No one even knows who the very best software developer is, in a particular practice area.
  3. Even if we could magically discern who the best software developer was, it is very likely that:
  • Her approach would be highly tuned to the specific company/organization she was with
  • She would have a hard time elaborating and generalizing her approach without diluting its effectiveness
  • Others would point at this poor developer and say “She is only an expert on Y in situation X, but we are in situation Z”

So while I think it is an interesting concept (practices of the best), I can’t acept that interpretation as being any more valid than “the best way to solve this problem”.

March 17, 2008

More on CruiseControl Dashboard

It took me about an hour and a half to get the dashboard configured properly.  Here’s what I had to do:

  1. I had to copy all of the cruisecontrol jars and all tornei poker on lineworld pokerpoker italiagame on line pokerdownload live pokerstrip poker livesrtip poker gratisgiochi cartepoker scaricabili gratistexas holdem calculator,texas holdem,poker texas holdemtexas holdem italiastreap pokerpoker in tourseven card stud onlinegiochi on line pokergiocare texas holdem online,poker texas holdem online,texas holdem onlineparty poker bonus,poker con bonus,poker bonusstreet poker onlinesexi poker onlinesexy poker onlinehow to play pokergioco carte pokerpoker carte gratistornei di poker gratisonline poker gameparty poker bonuscraps in lineavirtual gamblingscaricare casino gratisonline casino gamesbonus dei casinogioco keno gratiscasino on line roulette,roulette on line,giochi on line roulettegiochi keno inlineagiochi casino pcsistemi roulettecasino tropezgioco craps in lineawww giochi casinoblog casino onlinekeno inlineacasino poker gratisbest casino onlineautomatic video pokercasino tropez bonus codegiochi video pokerroulette strategyrisposte eurobarre casino on netvincere casino onlinelista casino online of the xml-related jars (saxon, jdom, xerces, xml*) into the WEB-INF/lib directory of the dashboard war
  2. I had to update WEB-INF/web.xml and add a context-param to specify the location of the config-xml file.

Note: You might think that you can give it the correct filename at the web interface, but that never worked for me, no matter how I tried to tweak it.

At the end of the day, cruisecontrol requires a great deal of by-hand tweaking to get it to work for your project.  That’s not necessarily the end of the world, but it is a little disconcerting, since the documentation isn’t really clear about how you do this setup, where and so forth.

CruiseControl….

Well, I’m having a bit of an adventure with CruiseControl.  Some tips, perhaps just for myself:

  1. You have to check your project out of source control into the appropriate checkout directory under the cruisecontrol/ build directory before CruiseControl proper will consider building it.
  2. You have to merge unit test results in by hand
  3. You have to set up your dashboard by hand, and (at least as of today) you have to find the missing classes that it needs and include them

More later…

Groovy: no such property: X for class Y

Having taken up the task of learning Groovy, I stumbled early, as I tried to figure out how to integrate groovy-based unit tests with my java code. I had a java class called ContactScreen, and I wrote a groovy test case:

class ContactScreenTest extends GroovyTestCase {
    void testStandardEmailScreen() {
       screen = ContactHelper.getStandardContactScreen( Contact.EMAIL )
       assertTrue( screen instanceof AnyDayEmailScreen )
    }
}

Which failed when I tried to run it via Eclipse, giving the following error:

testStandardEmailScreen(ContactScreenTest)groovy.lang.MissingPropertyException: No such property: screen for class: ContactScreenTest

I stared at that error for a long time, wondering what the heck it meant. I mean, I’ve seen all sorts of example groovy scripts that don’t require definitions. In fact, the code I was modeling mine after used this very format. What is going on?

Finally, I turned to the groovy user group to help debug my groovy test case. Here’s what I found:

  1. The code I was looking at, circa 2004, is now victim to a fairly significant shift in language specification. In other words, it won’t compile anymore.
  2. The rules for declaring variables is different for scripts versus classes. In other words, if you are just running a script, you don’t need to declare variables. If you are building a class, you have to declare the members of the class via def.

So the working code looks like this:

class ContactScreenTest extends GroovyTestCase {
 void testStandardEmailScreen() {
 	def screen = ContactHelper.getStandardContactScreen( Contact.EMAIL )
 	assertTrue( screen instanceof AnyDayEmailScreen )
 }
}
February 11, 2008

This image is sadly in-tune with my experiences and personal opinion of Oracle, and the complexity of their tools.

November 29, 2007

The Fourteen Types of Programmers - Type 6: The ones who comment on articles like this one

(You can find the full list here)

Some people feel compelled to comment.  Some feel that they have humorous observations to add.  Others simply enjoy the self-referential nature of blog posts about commenting on blog posts.   Others enjoy the meta-story of how they comment on blog posts about commenting on blog posts. Sometimes, when the comments take a life of their own, the original blog post becomes irrelevant - it is only a host body to allow the comments to flourish.

Those that do not comment, and those that do, will have one thing in common.   What do you think that might be?

November 6, 2007

ProgrammableWeb

If you like APIs and mashups, you should check out ProgrammableWeb - it’s a directory/advice/analysis site for all things API-ish.

Most recently, they’ve been working on building a subsection for government APIs, which is something that I’m very keen on. They’ve done a terrific job of organizing and structuring the information there. Outstanding work!

October 22, 2007

Some very good advice for programmers

Reg Braithwaite has a very strong case for being more open-minded in your programming research/learning.

Having said that, this is probably the difference between the Myers-Briggs INTP and INTJ subtypes.  INTJs (which is very common amongst programmers) are prone to judging and rejecting information that they disagree with.   INTPs less so.

Having said that, I’ve certainly made this mistake on more than one occasion (and quite possibly blogged about it as well).   But now that I’m thinking about it, I suspect I’ll make it less often.

October 21, 2007

Bookr - a web app for young readers

It all started when I realized that my younger son was struggling with reading.

Not with the letters, or the words, really, but with his own expectations. He didn’t like making mistakes, and didn’t like that his older brother didn’t make many mistakes.

So he refused to read, because he wasn’t good at it.  Catch 22

Pondering this for a while, I thought - maybe if he had something to read that was really interesting, it would motivate him.

And so I wrote Bookr - http://www.undefined.com/bookr - a Flex app that lets the reader choose which characters will be in the book, and makes it more “just for them”, which I hope gives them a reason to want to read it.

I started with Star Wars characters, and have since added characters from the Nightmare Before Christmas and Disney princesses.

So far, I’ve discovered two things:
1. It does seem to work - my son loves the stories, and was very interested in making up fun combinations.
2. Because you can play the same book with different characters, there’s a fair amount of reinforcement.

If you have younger children who are thinking about reading, feel free to give it a try. You can even write your own Bookr books, and I’ll include them in the library.

Tutorial here: http://www.undefined.com/ia/bookr/

Comments and feedback are welcome.

August 10, 2007

News

Now that everyone at work knows, I can tell my loyal readers (all 2 of you) that I have taken a new job, as the CTO of the Sunlight Foundation. It’s a non-profit, based in DC, that focuses on using technology and the Internet to spotlight waste, fraud, corruption and “questionable” behavior in Congress.

I start in September. Half of my family is nervously excited about the move, the other half is nervously anxious.

June 5, 2007

Interesting technique for modifying internal Flex code

You can do this in Ruby, and there is some argument whether it is a good thing to be able to do (in terms of readability, comprehensibility).  You can override an existing method w/your own   (I forget what the term is, right now, mainly because I never use it).  Ruby on Rails takes full advantage of this.

Apparently, you can do the same thing in Flex, for the internal functions/capabilities of the MX Controls.

Void where prohibited, your mileage may vary, etc.

February 28, 2007

Follow Up on WinHugs

In case anyone else is wondering, I did find the problem with opening my saved Haskell file in WinHugs.

At the same time, apparently there are different dialects of Haskell, and it is difficult for a casual observer to tell.

Specifically:

  • If I go to  Haskell.org, click on Hugs, then Download, and the WinHugs, download it and install it.
  • And I then go back to Haskell.org, and click on Haskell in 5 easy steps, I would expect that the provided examples would work.  In fact, if I look at Haskell in 5 easy steps, it gives absolutely no indication that the examples they are using will not work with Hugs.  They even provide suggestions on how to download and install Hugs as part of that tutorial.

This is not a slam on Haskell, Hugs, or any person out there who writes, enjoys or uses Haskell!  I am not criticizing anyones abilities, intelligence or judgment.   I am simply pointing out that for a casual amateur, this is not the most friendly of introductions, and I’m sure that a lot of people give up at this point, rarely to return.

As for me, thanks to Don and Neil’s help, I can actually try experimenting with Haskell now and see what I can learn.

Thanks, guys!

February 26, 2007

Woke up this morning, had a blue moon in my eyes

I thought I would spend some time this morning trying to learn Haskell.  I happen to have downloaded a copy of WinHugs, and it seems to be functioning properly.

Alas, every function definition example I try to use blows up on me.

From: Beginning Haskell 

Hugs> myNum :: Int
ERROR - Undefined variable “myNum”
Hugs> square :: Int -> Int
ERROR - Undefined variable “square”
Hugs> square n = n*n
ERROR - Syntax error in input (unexpected `=’)

Hmm, maybe the syntax is different?  Looking at the WinHugs documentation, it says it is Haskell 98 compliant, except in some strange ways.  Well, there’s always “Haskell in 5 steps

Hugs> let fac n = if n == 0 then 1 else n * fac (n-1)
ERROR - Syntax error in expression (unexpected end of input)
Hugs> fac n = if n == 0 then 1 else n * fac (n-1)
ERROR - Syntax error in input (unexpected `=’)

Hmmm.  Looking further at the Haskell in 5 steps, it seems like maybe I have to write the factorial program seperately, and load it into WinHugs?  So I create fac.hs, and put it in:

C:\dev\haskell

C:

My Documents

C:\Program Files\WinHugs\

Can it find it in any of those locations?  No.   Even when I use the “Open” command from within WinHugs, it still can find fac.hs, even though I can clearly see it in my file explorer.
So I think that’s enough for one day.

February 12, 2007

Why settle for great when you can be the world’s greatest?

Steve Yegge escalates the pompous programming punditry, telling us all exactly what you need to know to be one of the world’s best programmers.  And I bet you can guess how well those skills intersect with the Venn diagram of Steve’s own skills.
Now, applying the lessons of this article to punditry, I need to mention three things that Steve can do better than I can before I criticize him:

  • Steve clearly knows more about programming language internals and concepts than I do, even more than I knew when I wrote a few interpreters back in the day.
  • Steve has some great advice on recruiting and phone screening.
  • Steve works for Google, and I don’t

There’s no doubt that Steve knows his stuff.  And I would feel, if I were to ask him about a programming question, that if he answered swiftly and decisively, he would probably be right.

Now, having said all that, I think he’s developing into a Clooney-esque perfect storm of self-satisfaction.   There’s no way he can make this claim legitimately.

a) He’s not omniscient.  He can only apply his assertion to the domains that he has actually worked with in depth.
b) The definition of “best” is quite amorphous.  The best GUI programmers, the best O/S programmers, the best real-time systems programmers, the best customer-domain experts probably do not find that lexical programming is the lump of coal that gets them over the hump into the “world’s greatest” class.
c) These claims of absoluteness are risible when they are made by politicians about law and government.  They are typically risible when made by scientists, beyond some super-well-proven facts.   And about software… a field that is so young and raw that we still debate whether strong or weak typing is better?  Hah!
Don’t get me wrong.  Learning and knowing about programming language internals is valuable.  It was extremely enlightening in a number of ways.  But it is not, by any means the height of perfection that Steve would claim it to be, and it would be a disservice to the young people of the world if someone did not point out that Steve is conflating his opinion with absolute fact in an embarrassingly simplistic way that is unbecoming of his experience and intelligence.

February 7, 2007

Hrmmm

  • What is a useful application of the Y Combinator? I found a JavaScript example, which I understand syntactically, but I don’t see the point. Is it just the “flavor of the month” in geek one-uppedness?
  • Finding an implementation of Haskell that runs on MacOS would appear to be an exercise in pain and IRC. Both of which I try to avoid.
  • I love the way that everyone and their brother is telling us what the “characteristics of a great programmer” are. Two observations:
    1. The lists are always different in significant ways
    2. The writer always seems to feel that they themselves have most, if not all, of the characteristics of a great programmer.

So really these posts should all be read as “Here’s why I’m a great programmer.
Update: Reg Braithwaite says “Learn the Y Combinator because it makes you a better programmer.” He then proceeds to write a blog post showing how he does exactly that. Which, while I respect Reg a lot, is yet another example of “Here’s why I’m a great programmer.” Reg’s approach, of course, is completely different from all the other posts on the same subject.

For the sake of argument, assume that every single of them is telling the truth, and that they are all, in fact, great programmers. What can you infer from that?

Update 2: In the comments, Reg insists he is not, in fact, a great programmer.  I’m not sure I can agree with him on that :)   He also insists that his approach will make one a better programmer, not a great programmer.