Extreme Programming in Perl Robert Nagler phần 9

Tham khảo tài liệu 'extreme programming in perl robert nagler phần 9', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Stylin Coding style is important to consider when refactoring. In this chapter I chose to maintain the style of the To contrast here s what .access would look like in bOP style sub access my field self value @ return @ 3 self- a There are some minor changes to whitespace indentation and brace placement for consistency and brevity within this book. b Except in FORTRAN where the name of the variable can determine its type. ield value self Tactics Versus Strategy When we begin a task tactics are important. We want to add business value as quickly as possible. Doing the simplest thing that could possibly work is a tactic to reach our goal. Copy-and-paste is the weapon of choice when task completion is our only objective. Generalizations such as the refactorings shown thus far are not easy to come up with when you re under pressure to get the job done. Besides you don t know if the code you copy solves the problem until the implementation is finished. It s much better to copy-and-paste to test an idea than to invent to implement and to use the wrong abstraction. As a design strategy copy-and-paste poses problems. The code is more difficult to comprehend because it s difficult to see subtle differences. Faults fixed in one place do not propagate themselves automatically. For example there s an alternative fix to the problem already embedded in two other accessors Count and Size sub Count my me shift my c shift if defined c and length c 0 me- COUNT c else return me- COUNT Copyright 2004 Robert Nagler All rights reserved nagler@ 134 sub Size my me shift my c shift if defined c and length c 0 me- SIZE c else return me- SIZE These accessors behave differently from the other eight that we refactored and fixed above. Count and Size need to be resettable to zero mailboxes can be empty which is why the accessors have an alternate implementation. The thought and debugging that went into fixing Count and Size could have also applied to the other .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.