SlideShare ist ein Scribd-Unternehmen logo
1 von 27
Downloaden Sie, um offline zu lesen
Clean Code

                              Hendrik Ebel
                             10. Mar. 2009
Tuesday, March 10, 2009
Topics
                          Motivation
                          Meaningful Names
                          Comments
                          Functions
                                                        By Robert C. Martin & Co.


                          Objects and Data Structures      Object Mentor Inc.




                          Error Handling
                          Unit Tests
Tuesday, March 10, 2009
What is Clean Code?
                          One Question ...




Tuesday, March 10, 2009
What is Clean Code?
                          One Question ...
                                                   elegant
                                                                efficient
                             simple and direct

                                                  readability        easy to enhance
                      like a well-written prose
                                                             care
                                     no duplications
                                                   was made for the problem
                  ...many answers!
Tuesday, March 10, 2009
What is Clean Code?
                          One Question ...
                                                   elegant
                                                                efficient
                             simple and direct

                                                  readability        easy to enhance
                      like a well-written prose
                                                             care
                                     no duplications
                                                   was made for the problem
                  ...many answers!
Tuesday, March 10, 2009
Motivation
                          The Total Cost of Owning a Mess




                                    productivity vs. time

Tuesday, March 10, 2009
Aims of Clean Code

                          producing better code
                          @author writing for readers
                          code has to be kept clean over time
                          „Leave the campground cleaner than
                          you found it.“


Tuesday, March 10, 2009
Meaningful Names




Tuesday, March 10, 2009
Meaningful Names
                          variable, function or class names should
                          answer all the big questions:

                           why it exists?
                           what it does?
                           how it is used?


Tuesday, March 10, 2009
Meaningful Names
                          If a name requires a comment, then the
                          name does not reveal its intent
                          avoid disinformation
                           don't use type information in names
                           (example: personList)
                           Spelling similar concepts similarly is
                           information. Using inconsistent spellings is
                           disinformation.

Tuesday, March 10, 2009
Comments




Tuesday, March 10, 2009
Good and Bad Comments
                     • Public API Comments     • Redundant Comments
                     • Legal Comments          • Noise Comments
                     • Explanation of Intent   • Position Markers
                     • Warning for             • Closing Brace Comments
                                               • Commented-Out Code
                          Consequences
                     • real TODO Comments      • Obsolete Comments
                                               • Nonpublic JavaDocs



Tuesday, March 10, 2009
Comments

                          „Purpose of a comment is to explain code
                          that does not explain itself.“
                          Comments do not make up for bad code
                          Don‘t use a comment when you can use a
                          function or a variable
                          Comments can contains lies

Tuesday, March 10, 2009
Functions




Tuesday, March 10, 2009
Functions
                          The goal is to tell the story of the
                          system.
                          „The first rule of functions is that they
                          should be small.“
                          Do One Thing!
                          Stepdown Rule


Tuesday, March 10, 2009
Functions
                          Ideal number of arguments is zero
                          More than three should‘t be used
                          anyway
                          Flag arguments are ugly.
                          Avoid output arguments
                          Side effects are lies.


Tuesday, March 10, 2009
Objects and Data
                             Structures




Tuesday, March 10, 2009
Objects
                          hide data and expose functions
                          easy to add new objects
                          hard to add new behaviors




Tuesday, March 10, 2009
Data Structures
                          expose data and have no meaningful
                          functions
                          easy to add new behaviors
                          hard to add new data structures

                          Choose the approach that is best for the job.



Tuesday, March 10, 2009
Error Handling




Tuesday, March 10, 2009
Error Handling

                          Write code that is clean and rebust
                          See error handling as a separate concern
                          Use exceptions rather than return codes
                          Use unchecked exceptions



Tuesday, March 10, 2009
Error Handling
                          Don‘t return NULL
                           throwing an exception or a special
                           case object like
                           „Collections.emptyList()“
                          Don‘t pass NULL
                           InvalidArgumentExceptions or assert
                           better: forbid passing NULL by default
Tuesday, March 10, 2009
Unit Tests




Tuesday, March 10, 2009
Unit Tests
                          Test Driven Development (TDD)
                           test and production code are written
                           together
                           tests just a few seconds ahead
                          Keeping tests clean
                          Test code is just as important as
                          production code.

Tuesday, March 10, 2009
Unit Tests
                          One Assert or Single Concept per Test
                          F.I.R.S.T.
                            Fast
                            Independent
                            Repeatable (in any environment)
                            Self-Validation
                            Timly

Tuesday, March 10, 2009
Thanks - Any Questions?




