Keep code base clean – avoid unnecessary variable assignments
Keep code base clean – avoid unnecessary variable assignments
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"]
Significant Revisions
- May 6th, 2024 Converted to jekyll markdown format and copied to personal site
- Jul 14th, 2011 Originally published on txcowboycoder wordpress site1
Footnotes
-
Initial
md
Generated using https://github.com/jsr6720/wordpress-html-scraper-to-mdOriginal Wordpress categories: [‘Clean Code’]
Original Wordpress tags: “Clean Code”, “clean code”, “temp variables” ↩