Alex Chaffee's blog
JAVA_HOME on Mac OS X
For the millionth time, cause I always forget...
Put this in ~/.bashrc:
export JAVA_HOME=/Library/Java/Home
Also, run "sudo visudo" and add the line
Defaults env_keep += "JAVA_HOME"
or else commands like "sudo gem install" won't be able to find Java.
Without the above, I got the following error (which seemed to have been run through a baby-talk filter) when running "sudo gem install rjb":
extconf.rb:44: JAVA_HOME is not setted. (RuntimeError)
XPath CSS Class Matching
I'm writing Selenium tests again, which means a lot of XPath. Here's a trick I learned thanks to this article on Push Button Paradise.
The problem is, how do you write XPath that matches one class in a multi-class element like
<div class='foo bar'>
? The standard XPath equality operator matches a full string, so
//div[@class='foo']
won't work. The solution is arcane but I promise it works:
//div[contains(concat(' ',normalize-space(@class),' '),' foo ')]
Note that there must be spaces on either side of the class name 'foo'.
Since this is quite a mouthful, I've extracted it into a helper method. Here it is in Java:
/**
* Generates a partial xpath expression that matches an element whose 'class' attribute
* contains the given CSS className. So to match <div class='foo bar'> you would
* say "//div[" + containingClass("foo") + "]".
*
* @param className CSS class name
* @return XPath fragment
*/
protected static String containingClass(String className) {
return "contains(concat(' ',normalize-space(@class),' '),' " + className + " ')";
}
Can less leave the screen alone when it quits?
From the less faq:
blah blah blah ti/te blah blah blah -X blah blah.
Also, -R makes it show ANSI color. So I put this in my .bash_profile:
export LESS=-RX
Java Stink
After about two years in which the only Java I wrote had a "Script" after it, I've recently started working in my old favorite language again. It was clear to me long before I made the leap that somewhere along the line Java took a sharp turn towards Scarytown. (Maybe the writing was on the wall when the "Hello World" program comprised five lines, two declarations, and a static reference, but back in 1995 we were all so excited about getting objects without C++ that our judgement was clouded.)
Anyway, I will always have a place in my heart for the old bird (picture a portly English matron with flower dress and pocketbook and floppy hat), but Stu at Relevance Blog points out why coding in Java now feels like trying to sprint with 30-pound weights strapped to my ankles.
Java is a high-ceremony language. At every turn, Java enforces a high busy-work/real-work ratio. Specifically:
- Java's checked exceptions bloat code, make components harder to use and maintain, and lead to tons of boilerplate code, each line of which is a bug-in-waiting.
- Java's new operator/constructors cannot pick a return type. The amount of code that exists only to work around this is staggering. Two entire cottage industries have sprung up to deal with this single issue: factory patterns and dependency injection.
- Java has no metaprogramming features to automate common tasks such as field accessors, standard constructors, and simple delegation.
- Primitives, functions, and classes are not first-class objects, leading to huge code bloat to deal with these types specially.
- Java's core reflection and interception capabilities are clunky, requiring tons of bolt-on technologies to make them workable, including AOP, annotations, and code generators.
That's a pretty big stink, but if you are used to it you probably can't smell it anymore.
(And that's not even mentioning the prevalent idioms of programming with massive amounts of indirection and wrappers and statics and service locators and and BigLongClassNamesThatIncludeTheirAncestry (I always say, "Do we call it a DogMammalVertebrateAnimal? No, we call it a dog!") and redundant JavaDoc on every method and...)
I ranted and spoke and even blogged about some of these issues before, but now that I'm a visitor in that world I just feel vaguely amused and sad when I see all the hoops Java programmers still have to jump through. Yeah, control-space completion is nice, but gotapi works pretty well, and at the end of the day, no matter how many curly braces my IDE inserts for me, I'd rather have my code look like this:
parse_args(["--topping", "pepperoni"])
than this:
String[] args = {"--topping", "pepperoni"};
parseArgs(new ArrayList<String>(Arrays.asList(args)))
Wouldn't you?
User Research As A Commodity
The intersection of development and UI is an area I've got some interest in. Arena just shared this amazing article about a team's experience merging Agile project management with User Research and testing.
User Research as a Commodity (part 3 of 7) by Tim Kieschnick
Here (below the fold) are some of the things in the article I found eye-opening.
CPU Leak
I just had to quit Firefox for the umpteenth time because it was taking up 25% of my CPU and 1.5 GB of virtual memory. It makes my lap hot and burns down my battery and activates my fan and slows down my click response time. I have no idea if it was Gmail or Google Reader or one of the other JS-heavy apps and frankly, I'm sick of guessing.
Let's face it: the browser is an operating system. It's time it started acting like one.
Here's what I want my next browser to do:
- Put every tab's JS in its own thread or process space
- Pause that process when I switch tabs (i.e. I don't want Gmail to check for incoming mail or chats unless it's in a visible tab)
- Show me a list of the CPU and memory usage of each JS slice like "top" or the Windows process monitor and allow me to kill them without restarting my browser
- Same goes for Flash but even moreso: I want every seizure-inducing, focus-stealing, ringtone-blaring flash app to be individually killable and blockable
- Show me the content of the page now even if some stupid ad or web bug or analytics script on a different server is slow to load
And for Santa's sake when I tell you to quit don't swap in every little JS object and free it individually. Throw the whole heap away and quit, damn your eyes!
OK? OK.
Alexisms
Sayings I use, only some of which are actually originally attributable to me. Anyone with research on a saying's provenance, feel free to comment. This page, unlike a normal blog entry, will be updated as needed with stuff I find myself saying with air quotes.
A comment is a lie waiting to happen.
"Legacy" means any program that people are actually using.
(Feathers: "Legacy" means "no tests.")
If you try hard enough, you can make anything fail.
There's no such thing as human error. (Only system error.)
If you pay attention to something, it gets better.
It's always a people problem. (Jerry Weinberg)
You can see a lot by looking. (Yogi Berra)
Yogi wrote a book called "You Can Observe A Lot By Watching" but I prefer to think he was misquoting himself.
Language Log has a take on this quote: She was seeing at me
Object-Oriented Programming is like teenage sex: everyone says they're doing it; few actually are; and those who are rarely know what they're doing. (Anonymous, via Misko)
Here's a simple test for whether you're doing it right: Is your data in the same class as the methods accessing it? Oh, really? Check again.
Double negatives are not unconfusing.
Scrum Diagram
Good Scrum diagram. Suitable for XP too (replace "sprint" with "iteration" and "daily scrum" with "daily standup").

Courtesy of Mountain Goat Software