Tuesday, March 10, 2009
Sources
             Book
                   „Clean Code“ by Robert C. Martin
                   ISBN: 0132350882
             Images
                   http://www.failblog.org
                   http://www.flickr.com/photos/hugovk/199425487/
                   http://www.flickr.com/photos/jackpot321/1809424991/
                   http://www.osnews.com/story/19266/WTFs_m

Tuesday, March 10, 2009

Más contenido relacionado

Was ist angesagt?

Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best PracticesTheo Jungeblut
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable codeGeshan Manandhar
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionKent Huang
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentationBhavin Gandhi
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code PrinciplesYeurDreamin'
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean ArchitectureBadoo
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next ChapterVictor Rentea
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Scott Wlaschin
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented ProgrammingScott Wlaschin
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean codeVictor Rentea
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipIvan Paulovich
 

Was ist angesagt? (20)

Clean Code I - Best Practices
Clean Code I - Best PracticesClean Code I - Best Practices
Clean Code I - Best Practices
 
Clean code
Clean codeClean code
Clean code
 
Writing clean code
Writing clean codeWriting clean code
Writing clean code
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean coding-practices
Clean coding-practicesClean coding-practices
Clean coding-practices
 
Clean Code
Clean CodeClean Code
Clean Code
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
Clean code
Clean codeClean code
Clean code
 
Clean Code: Chapter 3 Function
Clean Code: Chapter 3 FunctionClean Code: Chapter 3 Function
Clean Code: Chapter 3 Function
 
Clean code
Clean code Clean code
Clean code
 
Clean code presentation
Clean code presentationClean code presentation
Clean code presentation
 
Clean Code
Clean CodeClean Code
Clean Code
 
Clean Code Principles
Clean Code PrinciplesClean Code Principles
Clean Code Principles
 
Clean code
Clean codeClean code
Clean code
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Clean Code - The Next Chapter
Clean Code - The Next ChapterClean Code - The Next Chapter
Clean Code - The Next Chapter
 
Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)Functional Programming Patterns (NDC London 2014)
Functional Programming Patterns (NDC London 2014)
 
Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented Programming
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean code
 
Clean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software CraftsmanshipClean Architecture Essentials - Stockholm Software Craftsmanship
Clean Architecture Essentials - Stockholm Software Craftsmanship
 

Ähnlich wie Clean Code

Inleiding tot CHI
Inleiding tot CHIInleiding tot CHI
Inleiding tot CHIErik Duval
 
NodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' GuideNodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' GuideGrey Ang
 
Towards Organizational Agent-based Operating Systems
Towards Organizational Agent-based Operating SystemsTowards Organizational Agent-based Operating Systems
Towards Organizational Agent-based Operating SystemsJavi Palanca
 
JSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph PicklJSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph PicklChristoph Pickl
 
JSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph PicklJSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph PicklChristoph Pickl
 
Managing And Optimizing Memory Usage
Managing And Optimizing Memory UsageManaging And Optimizing Memory Usage
Managing And Optimizing Memory UsageJohn Wilker
 
Multi player iPhone Games
Multi player iPhone GamesMulti player iPhone Games
Multi player iPhone GamesJohn Wilker
 
IT Presentation to Internal Library Building Committee
IT Presentation to Internal Library Building CommitteeIT Presentation to Internal Library Building Committee
IT Presentation to Internal Library Building CommitteeJason Griffey
 
Introduction au referencemnet naturel
Introduction au referencemnet naturelIntroduction au referencemnet naturel
Introduction au referencemnet naturelSamuel Lavoie
 
Szczepan Faber mockito story (1)
Szczepan Faber   mockito story (1)Szczepan Faber   mockito story (1)
Szczepan Faber mockito story (1)magda3695
 
ATA 2009 LT-10 Why You Want To Translate On The Mac
ATA 2009 LT-10 Why You Want To Translate On The MacATA 2009 LT-10 Why You Want To Translate On The Mac
ATA 2009 LT-10 Why You Want To Translate On The MacDierk Seeburg
 

Ähnlich wie Clean Code (16)

JavaScript for PHP Developers
JavaScript for PHP DevelopersJavaScript for PHP Developers
JavaScript for PHP Developers
 
Depot Best Practices
Depot Best PracticesDepot Best Practices
Depot Best Practices
 
Inleiding tot CHI
Inleiding tot CHIInleiding tot CHI
Inleiding tot CHI
 
NodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' GuideNodeJS: Writing tests -- A Beginners' Guide
NodeJS: Writing tests -- A Beginners' Guide
 
