visit
TL;DR: Don't Assign and overwrite values
The "dead store" code smell refers to a situation in programming where a variable is assigned a value but is never subsequently read or used in the program. It's a variable that is given a value but that value is never utilized, making the assignment unnecessary and potentially indicative of a mistake or inefficiency in the code.
<?
$lastGoalAuthor = "Lio Messi";
$lastGoalAuthor = "Ángel Di María";
$lastGoalAuthor = "Lio Messi";
// This is stored unconditionally
// You can optimize it by removing the first two statements
// Since storing in a variable has no side effects
<?
$lastGoalAuthor = "Lio Messi";
// If you want to keep the last one
$goalAuthors[] = "Lio Messi";
$goalAuthors[] = "Ángel Di María";
$goalAuthors[] = "Lio Messi";
// If you want to keep a list
$lastGoalAuthor = firstGoalAutor();
$lastGoalAuthor = secondGoalAutor();
$lastGoalAuthor = thirdGoalAutor();
// This might be valid since functions in
// Object-Oriented Programming might have side effects
// and you cannot remove the first ones
// Unless you ensure they don't have side effects
Disclaimer: Code Smells are my opinion.
Good programmers use their brains, but good guidelines save us having to think out every case.
This article is part of the CodeSmell Series—How to Find the Stinky Parts of your Code