Naming Things
October 11, 2014 by Chris Johnson. Filed under
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
Deprecated: Creation of dynamic property WP_Term::$cat_ID is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 378
Deprecated: Creation of dynamic property WP_Term::$category_count is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 379
Deprecated: Creation of dynamic property WP_Term::$category_description is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 380
Deprecated: Creation of dynamic property WP_Term::$cat_name is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 381
Deprecated: Creation of dynamic property WP_Term::$category_nicename is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 382
Deprecated: Creation of dynamic property WP_Term::$category_parent is deprecated in /var/www/twodee/blog/wp-includes/category.php on line 383
pop computer science, public.
Often in my introductory programming classes I will share a snippet of code that is unnamed or vaguely named. I ask the students to interpret the code and choose better names.
This past week I gave them this snippet:
public static double ?(double x, boolean b) {
if (b) {
return x;
} else {
return x * 1.055;
}
}
After giving them time to consider the code, I asked, “What’s a better name for this?” Answer 1: returnX. Answer 2: pinocchio. Answer 3: addSalesTax. No more answers. We went back through these suggestions and discussed their relative merits. Answer 1 didn’t provide any semantic meaning and wasn’t always completely true. Answer 3 was appropriate. Our local sales tax is 5.5%, but not all items are taxable.
I asked the student who offered the pinocchio answer to explain himself. Certain that he was being silly, I was leveled by his justification: “Everytime the expression is false, x gets bigger.”