Towards Organizational Agent-based Operating Systems
Towards Organizational Agent-based Operating SystemsTowards Organizational Agent-based Operating Systems
Towards Organizational Agent-based Operating Systems
 
JSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph PicklJSUG - ActionScript 3 vs Java by Christoph Pickl
JSUG - ActionScript 3 vs Java by Christoph Pickl
 
JSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph PicklJSUG - AS3 vs Java by Christoph Pickl
JSUG - AS3 vs Java by Christoph Pickl
 
Managing And Optimizing Memory Usage
Managing And Optimizing Memory UsageManaging And Optimizing Memory Usage
Managing And Optimizing Memory Usage
 
STOP! Use case time!
STOP! Use case time!STOP! Use case time!
STOP! Use case time!
 
Multi player iPhone Games
Multi player iPhone GamesMulti player iPhone Games
Multi player iPhone Games
 
IT Presentation to Internal Library Building Committee
IT Presentation to Internal Library Building CommitteeIT Presentation to Internal Library Building Committee
IT Presentation to Internal Library Building Committee
 
Introduction au referencemnet naturel
Introduction au referencemnet naturelIntroduction au referencemnet naturel
Introduction au referencemnet naturel
 
Becoming Indie
Becoming IndieBecoming Indie
Becoming Indie
 
Becoming Indie
Becoming IndieBecoming Indie
Becoming Indie
 
Szczepan Faber mockito story (1)
Szczepan Faber   mockito story (1)Szczepan Faber   mockito story (1)
Szczepan Faber mockito story (1)
 
ATA 2009 LT-10 Why You Want To Translate On The Mac
ATA 2009 LT-10 Why You Want To Translate On The MacATA 2009 LT-10 Why You Want To Translate On The Mac
ATA 2009 LT-10 Why You Want To Translate On The Mac
 

Último

LEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollLEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollDr. Bruce A. Johnson
 
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxBBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxProf. Kanchan Kumari
 
Riti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptxRiti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptxDhatriParmar
 
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17Celine George
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...Sandy Millin
 
UNIT I Design Thinking and Explore.pptx
UNIT I  Design Thinking and Explore.pptxUNIT I  Design Thinking and Explore.pptx
UNIT I Design Thinking and Explore.pptxGOWSIKRAJA PALANISAMY
 
Plant Tissue culture., Plasticity, Totipotency, pptx
Plant Tissue culture., Plasticity, Totipotency, pptxPlant Tissue culture., Plasticity, Totipotency, pptx
Plant Tissue culture., Plasticity, Totipotency, pptxHimansu10
 
POST ENCEPHALITIS case study Jitendra bhargav
POST ENCEPHALITIS case study  Jitendra bhargavPOST ENCEPHALITIS case study  Jitendra bhargav
POST ENCEPHALITIS case study Jitendra bhargavJitendra Bhargav
 
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxBBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxProf. Kanchan Kumari
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...Nguyen Thanh Tu Collection
 
Material Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.pptMaterial Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.pptBanaras Hindu University
 
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...Subham Panja
 
Quantitative research methodology and survey design
Quantitative research methodology and survey designQuantitative research methodology and survey design
Quantitative research methodology and survey designBalelaBoru
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxiammrhaywood
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsDhatriParmar
 
3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptx3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptxmary850239
 
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandThe OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandDr. Sarita Anand
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...Nguyen Thanh Tu Collection
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptxmary850239
 

Último (20)

LEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community CollLEAD5623 The Economics of Community Coll
LEAD5623 The Economics of Community Coll
 
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptxBBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
BBA 205 BE UNIT 2 economic systems prof dr kanchan.pptx
 
Riti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptxRiti theory by Vamana Indian poetics.pptx
Riti theory by Vamana Indian poetics.pptx
 
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...
 
UNIT I Design Thinking and Explore.pptx
UNIT I  Design Thinking and Explore.pptxUNIT I  Design Thinking and Explore.pptx
UNIT I Design Thinking and Explore.pptx
 
Plant Tissue culture., Plasticity, Totipotency, pptx
Plant Tissue culture., Plasticity, Totipotency, pptxPlant Tissue culture., Plasticity, Totipotency, pptx
Plant Tissue culture., Plasticity, Totipotency, pptx
 
POST ENCEPHALITIS case study Jitendra bhargav
POST ENCEPHALITIS case study  Jitendra bhargavPOST ENCEPHALITIS case study  Jitendra bhargav
POST ENCEPHALITIS case study Jitendra bhargav
 
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxBBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
 
