Archive for the ‘Clean Code’ Category

Can’t tell you how frustrating it is to find the context of a variable stripped away by a meaningless re-assgiment (login required).

From Clean Code: A Handbook of Agile Software Craftsmanship:

The name of a variable, function, or class, should answer all the big questions. It
should tell you why it exists, what it does, and how it is used

// doing this totally strips away any meaningful context
$my_temp_variable = $employee_salaries[$an_employee_name];
$gross_salary = $bonus_factor * $my_temp_variable;

// hopefully the language constructs allow full variable interaction
$gross_salary = $bonus_factor * $employee_salaries["Fred"]

Read Full Post »

%d bloggers like this: