Your SlideShare is downloading. ×
程序员实践之路
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

程序员实践之路

637
views

Published on

Pragmatic Programmer …

Pragmatic Programmer
Estimating (提升专业素养)
DRY rule - Repeat or Reuse (提炼经验)
Control Structures & Complexity (简洁就是美)
Table Driven (善于运用算法)
Design for CHANGE (完善设计、争取主动)
Refactoring (追求卓越,勇于改进)
Automation (一切都要自动化)
Resource
Who is working for you (找个巨人的肩膀)
Accessories for you
Process and Methods
Process enhances confidence
Thought Disorder(最容易欺骗的人是自己)
Conceptual Blockbusting
Career anchors
How to define the VALUE (价值不等式)
Professionalism

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
637
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Horky SPD SW Apr/2011 http://blog.csdn.net/horkychen 1
  • 2. 介绍程序员成长路上的那些小事情! 2
  • 3. Agenda  Pragmatic Programmer  Estimating (提升专业素养)  DRY rule - Repeat or Reuse (提炼经验)  Control Structures & Complexity (简洁就是美)  Table Driven (善于运用算法)  Design for CHANGE (完善设计、争取主动)  Refactoring (追求卓越,勇于改进)  Automation (一切都要自动化)  Resource  Who is working for you (找个巨人的肩膀)  Accessories for you  Process and Methods  Process enhances confidence  Thought Disorder(最容易欺骗的人是自己)  Conceptual Blockbusting  Career anchors  How to define the VALUE (价值不等式)  Professionalism  Q&A 3
  • 4. Pragmatic Programmer (注重实效) 4
  • 5. Estimating (估算)  估算是专业能力的综合表现。  难点  需求分析  行政干预  精确度  PI  美国的议员曾提案要求将PI值定为3。  而NASA将需要12个小数位。  建议估算时间以周为单位。 5
  • 6.  估算是专业能力的体现!  新的系统  建立系统架构模型  分解为组件  设计组件的功能  依功能对各个组件进行估算  展开及细化  汇总  修改的系统  识别需要变更的组件  定义需变更的组件内容  依据变更的内容进行逐项估算  汇总  追踪估算,逐步修正误差!  Reference:  http://www.cnblogs.com/badwps/archive/2009/08/ 28/1555485.html Estimating (估算) 6
  • 7. DRY rule - Repeat or Reuse  开发者利器  Google & Baidu  Sourceforge & CodeProject  Ctrl+C & Ctrl+V  复用不是重复使用,而是如何重复使用!  思考:  物以稀为贵,越容易得到的也就越容易失去!  在如此开放的网络环境下,我们的知识还有多少价值?  面对变化时,维护成本变大且风险很高  知识是不稳定的!唯一不变的就是变化!  BUG可能隐藏在仸何位置,那是噩梦的开始!  对个人知识积累不利  常常消化不良 7
  • 8. Category and Count measure  类型:  无意的重复  无耐性的重复  对策  Simplify design  Cleaning Code  Coding Rule  Coding Review  Reference:  Refactoring: Improving the Design of existing code 8
  • 9. Control Structure  Need a loop that executes a specified number of times  To use a for loop  If change the index value of a for loop force it to terminate, use a while loop instead.  Else to use a while loop.  Reference:  Write Solid Code, Maguire, 1993 9
  • 10. Controlling the loop  Major principles  简化循环体相关连的因素(所引用的变量或数据),判 断或结束条件一定要简单。  循环也是另类的子程序,可以视其为Black box.  Entering the Loop  Put initialization code directly before the loop  Use while ( true ) for infinite loops  Don’t use a for loop when a while loop is more appropriate 10
  • 11. Sample Control statements vs. housekeeping statements 11
  • 12. Processing the middle of the loop  Use { and } to enclose the statements in a loop  Avoid empty loops  Keep loop-housekeeping chores at either the beginning or the end of the loop  Make each loop perform only one function  可以做,但不代表应该做。正确的代码不代表是好的代码! 12
  • 13. Exiting the loop  Existing loops early  According to an article in Software Engineering Notes, the software error that 7 brought down the New York City phone systems for 9 hours on January 15, 8 1990 was due to an extra break statement (SEN 1990) break的分散代表逻辑上的分散,会带来维护上的风险!大量的return出现在函数 体,多个深层嵌套,变量中途转为它用,多处理重复功能相近的代码,都预示者 开发者的逻辑可能已经出现问题! 13
  • 14. Checking endpoints  Willingness to perform this kind of check is a key difference between efficient and inefficient programmers.  How to check  Hand calculations  Mental simulations  Calculate by Excel  What are benefits?  You understand how your code works rather than guessing about it! 14
  • 15. How long should a loop be  Make your loops short enough to view all at once.  Limit nesting to three levels  Move loop innards of long loops into routines  Make long loops especially clear.  Single exit. 15
  • 16. Creating loop easily  From the inside out 16
  • 17. Control Structure and Complexity  The control flow is at least one of the largest contributors to complexity, if not the largest.  HP apply McCabe’s complexity metric, that is helpful to improve coding quality.  General guideline for reducing complexity  Improve your own mental juggling abilities  You can decrease the complexity of your programs and the amount of concentration required to understand them. 17
  • 18. How to measure complexity  Techniques for counting the decision points in a routine  Start with 1 for the straight pat through the routine  Add 1 for each of the following keywords, or their equivalents: if while repeat for and or  Add 1 for each case in a case statement  Exercise  if ( ( (status = Success ) and done) or ( not done and ( numLines >= maxLines ) ) ) then … *Cyclomatic Complexity 18
  • 19. Table Driven  Advantage:  Simplify codes and enhance the performance  Enhance the system customization capability.  Weakness:  Not everyone know it well, it may bring extra efforts.  Virtually anything you can select with logic statements, you can select with tables instead. 19
  • 20. Indexed Access Tables 20
  • 21. Stair-Step Access Tables 21
  • 22. Example static unsigned int chooseDPI(unsigned int original_dpi, int datatype) { int i, d, diff, k; static Support_Mode support_mode[] = { {4, 0}, //support two modes {150, 2}, {300, 3}, //300DPI with color and gray {600, 3}, //600DPI with color and gray {1200, 2} }; diff = -1; k = 1; for (i = 1; i <= support_mode[0].dpi; ++i) { if (support_mode[i].support_mode & datatype) { d = abs(support_mode[i].dpi - original_dpi); if (diff == -1) { diff = d; k = i; } else { if (d <= diff) { diff = d; k = i; } else break; } } } return support_mode[k].dpi; } 22
  • 23. Design for Change • 应对变化: – 解耦:得墨忒尔法则 – 元数据与动态配置 – 并发与次序 – 划分模块、分而治之 23
  • 24. The law of Demeter  某个对象的任何方法都应该只能调用:  它自身  传入该方法的任何参数  它创建的任何对象  任何直接持有的组件对象 24
  • 25. Meta data and Dynamic Configuration  将变化封装起来,使用元数据进行配置。  什么是变化的?  什么是不变化的?  抽象、抽象  Example:  Linux – Build your own Linux distribution 25
  • 26. 并发与时序  时间耦合(temporal coupling)  定义好你的工作流  用服务为并发进行设计 26
  • 27. 分而治之  观察者模式 27
  • 28. Refactoring 重构最困难之处在于情感上,而不是技术上! 目的: 不改变“软件之可察行为”前提下, 提高其可理解性,降低其维护成本. 权威著作: Author: Martin Fowler 28
  • 29. Example 1  分析switch(nBits)  以下两种为常用运算 +3)>>2)<<2  ConvertToMultipleOfFour +7)>>3)+3)>>2)<<2  GetRowBytesForMonoImage 29
  • 30. Example 2 if/else两个分支中有部分重复代码 if(nDestResolution <= nFromSourceResX) { FlatTypeCfg.bitsPerPixel=1; nScaleBitsPerPixel=1; FlatTypeCfg.composition=scLineArt; nDestWidth=nScanRight-nScanLeft+1; nSourceWidth=FlatTypeCfg.bounds.right-FlatTypeCfg.bounds.left+1; nSourceRowBytes=GetRowBytesForMonoImage(nSourceWidth); scImage.rowBytes=nSourceRowBytes; nDestRowBytes=GetRowBytesForMonoImage(nDestWidth); } else { // Use scan gray mode to simulate BW FlatTypeCfg.bitsPerPixel=8; FlatTypeCfg.composition=scGrayScale; nScaleBitsPerPixel=1; nDestWidth=nScanRight-nScanLeft+1; nSourceWidth=FlatTypeCfg.bounds.right-FlatTypeCfg.bounds.left+1; nSourceRowBytes=ConvertToMultipleOfFour(nSourceWidth); scImage.rowBytes=nSourceRowBytes; nDestRowBytes=GetRowBytesForMonoImage(nDestWidth); } 30
  • 31. Example 2. New codes nDestWidth=nScanRight-nScanLeft+1; nSourceWidth=FlatTypeCfg.bounds.right-FlatTypeCfg.bounds.left+1; if(nDestResolution <= nFromSourceResX) { FlatTypeCfg.bitsPerPixel=1; FlatTypeCfg.composition=scLineArt; nSourceRowBytes=GetRowBytesForMonoImage(nSourceWidth); } else { // Use scan gray mode to simulate BW FlatTypeCfg.bitsPerPixel=8; FlatTypeCfg.composition=scGrayScale; nSourceRowBytes=ConvertToMultipleOfFour(nSourceWidth); } nDestRowBytes=GetRowBytesForMonoImage(nDestWidth); nScaleBitsPerPixel=1; scImage.rowBytes=nSourceRowBytes; 31
  • 32. Automation  Release  Localization & Wording  Regression testing  Coding 32
  • 33. Release  Dynamic Languages  Perl  Python  Ruby 33
  • 34. Regression testing  Windows:  Python + Pywinauto  Mac OS (No full solution)  AppleScript  Sikuli 34
  • 35. Code Generator  用模具来提高工作效率!  M4 -> Generate Info.plist  -> Generate HTML/XML file  flex -> Parser 35
  • 36. Reference 36
  • 37. Authors Kent Beck Steve McConnell Andrew Hunt Dave Thomas Martin Fowler 37
  • 38. Resource 38
  • 39. Who is working for you  More than 1,441,209 engineers are working for you:  SourceForge  Google Code  Code Project  Linux Community 39
  • 40. Accessories  Unit Test: CPPUnit, Google Test, PyUnit  Static Code Checking: CPPTest, splint,  Cyclomatic Complexity counting: cyclo  LOC counting: Beyond Compare,Cloc in perl  UML tools:Bouml, ArgoUML  Drawing tool: yEd  Mind mapping tool:Freemind  VNC:TightVNC  Editor: Notepad++  Python/Perl Editor: TextWrangler  Schedule Utility on Linux/Mac OS: Taskjuggler  Installation utility: Inno Setup  MD5 Checksum on Windows: WinMD5  MD5 Checksum on Unix/Linux/Mac OS:md5sum  Team Work : GForge, FusionForge  Version Management: Subversion,Git,Bazaar 40
  • 41. Process and Methodology 41
  • 42. Process enhances confidence  Follow the existing process well.  To reduce development risk. 42
  • 43. Two critical issues  DLL building failed  Customer get corrupted release package  Side-effect for function parameter with default value 43
  • 44. Enhance the process with tool  DLL building failed  Create one script to check version number for each DLL  Customer get corrupted release package while testing  Provides the MD5 Checksum  Side-effect for function parameter with default value  Define in coding rule 44
  • 45. Thought Disorder 45
  • 46. Conceptual Blockbusting Reference: 突破思维的障碍 46
  • 47. Methodology 大M: 公司定义的工作方法 (BMS, VM, CMMI, Agile Dev.) 小m: 个人的工作方法 (SVN, Coding style) 47
  • 48. Key Problem in Project  Schedule & Quality  No enough time to build best deliverables.  压缩开发时间,必须做好承担风险的准备!  加班或加人都不是面对风险的最佳途径! 48
  • 49. Career anchors 49
  • 50. Career anchors  充分认识自我,准确地“抛锚”于你钟情的职业,实现人生价值的最大 化。  我们不得不面对这样一个事实:知识经济时代要求从业者具备终身学 习能力,从业者能力的提高必然带来择业机会的增多,而从者直接导 致从业者在面对职业选择机会时困惑的加剧!职业困惑部分源于外在 因素对个人价值观的影响,更有一部分是因为困惑者对自身需求的不 了解。 50
  • 51. Eight anchors  技术/职能型职业锚  管理型职业锚  创造/创业型职业锚  自主/独立型职业锚  安全/稳定型职业锚  服务型职业锚  挑战型职业锚  生活型职业锚 Edgar H. Schein 51
  • 52. Your Knowledge Portfolio  经营你的资产  定期投资  多元化是长期成功的关键  周期性地重新评估和平衡资产  批判地评判你所看到的和听到的! 52
  • 53. Study Plan for Programmer Level 10 Code Complete 2nd Edition, Steve McConnell Programming Pearls 2nd Edition, Jon Bentley Refactoring, Martin Fowler UML Distilled, Martin Fowler Applying UML & Patterns 2nd Ed, Craig Larman Testing Computer Software, Cem Kaner et all Conceptual Blockbusting, James Adams Software Creativity, Robert Glass Software Project Survival Guide, Steve McConnell Level 11 Mastering the Requirements Process, Robertson and Robertson Software Requirements, Karl Wiegers "Manager's Handbook for Software Development", NASA Goddard Space Flight Center Writing Efficient Programs, John Bentley Writing Solid Code, Steve Maquire Software Implementation, Michael Marcotty More Programming Pearls, John Bentley A Practitioner's Guide to Software Testing Design, Lee Copeland Rapid Development, Steve McConnell Level 12 Design Patterns, Erich Gamma et all Object Oriented Software Construction, Bertrand Meyer Object Oriented Analysis and Design, Grady Booch Software Architecture in Practice, Bass et all "Manager's Handbook for Software Development", NASA Goddard Space Flight Center "Software Measurement Guidebook", NASA Goddard Space Flight Center 53
  • 54. Level 10 Rapid Development, Steve McConnell "Manager's Handbook for Software Development", NASA Goddard Space Flight Center Mastering the Requirements Process, Robertson and Robertson Software Requirements, Karl Wiegers Level 11 Agile and Iterative Development: A Managers Guide, Craig Larman Balancing Agility with Discipline, Barry Boehm and Richard Turner Creating a Software Engineering Culture, Karl Wiegers Peopleware, DeMarco and Lister A Practitioner's Guide to Software Test Design, Lee Copeland "Recommended Approach to Software Development, NASA Goddard Space Flight Center "Software Measurement Guidebook", NASA Goddard Space Flight Center Level 12 Agile Modeling, Scott Adams Requirements by Collaboration: Workshops for Defining Needs, Ellen Gottesdiener Scenarios, Stories, Use Cases, Ian Alexander Writing Effective Use Cases, Alistair Cockburn Peer Reviews, Karl Wiegers The Logic of Failure: Recognizing and Avoiding Error in Complex Situations, Domer Dietrich Customer Oriented Software Quality Assurance, Frank Ginac Code Complete 2nd Edition, Steve McConnell Applying UML & Patterns 2nd Ed, Craig Larman Study Plan for Manager 54
  • 55. 正當的力量,才是人生的王道! 人生不只是一場戰鬥,更是一趟有夢相隨的旅 程。 為你的夢想追根究柢,一切就從基本功開始! ◎每一個工作,都可以有計畫的幫自己尋找磨練的機會。 ◎所有的成就都來自於基本功;而基本功來自於既深且廣 的歷練。 ◎從事每一行都需要寬廣的視野,才能出類拔萃。 ◎先求有,再求好。 55
  • 56. THANKS 56