Problems on Mean,Mode,Median Standard Deviation
Problems on Mean,Mode,Median Standard DeviationProblems on Mean,Mode,Median Standard Deviation
Problems on Mean,Mode,Median Standard Deviation
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (GLOB...
 
Material Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.pptMaterial Remains as Source of Ancient Indian History & Culture.ppt
Material Remains as Source of Ancient Indian History & Culture.ppt
 
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
THYROID HORMONE.pptx by Subham Panja,Asst. Professor, Department of B.Sc MLT,...
 
Quantitative research methodology and survey design
Quantitative research methodology and survey designQuantitative research methodology and survey design
Quantitative research methodology and survey design
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian Poetics
 
3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptx3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptx
 
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita AnandThe OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
The OERs: Transforming Education for Sustainable Future by Dr. Sarita Anand
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx
 

Clean Code

  • 1. Clean Code Hendrik Ebel 10. Mar. 2009 Tuesday, March 10, 2009
  • 2. Topics Motivation Meaningful Names Comments Functions By Robert C. Martin & Co. Objects and Data Structures Object Mentor Inc. Error Handling Unit Tests Tuesday, March 10, 2009
  • 3. What is Clean Code? One Question ... Tuesday, March 10, 2009
  • 4. What is Clean Code? One Question ... elegant efficient simple and direct readability easy to enhance like a well-written prose care no duplications was made for the problem ...many answers! Tuesday, March 10, 2009
  • 5. What is Clean Code? One Question ... elegant efficient simple and direct readability easy to enhance like a well-written prose care no duplications was made for the problem ...many answers! Tuesday, March 10, 2009
  • 6. Motivation The Total Cost of Owning a Mess productivity vs. time Tuesday, March 10, 2009
  • 7. Aims of Clean Code producing better code @author writing for readers code has to be kept clean over time „Leave the campground cleaner than you found it.“ Tuesday, March 10, 2009
  • 9. Meaningful Names variable, function or class names should answer all the big questions: why it exists? what it does? how it is used? Tuesday, March 10, 2009
  • 10. Meaningful Names If a name requires a comment, then the name does not reveal its intent avoid disinformation don't use type information in names (example: personList) Spelling similar concepts similarly is information. Using inconsistent spellings is disinformation. Tuesday, March 10, 2009
  • 12. Good and Bad Comments • Public API Comments • Redundant Comments • Legal Comments • Noise Comments • Explanation of Intent • Position Markers • Warning for • Closing Brace Comments • Commented-Out Code Consequences • real TODO Comments • Obsolete Comments • Nonpublic JavaDocs Tuesday, March 10, 2009
  • 13. Comments „Purpose of a comment is to explain code that does not explain itself.“ Comments do not make up for bad code Don‘t use a comment when you can use a function or a variable Comments can contains lies Tuesday, March 10, 2009
  • 15. Functions The goal is to tell the story of the system. „The first rule of functions is that they should be small.“ Do One Thing! Stepdown Rule Tuesday, March 10, 2009
  • 16. Functions Ideal number of arguments is zero More than three should‘t be used anyway Flag arguments are ugly. Avoid output arguments Side effects are lies. Tuesday, March 10, 2009
  • 17. Objects and Data Structures Tuesday, March 10, 2009
  • 18. Objects hide data and expose functions easy to add new objects hard to add new behaviors Tuesday, March 10, 2009
  • 19. Data Structures expose data and have no meaningful functions easy to add new behaviors hard to add new data structures Choose the approach that is best for the job. Tuesday, March 10, 2009
  • 21. Error Handling Write code that is clean and rebust See error handling as a separate concern Use exceptions rather than return codes Use unchecked exceptions Tuesday, March 10, 2009
  • 22. Error Handling Don‘t return NULL throwing an exception or a special case object like „Collections.emptyList()“ Don‘t pass NULL InvalidArgumentExceptions or assert better: forbid passing NULL by default Tuesday, March 10, 2009
  • 24. Unit Tests Test Driven Development (TDD) test and production code are written together tests just a few seconds ahead Keeping tests clean Test code is just as important as production code. Tuesday, March 10, 2009
  • 25. Unit Tests One Assert or Single Concept per Test F.I.R.S.T. Fast Independent Repeatable (in any environment) Self-Validation Timly Tuesday, March 10, 2009
  • 26. Thanks - Any Questions? Tuesday, March 10, 2009
  • 27. Sources Book „Clean Code“ by Robert C. Martin ISBN: 0132350882 Images http://www.failblog.org http://www.flickr.com/photos/hugovk/199425487/ http://www.flickr.com/photos/jackpot321/1809424991/ http://www.osnews.com/story/19266/WTFs_m Tuesday, March 10, 2009

Hinweis der Redaktion