Notes
Slide Show
Outline
1
The Software Craftsman
  • Keith Alcock
  • TCS DevSig
  • July 2, 2002
2
I. Introduction
3
Source
  • Software Development of July 2002 in article called “Opening Disaster” by Robert Martin
  • The forthcoming book Principles, Patterns, and Practices of Agile Software Development (Prentice Hall, 2002)
4
Query
  • Who subscribed to the magazine?
  • Who has read the article?
  • Who looked at the web page?
  • Who has seen Smalltalk version of code?
5
Cast
  • Apprentice: Alphonse
  • Journeyman: Jerry
  • Master craftsman: Mr. C.
6
Act I: Orientation
7
Scene I: Alphonse codes
  • Assignment
    • Sieve of Eratosthenes
    • Unit tests
  • Constraints
    • Java language
    • Due after lunch
    • Meets standards of Mr. C.
  • Preliminary results
    • Complete and under schedule
8
Scene II: Jerry reviews
  • 5-minute silent code review
  • Step-by-step walkthrough
  • Preliminary results
    • Does not meet Mr. C’s standards
      • Long method identified
      • Refactoring suggested
9
Topics
  • Code reviews
  • Refactoring
  • Unit testing
10
Methods
  • Overview
  • Discussion
  • Hands-on
11
II. Code review
12
Source
  • Handbook of Walkthroughs, Inspections, and Technical Reviews by Freedman and Weinberg (Dorset House, 1990)
  • Extreme Programming Explained by Kent Beck (Addison Wesley, 2000)
13
Query
  • Who has read either book?
  • Who has done code reviews?
  • Who read the handout from a previous meeting?
  • Who does XP or Agile?
14
Rationale
  • “Point out needed improvements in a product of a single person or team.”
  • “Confirm those parts of a product in which improvement is either not desired or not needed.”
  • “Achieve technical work of more uniform, or at least more predictable, quality than can be achieved without reviews, in order to make technical work more manageable.”
15
Additional benefits
  • Assure that more than one person has seen each part of the projects and has a basic understanding of it
  • Identify reusable components within a project or across projects
  • Provide data on common mistakes that can then be used in testing
  • Locate areas where code or function is duplicated
16
Example guidelines
  • Pretty print code to standard format
  • Code should compile and run
  • Reviewers must be prepared
  • Identify problems and correct them in different steps
  • Find good things as well as bad
17
Example materials
  • Program listing
  • Checklists for common problems
    • Style manuals
    • Pattern guides
  • Design documents
    • CRC cards
    • UML diagrams
  • Report forms
18
Roles
  • Review leader
  • Recorder
  • Reviewers
  • Author
19
III. Refactoring
20
Source
  • Refactoring by Martin Fowler (Addison Wesley, 2000)
  • www.refactoring.com/
21
Query
  • Who has read the book?
  • Who has used automated tools?
22
Definition
  • “Refactoring (noun): a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.”
  • “Refactor (verb): to restructure software by applying a series of refactorings without changing its observable behavior.”
23
Rationale
  • Improves the design
  • Simplifies the software
  • Helps identify errors
  • Prevents decay
24
Timing
  • When adding functionality
  • During debugging
  • For code review
  • To avoid the third strike
25
Example problems
  • Duplicated code
  • Long method
  • Long parameter list
  • Comments
  • Lazy class
26
Example solutions
  • Extract method
  • Replace magic number with symbolic constant
  • Rename variable
  • Introduce explanatory variable
27
Tools
  • Refactoring browser
  • Unit testing framework
28
IV. Unit testing
29
Source
  • Article “Simple Smalltalk Testing: With Patterns” by Kent Beck
  • www.xprogramming.com/software.htm
30
Query
  • Who has used SUnit or JUnit?
31
Unit
  • For purposes of unit testing with object-oriented languages, unit most often means a class.
  • “Classes should contain their own tests.”
32
Components
  • Fixture
    • Configured instance of class to be tested
  • Test case
    • Stimulus used for the test
  • Check
    • Code to check results of the test
  • Test suite
    • Collection of tests
33
Results
  • Pass
    • No failure or error detected
  • Failure
    • Anticipated problem
  • Error
    • Condition that wasn’t checked
34
Example guidelines
  • Write tests based on risk factor
  • Tests should be fully automatic
  • Tests should check their own results
  • Don’t be a completionist
35
V. Summary
36
Craftsman
  • A craftsman is a person who makes or manufactures (e.g., software) with skill and careful attention to detail
  • Some of the skills include knowing how to review code, refactor, and test.