Saturday, May 22, 2010

Focus-follows-mouse in Windows (AutoHotKey)

This AutoHotKey code gives you focus-follows-mouse behavior: whatever window the mouse is over has "focus" (keys pressed are sent here). This lets you select a window faster than alt-tabbing though all the options. This script does not raise the window, so you can type in part of a window that is still partially covered (this comes in handy more often than you might think).

Thanks to sooyke, who posted it here.


~ScrollLock::

SLStatus := GetKeyState("ScrollLock", "T")
SPI_SETACTIVEWINDOWTRACKING = 0x1001
SPIF_UPDATEINIFILE = 1
SPIF_SENDCHANGE = 2
DllCall("SystemParametersInfo",UInt,SPI_SETACTIVEWINDOWTRACKING,UInt,0,UInt,SLStatus,UInt,SPIF_UPDATEINIFILE | SPIF_SENDCHANGE)
return

There and back again: last week's brief return to linux

I put Ubuntu back on my machine recently, because the ATI drivers for my card under Win7 weren't working with my shaders. It was kind of fun, and I do remember liking the control it gave me over customization. However, to my surprise, I noticed several things:
1) Lots of fit and finish bugs (options missing or not being saved, UI elements in the wrong place, stuff like that). And these were all within the first few hours of using the product!
2) At least one completely unexpected hard crash (while scrolling a page in firefox!)
3) I *really* missed the (Shift)+Win+Left/Right/Up window management and Win+P display management from Win7
4) Something in the font smoothing or colors in X gives me a headache! (I can stare at gvim with the desert colorscheme for hours in Win7, but had trouble concentrating after a few minutes in Ubuntu)

I actually remember getting headaches in college when working on code late at night, but I always assumed it was because it was late or I was tired. Now I'm not so sure...

As surprised as I am to say it, I really prefer working in Windows now. As I said, I like the customizability of the linux world, but the quality bar isn't nearly as high as Win7 or OS X. Only the hard-crash prevented me from doing my work, but that's the problem with how the linux world tends to view these problems. There's a sort of broken window theory at play: if it's understood that "minor" bugs can be left in (because "they don't really affect functionality, just work around it! They should use the command line anyway..."), then other more severe bugs will start to creep in.

That said, I'm a stubborn person, and would've scripted my way around it, were it not for the fact that using it literally gave me a headache! Rebooting back to Win7, I was actually comforted by aero theme, taskbar, and other things i have limited control over. Sure, I can't customize them to my hearts content, but I can count on them. I feel at home in Windows now, and if I ever want to really get crazy with customizability, I can look into AutoHotkey.

I'm still curious about why X gave me a headache, though.

Friday, May 21, 2010

The "Uncanny valley" of automation

Automation is not the panacea I thought it was.

Implemented incorrectly, an automation system will waste more of your time than it saves. Sure, you won't have to run through the same checklists over and over, but your time will instead be spent tracking down a disproportionately large number of false positives. At first, I thought: "Hey, at least it's code! It's got to be more fun than just using the product, right?" Now I'm not so sure.

In robotics and computer graphics, there's a problem known as the "uncanny valley": when you get closer to modeling realistic human behavior, the results can be unsettling. I propose that there's a similar problem with automation: the closer you get to trying to simulate human behavior, the more problematic the results. (A bit of a stretch, and due to an entirely different set of problems, but bear with me).

Humans are good at dealing with the abstract. Take, for instance, the hard to read text you're supposed to identify when signing up for something (it's called a "CAPTCHA"). Reading these is (usually) easy for a human; we look at the blurry distorted mess and see letters. This is something we are good at. Writing a program that can read those things, on the other hand, is a difficult computer science problem.

Conversely, say you had to create dozens of accounts somewhere (perhaps as part of testing an online service). Completely filling out the name, address, interests, secret question, etc, is boring, repetitive, and prone to mistakes. These sort of tasks are not our forte. However, it's easy to write a script that fills in all of the fields for you. (Especially with a web page, since you can interact directly with the DOM).

This example illustrates the balance between manual and automatic tasks. Humans are good at abstract reasoning and big picture. Computers are good at repetition and precision (note I didn't say accuracy :-P)

Human users have no problem with slight changes in design or layout (and sometimes they won't even notice); computers tend to go apeshit. This is what causes so many of the automation failures you'll be tracking down. Maybe the browser started minimized, or another window popped up in front of it and stole focus (automatic updates, anyone?). Maybe the page took a few seconds longer to load, and the expected items weren't there when the script checked for them. Maybe the designer moved a button or changed a label. Or, maybe your test itself was wrong! There may be a legitimate outcome that you, author of the test, didn't think of. (When tests are code, they can have bugs too!)

Where computers shine are precisely defined problems. This suits them well for testing behind the scenes, where the input and output is not so abstract. If I send this packet, does the server give back that response? If I call this function with this value, do I get back that answer? What makes this sort of testing and verification so boring (and difficult) for humans is precisely what makes it so perfect for computers.

Another area where automation shines is tools. Running a series of installers and patches...opening up dozens of web browsers to a series of long, convoluted URLs...finding all the logs from a certain period of time, spread over dozens of computers, compressing them, copying them to a central repository, and emailing all interested parties about their availability...these are the sort of mindless, error prone tasks that waste tester time and are just begging to be automated.

The take away from this is that automated tests are most useful when they augment human testing, not try to replace it. Automation should simplify the lives of human testers -- by taking over the tasks humans are inherently bad at -- so they can focus on what they do well: finding problems in the user experience.

Sunday, May 16, 2010

Compile Cg shaders from command line

Use cgc to compile Cg shader programs from the command line. (cgc --help for usage). Useful for seeing errors/warnings and instruction counts.

Cheat sheet:
Vertex shader: cgc vert.cg -entry main -profile arbvp1
Fragment shader: cgc frag.cg -entry main -profile arbfp1