Commit as Often as Possible

A source control tool enables us to safely and quickly revert to a known good point, provided we took small steps and committed frequently.

Andreas Diehl
From dno

If, by any chance, we find ourselves in a bad spot, we can revert back to a safe point and start over. Refactoring should be a series of small experiments that we can easily roll back from. Figure 6.1: Extended TDD cycle: the refactor cycle Refactor Readability before Design If we cannot fully understand what the code we are refactoring does, then what are the chances of succeeding? Small improvements in code readability can drastically improve code understandability. To improve readability, you should start with better names for variables, methods, and classes. The idea is to express intent rather than implementation details. We recommend Arlo Belshee's approach to naming. Arlo Belshee, Good naming is a process, not a single step: http://arlobelshee.com/good-naming-is-a-process-not-a-single-step/. Format Format the code – a simple but very effective technique. Format consistently and don't force the reader to waste time due to inconsistent formatting. Example: Before if (i == 1) tempScore = m_score1; else { score += "-"; tempScore = m_score2; } After A simple change can make the code much more obvious for the reader: if (i == 1) { tempScore = m_score1; } else { score += "-"; tempScore = m_score2; } Rename Rename bad names, variables, arguments, instance variables, methods, and classes Make abbreviations explicit Example: Before class TennisGame1 : ITennisGame { private int m_score1 = 0; private int m_score2 = 0; } After In this example, the meaning of m_score1 is confusing, so we renamed it to the more obvious name of player1Score: class TennisGame1 : ITennisGame { private int player1Score = 0; private int player2Score = 0; } Remove Delete unnecessary comments. Delete dead code. Don't make the reader waste time trying to figure out code that is not in use anymore. Example: Before class TennisGame : ITennisGame { private int player1Score = 0; private int player2Score = 0; private string player1Name; private string player2Name; public TennisGame1(string player1Name, string player2Name) { this.player1Name = player1Name; this.player2Name = player2Name; } }

Kommentare

-

Formular

Lade Formular…

Formular konnte nicht geladen werden. Bitte versuche es erneut.