Monday, November 3, 2014

Wrong naming revisit


I was looking at the excellent work by appium, and saw this little snippet in an example:


var el = driver.FindElementById ("name_input");

el.Clear ();

el.SendKeys ("Appium User");

el.SendKeys (Keys.Return);

There's nothing horribly wrong with the name el, except that it's exactly what we ask people not to do with names. 

El is short for element (a bit of mental mapping, but the length of the name reflects the shortness of scope). But it is not informative.

The variable "el" (EE-EL) looks like "e1" (EE-ONE) to the casual reader. The name doesn't look right. 

Also, "element" is what it's made of, not what it's for.  Yes it's an element. But it means "the name input field" so "nameField" or"name_field" or "name" might be better. Or even "input" if it's the only input field in the block.

Appium is pretty cool. You should check it out. But remember that writing examples is both something rather important (people copy or imitate examples) and something hard to do. We write them thinking "the api is the important thing" or "the idea is what matters" but we forget how seriously people will take examples.

No comments:

Post a Comment