SlideShare a Scribd company logo
1 of 48
Download to read offline
Coding standards
McGill ECSE 321
Introduction to Software Engineering
Radu Negulescu
Fall 2003
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 2
About this module
Coding and documentation standards
ā€¢ Important for team communication
ā€¢ Essential for component-based development
E.g. Java Beans
Customs eventually become law...
ā€¢ Introduce many of the general principles software engineering
Bridge the gap between programming and software engineering
Contents
ā€¢ Code conventions: layout, naming, comments, etc.
Focus on reasons and principles!
ā€¢ Component standards
Java Beans essentials
ā€¢ Technical documentation
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 3
Why use code conventions?
Danger! Religious wars!
ā€¢ Some programmers would rather quit than put a curly bracket in a
different place. Then, why bother them with coding conventions?
ā€¢ Not for aesthetics!
ā€¢ Team integration
Needs of code readers (reviewers and maintainers) are at least as important
as the needs of the code writers!
Developers, testers often communicate by code
No such thing as ā€œbest conventionsā€
More important to follow some consistent conventions
Focus on reasons behind, link to organizational objectives
ā€¢ Source code may need to be released with the product
ā€¢ Part of certain development processes
ā€œIf you are going to have all these programmers (ā€¦) refactoring each otherā€™s
code constantly, you simply cannot afford to have different sets of coding
practices.ā€ [Kent Beck, ā€œExtreme Programming Explainedā€]
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 4
Why use code conventions?
Support the following activities on the code:
ā€¢ Reading and understanding
Explain the intent
Help decypher the meaning and behavior
ā€¢ Retrieving quickly a desired part of the code
ā€¢ Maintaining the code
ā€¢ Preparing for reuse
Porting to multiple contexts
Use in unforeseen contexts
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 5
Code layout
How to achieve good code layout?
ā€¢ ā€œFundamental principleā€: highlight logical structure of the code
ā€¢ Proximity: keep related things close together
ā€¢ Maintainability: facilitate editing
ā€¢ Consistency
ā€¢ Compactness
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 6
Fundamental principle of code layout
Layout should highlight the logical structure of the code!
ā€¢ Resemble the structure of chapters and sections in a book
ā€¢ Example of bad layout (why is it bad?):
IRU L  L  Q L
IRU L  L  Q L
IRU L  L  Q L
IRU L  L  Q L
DL@ WHPSDL@ WHPSDL@ WHPSDL@ WHPS
WHPSWHPSWHPSWHPS
ā€¢ Avoid embellishments!
Embellishments distract attention from logical structure
ā€¢ Align elements that belong together
E.g. indent block statements by the same amount
ā€¢ Parentheses: use more of them
LI D E F G
EDGLI D E F G
EDGLI D E F G
EDGLI D E F G
EDG
LI D E
F G
JRRGLI D E
F G
JRRGLI D E
F G
JRRGLI D E
F G
JRRG
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 7
Proximity
Group things that are related
ā€¢ Keep comments close to what they describe (weā€™ll discuss later)
ā€¢ Group related statements
E.g. [after McC.]:
ZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQV HGLW:LQGRZHGLW:LQGRZHGLW:LQGRZHGLW:LQGRZGLPHQVLRQVGLPHQVLRQVGLPHQVLRQVGLPHQVLRQV
ZLQGRZWLWOHZLQGRZWLWOHZLQGRZWLWOHZLQGRZWLWOH HGLW:LQGRZHGLW:LQGRZHGLW:LQGRZHGLW:LQGRZWLWOHWLWOHWLWOHWLWOH
FXUVRUVWDUWFXUVRUVWDUWFXUVRUVWDUWFXUVRUVWDUW VWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQH
FXUVRUHQGFXUVRUHQGFXUVRUHQGFXUVRUHQG HQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQH
FXUVRUFXUVRUFXUVRUFXUVRUEOLQN5DWHEOLQN5DWHEOLQN5DWHEOLQN5DWH HGLW0RGHHGLW0RGHHGLW0RGHHGLW0RGHEOLQN5DWHEOLQN5DWHEOLQN5DWHEOLQN5DWH
Separate things that are unrelated
ā€¢ Insert a blank line before a paragraph
ā€¢ Use one file per program module (enforced in Java)
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 8
Maintainability
Make it easy to cut and paste related text
ā€¢ E.g. use ā€œnew styleā€ C function parameters:
VWUFSVWUFSVWUFSVWUFS 
FKDU 
W 
 GHVWLQDWLRQ VWULQJ 
FKDU 
W 
 GHVWLQDWLRQ VWULQJ 
FKDU 
W 
 GHVWLQDWLRQ VWULQJ 
FKDU 
W 
 GHVWLQDWLRQ VWULQJ 

FKDU 
V 
 VRXUFH VWULQJ 
FKDU 
V 
 VRXUFH VWULQJ 
FKDU 
V 
 VRXUFH VWULQJ 
FKDU 
V 
 VRXUFH VWULQJ
^
^
^
^

VWUFSVWUFSVWUFSVWUFS W V
W V
W V
W V
FKDU 
W 
V 
FKDU 
W 
V 
FKDU 
W 
V 
FKDU 
W 
V 
 GHVWGHVWGHVWGHVW VWULQJ VRXUFH VWULQJ 
 VWULQJ VRXUFH VWULQJ 
 VWULQJ VRXUFH VWULQJ 
 VWULQJ VRXUFH VWULQJ 

^^^^

Make it hard to move unrelated text
ā€¢ Use one statement per line
ā€¢ ā€œNew styleā€ C routine declarations also help here
Make it hard to edit things by mistake
ā€¢ Class and method Javadoc comments
ā€¢ File headers
ā€œNew styleā€
parameters
ā€œOld styleā€
parameters
McGill University ECSE 321 Ā© 2003 Radu Negulescu
Introduction to Software Engineering Coding standardsā€”Slide 9
Consistency
Avoid exceptions from usual layout conventions
ā€¢ E.g. braces around a single-statement block reduce the chance of
error in case you need to add more statements to the block
LI FRQGLWLRQ
^LI FRQGLWLRQ
^LI FRQGLWLRQ
^LI FRQGLWLRQ
^
VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW
VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW
VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW
````
LI FRQGLWLRQ
^LI FRQGLWLRQ
^LI FRQGLWLRQ
^LI FRQGLWLRQ
^
VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW
````
LI FRQGLWLRQ
LI FRQGLWLRQ
LI FRQGLWLRQ
LI FRQGLWLRQ

More Related Content

Similar to Intro to Software Engineering - Coding Standards

Intro to Software Engineering - Module Design
Intro to Software Engineering - Module DesignIntro to Software Engineering - Module Design
Intro to Software Engineering - Module Design
Radu_Negulescu
Ā 
Intro to Software Engineering - Life Cycle Models
Intro to Software Engineering - Life Cycle ModelsIntro to Software Engineering - Life Cycle Models
Intro to Software Engineering - Life Cycle Models
Radu_Negulescu
Ā 

Similar to Intro to Software Engineering - Coding Standards (20)

Intro to Software Engineering - Module Design
Intro to Software Engineering - Module DesignIntro to Software Engineering - Module Design
Intro to Software Engineering - Module Design
Ā 
Coding conventions
Coding conventionsCoding conventions
Coding conventions
Ā 
Jooq java object oriented querying
Jooq java object oriented queryingJooq java object oriented querying
Jooq java object oriented querying
Ā 
Intro to Software Engineering - Life Cycle Models
Intro to Software Engineering - Life Cycle ModelsIntro to Software Engineering - Life Cycle Models
Intro to Software Engineering - Life Cycle Models
Ā 
RVCE-Bengaluru-Internship_PPT format.pptx
RVCE-Bengaluru-Internship_PPT format.pptxRVCE-Bengaluru-Internship_PPT format.pptx
RVCE-Bengaluru-Internship_PPT format.pptx
Ā 
Practical Design Patterns for Building Applications Resilient to Infrastructu...
Practical Design Patterns for Building Applications Resilient to Infrastructu...Practical Design Patterns for Building Applications Resilient to Infrastructu...
Practical Design Patterns for Building Applications Resilient to Infrastructu...
Ā 
Fugue: Unifying Spark and Non-Spark Ecosystems for Big Data Analytics
Fugue: Unifying Spark and Non-Spark Ecosystems for Big Data AnalyticsFugue: Unifying Spark and Non-Spark Ecosystems for Big Data Analytics
Fugue: Unifying Spark and Non-Spark Ecosystems for Big Data Analytics
Ā 
Containers: Don't Skeu Them Up (LinuxCon Dublin)
Containers: Don't Skeu Them Up (LinuxCon Dublin)Containers: Don't Skeu Them Up (LinuxCon Dublin)
Containers: Don't Skeu Them Up (LinuxCon Dublin)
Ā 
Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)Illustrated Code (ASE 2021)
Illustrated Code (ASE 2021)
Ā 
Tools and Methods for Continuously Expanding Software Applications
Tools and Methods for Continuously Expanding Software ApplicationsTools and Methods for Continuously Expanding Software Applications
Tools and Methods for Continuously Expanding Software Applications
Ā 
Kutulu: A Domain-specific Language for Feature-driven Product Derivation
Kutulu: A Domain-specific Language for Feature-driven Product DerivationKutulu: A Domain-specific Language for Feature-driven Product Derivation
Kutulu: A Domain-specific Language for Feature-driven Product Derivation
Ā 
Distributed Development, Centralised Delivery - SAGrid Jenkins + CVMFS
Distributed Development, Centralised Delivery - SAGrid Jenkins + CVMFSDistributed Development, Centralised Delivery - SAGrid Jenkins + CVMFS
Distributed Development, Centralised Delivery - SAGrid Jenkins + CVMFS
Ā 
IDEA StatiCa Seel Connections - seminar Genk/Kortrijk nov 2016
IDEA StatiCa Seel Connections - seminar Genk/Kortrijk nov 2016IDEA StatiCa Seel Connections - seminar Genk/Kortrijk nov 2016
IDEA StatiCa Seel Connections - seminar Genk/Kortrijk nov 2016
Ā 
GTU PHP Project Training Guidelines
GTU PHP Project Training GuidelinesGTU PHP Project Training Guidelines
GTU PHP Project Training Guidelines
Ā 
Clean Infrastructure as Code
Clean Infrastructure as CodeClean Infrastructure as Code
Clean Infrastructure as Code
Ā 
Lec1 final
Lec1 finalLec1 final
Lec1 final
Ā 
Presenter manual oracle D2K (specially for summer interns)
Presenter manual oracle D2K (specially for summer interns)Presenter manual oracle D2K (specially for summer interns)
Presenter manual oracle D2K (specially for summer interns)
Ā 
Android architecture
Android architectureAndroid architecture
Android architecture
Ā 
An Introduction To Model ļ‚· View ļ‚· Controller In XPages
An Introduction To Model ļ‚· View ļ‚· Controller In XPagesAn Introduction To Model ļ‚· View ļ‚· Controller In XPages
An Introduction To Model ļ‚· View ļ‚· Controller In XPages
Ā 
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Faking a Grid - Franco Alvarado (Macmillan Learning), Betsy Granger (Macmilla...
Ā 

More from Radu_Negulescu

Intro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality AssuranceIntro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality Assurance
Radu_Negulescu
Ā 
Final Exam Solutions Fall02
Final Exam Solutions Fall02Final Exam Solutions Fall02
Final Exam Solutions Fall02
Radu_Negulescu
Ā 
Final Exam Questions Fall03
Final Exam Questions Fall03Final Exam Questions Fall03
Final Exam Questions Fall03
Radu_Negulescu
Ā 
Midterm Exam Solutions Fall03
Midterm Exam Solutions Fall03Midterm Exam Solutions Fall03
Midterm Exam Solutions Fall03
Radu_Negulescu
Ā 
Midterm Exam Solutions Fall02
Midterm Exam Solutions Fall02Midterm Exam Solutions Fall02
Midterm Exam Solutions Fall02
Radu_Negulescu
Ā 
Intro to Software Engineering - Software Testing
Intro to Software Engineering - Software TestingIntro to Software Engineering - Software Testing
Intro to Software Engineering - Software Testing
Radu_Negulescu
Ā 
Intro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality AssuranceIntro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality Assurance
Radu_Negulescu
Ā 
Intro to Software Engineering - Requirements Analysis
Intro to Software Engineering - Requirements AnalysisIntro to Software Engineering - Requirements Analysis
Intro to Software Engineering - Requirements Analysis
Radu_Negulescu
Ā 
Software Engineering Practice - Software Quality Management
Software Engineering Practice - Software Quality ManagementSoftware Engineering Practice - Software Quality Management
Software Engineering Practice - Software Quality Management
Radu_Negulescu
Ā 
Software Engineering Practice - Software Metrics and Estimation
Software Engineering Practice - Software Metrics and EstimationSoftware Engineering Practice - Software Metrics and Estimation
Software Engineering Practice - Software Metrics and Estimation
Radu_Negulescu
Ā 
Software Engineering Practice - Software Business Basics
Software Engineering Practice - Software Business BasicsSoftware Engineering Practice - Software Business Basics
Software Engineering Practice - Software Business Basics
Radu_Negulescu
Ā 
Software Engineering Practice - Project management
Software Engineering Practice - Project managementSoftware Engineering Practice - Project management
Software Engineering Practice - Project management
Radu_Negulescu
Ā 
Software Engineering Practice - Configuration management
Software Engineering Practice - Configuration managementSoftware Engineering Practice - Configuration management
Software Engineering Practice - Configuration management
Radu_Negulescu
Ā 
Software Engineering Practice - Advanced Development Methodologies
Software Engineering Practice - Advanced Development MethodologiesSoftware Engineering Practice - Advanced Development Methodologies
Software Engineering Practice - Advanced Development Methodologies
Radu_Negulescu
Ā 

More from Radu_Negulescu (14)

Intro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality AssuranceIntro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality Assurance
Ā 
Final Exam Solutions Fall02
Final Exam Solutions Fall02Final Exam Solutions Fall02
Final Exam Solutions Fall02
Ā 
Final Exam Questions Fall03
Final Exam Questions Fall03Final Exam Questions Fall03
Final Exam Questions Fall03
Ā 
Midterm Exam Solutions Fall03
Midterm Exam Solutions Fall03Midterm Exam Solutions Fall03
Midterm Exam Solutions Fall03
Ā 
Midterm Exam Solutions Fall02
Midterm Exam Solutions Fall02Midterm Exam Solutions Fall02
Midterm Exam Solutions Fall02
Ā 
Intro to Software Engineering - Software Testing
Intro to Software Engineering - Software TestingIntro to Software Engineering - Software Testing
Intro to Software Engineering - Software Testing
Ā 
Intro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality AssuranceIntro to Software Engineering - Software Quality Assurance
Intro to Software Engineering - Software Quality Assurance
Ā 
Intro to Software Engineering - Requirements Analysis
Intro to Software Engineering - Requirements AnalysisIntro to Software Engineering - Requirements Analysis
Intro to Software Engineering - Requirements Analysis
Ā 
Software Engineering Practice - Software Quality Management
Software Engineering Practice - Software Quality ManagementSoftware Engineering Practice - Software Quality Management
Software Engineering Practice - Software Quality Management
Ā 
Software Engineering Practice - Software Metrics and Estimation
Software Engineering Practice - Software Metrics and EstimationSoftware Engineering Practice - Software Metrics and Estimation
Software Engineering Practice - Software Metrics and Estimation
Ā 
Software Engineering Practice - Software Business Basics
Software Engineering Practice - Software Business BasicsSoftware Engineering Practice - Software Business Basics
Software Engineering Practice - Software Business Basics
Ā 
Software Engineering Practice - Project management
Software Engineering Practice - Project managementSoftware Engineering Practice - Project management
Software Engineering Practice - Project management
Ā 
Software Engineering Practice - Configuration management
Software Engineering Practice - Configuration managementSoftware Engineering Practice - Configuration management
Software Engineering Practice - Configuration management
Ā 
Software Engineering Practice - Advanced Development Methodologies
Software Engineering Practice - Advanced Development MethodologiesSoftware Engineering Practice - Advanced Development Methodologies
Software Engineering Practice - Advanced Development Methodologies
Ā 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
Ā 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
Ā 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
Ā 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
Ā 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
Ā 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Ā 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
Ā 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Ā 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Ā 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
Ā 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Ā 
šŸ¬ The future of MySQL is Postgres šŸ˜
šŸ¬  The future of MySQL is Postgres   šŸ˜šŸ¬  The future of MySQL is Postgres   šŸ˜
šŸ¬ The future of MySQL is Postgres šŸ˜
Ā 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Ā 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
Ā 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
Ā 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
Ā 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
Ā 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
Ā 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Ā 

Intro to Software Engineering - Coding Standards

  • 1. Coding standards McGill ECSE 321 Introduction to Software Engineering Radu Negulescu Fall 2003
  • 2. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 2 About this module Coding and documentation standards ā€¢ Important for team communication ā€¢ Essential for component-based development E.g. Java Beans Customs eventually become law... ā€¢ Introduce many of the general principles software engineering Bridge the gap between programming and software engineering Contents ā€¢ Code conventions: layout, naming, comments, etc. Focus on reasons and principles! ā€¢ Component standards Java Beans essentials ā€¢ Technical documentation
  • 3. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 3 Why use code conventions? Danger! Religious wars! ā€¢ Some programmers would rather quit than put a curly bracket in a different place. Then, why bother them with coding conventions? ā€¢ Not for aesthetics! ā€¢ Team integration Needs of code readers (reviewers and maintainers) are at least as important as the needs of the code writers! Developers, testers often communicate by code No such thing as ā€œbest conventionsā€ More important to follow some consistent conventions Focus on reasons behind, link to organizational objectives ā€¢ Source code may need to be released with the product ā€¢ Part of certain development processes ā€œIf you are going to have all these programmers (ā€¦) refactoring each otherā€™s code constantly, you simply cannot afford to have different sets of coding practices.ā€ [Kent Beck, ā€œExtreme Programming Explainedā€]
  • 4. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 4 Why use code conventions? Support the following activities on the code: ā€¢ Reading and understanding Explain the intent Help decypher the meaning and behavior ā€¢ Retrieving quickly a desired part of the code ā€¢ Maintaining the code ā€¢ Preparing for reuse Porting to multiple contexts Use in unforeseen contexts
  • 5. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 5 Code layout How to achieve good code layout? ā€¢ ā€œFundamental principleā€: highlight logical structure of the code ā€¢ Proximity: keep related things close together ā€¢ Maintainability: facilitate editing ā€¢ Consistency ā€¢ Compactness
  • 6. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 6 Fundamental principle of code layout Layout should highlight the logical structure of the code! ā€¢ Resemble the structure of chapters and sections in a book ā€¢ Example of bad layout (why is it bad?): IRU L L Q L
  • 7. IRU L L Q L
  • 8. IRU L L Q L
  • 9. IRU L L Q L
  • 10. DL@ WHPSDL@ WHPSDL@ WHPSDL@ WHPS WHPSWHPSWHPSWHPS ā€¢ Avoid embellishments! Embellishments distract attention from logical structure ā€¢ Align elements that belong together E.g. indent block statements by the same amount ā€¢ Parentheses: use more of them LI D E F G
  • 11. EDGLI D E F G
  • 12. EDGLI D E F G
  • 13. EDGLI D E F G
  • 15. F G
  • 16.
  • 18. F G
  • 19.
  • 21. F G
  • 22.
  • 24. F G
  • 25.
  • 26. JRRG
  • 27. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 7 Proximity Group things that are related ā€¢ Keep comments close to what they describe (weā€™ll discuss later) ā€¢ Group related statements E.g. [after McC.]: ZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQV HGLW:LQGRZHGLW:LQGRZHGLW:LQGRZHGLW:LQGRZGLPHQVLRQVGLPHQVLRQVGLPHQVLRQVGLPHQVLRQV ZLQGRZWLWOHZLQGRZWLWOHZLQGRZWLWOHZLQGRZWLWOH HGLW:LQGRZHGLW:LQGRZHGLW:LQGRZHGLW:LQGRZWLWOHWLWOHWLWOHWLWOH FXUVRUVWDUWFXUVRUVWDUWFXUVRUVWDUWFXUVRUVWDUW VWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQH FXUVRUHQGFXUVRUHQGFXUVRUHQGFXUVRUHQG HQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQH FXUVRUFXUVRUFXUVRUFXUVRUEOLQN5DWHEOLQN5DWHEOLQN5DWHEOLQN5DWH HGLW0RGHHGLW0RGHHGLW0RGHHGLW0RGHEOLQN5DWHEOLQN5DWHEOLQN5DWHEOLQN5DWH Separate things that are unrelated ā€¢ Insert a blank line before a paragraph ā€¢ Use one file per program module (enforced in Java)
  • 28. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 8 Maintainability Make it easy to cut and paste related text ā€¢ E.g. use ā€œnew styleā€ C function parameters: VWUFSVWUFSVWUFSVWUFS FKDU W GHVWLQDWLRQ VWULQJ FKDU W GHVWLQDWLRQ VWULQJ FKDU W GHVWLQDWLRQ VWULQJ FKDU W GHVWLQDWLRQ VWULQJ FKDU V VRXUFH VWULQJ FKDU V VRXUFH VWULQJ FKDU V VRXUFH VWULQJ FKDU V VRXUFH VWULQJ
  • 29. ^
  • 30. ^
  • 31. ^
  • 33. W V
  • 34. W V
  • 35. W V
  • 36. FKDU W V FKDU W V FKDU W V FKDU W V GHVWGHVWGHVWGHVW VWULQJ VRXUFH VWULQJ VWULQJ VRXUFH VWULQJ VWULQJ VRXUFH VWULQJ VWULQJ VRXUFH VWULQJ ^^^^ Make it hard to move unrelated text ā€¢ Use one statement per line ā€¢ ā€œNew styleā€ C routine declarations also help here Make it hard to edit things by mistake ā€¢ Class and method Javadoc comments ā€¢ File headers ā€œNew styleā€ parameters ā€œOld styleā€ parameters
  • 37. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 9 Consistency Avoid exceptions from usual layout conventions ā€¢ E.g. braces around a single-statement block reduce the chance of error in case you need to add more statements to the block LI FRQGLWLRQ
  • 49. VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW Multi-statement block Layout similar to multi-statement blocks Exception from usual layout convention for multi-statement blocks
  • 50. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 10 Compactness Optimal amount of blank lines: 8-16% Optimal amount of indentation: 2-4 spaces ā€¢ OR, a tab (but not both tab and spaces!) Avoid redundancy ā€¢ New style vs. old style C function prototypes VWUFSVWUFSVWUFSVWUFS W V
  • 51. W V
  • 52. W V
  • 53. W V
  • 54. FKDU W V FKDU W V FKDU W V FKDU W V GHVWGHVWGHVWGHVW VWULQJ VRXUFH VWULQJ VWULQJ VRXUFH VWULQJ VWULQJ VRXUFH VWULQJ VWULQJ VRXUFH VWULQJ ^^^^
  • 55. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 11 Other layout conventions Continuation lines ā€¢ Indent continuation lines by a larger amount ā€¢ Break after a comma or before an operator ā€¢ In the case of multi-line comments, break at the end of a complete phrase Follows from principles?
  • 56. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 12 Selecting a layout (Adapted from [McC.]) ā€¢ Compact block layout: LI LI LI LI SL[HORORUSL[HORORUSL[HORORUSL[HORORU UHGRORUUHGRORUUHGRORUUHGRORU
  • 57. ^
  • 58. ^
  • 59. ^
  • 60. ^ VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW ```` ā€¢ More lines, some separation: LI LI LI LI SL[HORORUSL[HORORUSL[HORORUSL[HORORU UHGRORUUHGRORUUHGRORUUHGRORU
  • 61.
  • 62.
  • 63.
  • 64. ^^^^ VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW ```` ā€¢ More lines, more indenting levels: LI LI LI LI SL[HORORUSL[HORORUSL[HORORUSL[HORORU UHGRORUUHGRORUUHGRORUUHGRORU
  • 65.
  • 66.
  • 67.
  • 68. ^^^^ VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW VWDWHPHQWVWDWHPHQWVWDWHPHQWVWDWHPHQW ```` ā€¢ More lines, misleading alignment: LI LI LI LI SL[HORORUSL[HORORUSL[HORORUSL[HORORU UHGRORUUHGRORUUHGRORUUHGRORU
  • 69.
  • 70.
  • 71.
  • 73. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 13 Selecting a layout Endline layout vs. block layout ā€¢ Endline layout is bad most of the time E.g. LI LI LI LI VROGQWVROGQWVROGQWVROGQW ! DQG VDOHV !
  • 74. ! DQG VDOHV !
  • 75. ! DQG VDOHV !
  • 76. ! DQG VDOHV !
  • 77. LI LI LI LI VROGQWVROGQWVROGQWVROGQW ! DQG VDOHV !
  • 78. ! DQG VDOHV !
  • 79. ! DQG VDOHV !
  • 80. ! DQG VDOHV !
  • 81. LI LI LI LI VROGQWVROGQWVROGQWVROGQW !
  • 85. PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ HOVH PDUNGRZQ Pro: scraps a few lines Cons: poor maintainability (modifications move more code than they should); inconsistency (not sustainable for larger structures); non-uniformity ā€¢ Endline layout is good for certain comments tied to the line E.g. a comment that indicates the role of a declared variable FKDU V VRXUFH VWULQJFKDU V VRXUFH VWULQJFKDU V VRXUFH VWULQJFKDU V VRXUFH VWULQJ
  • 86. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 14 Selecting a layout What is good or bad about the following layouts: IRU L L Q L
  • 87. ^IRU L L Q L
  • 88. ^IRU L L Q L
  • 89. ^IRU L L Q L
  • 90. ^ IRU M M Q M
  • 91. ^IRU M M Q M
  • 92. ^IRU M M Q M
  • 93. ^IRU M M Q M
  • 94. ^ GR VRPHWKLQJ GR VRPHWKLQJ GR VRPHWKLQJ GR VRPHWKLQJ ` `` `` `` ` IRU L L Q L
  • 95. ^IRU L L Q L
  • 96. ^IRU L L Q L
  • 97. ^IRU L L Q L
  • 98. ^ IRU M M Q M
  • 99. ^IRU M M Q M
  • 100. ^IRU M M Q M
  • 101. ^IRU M M Q M
  • 102. ^ GR VRPHWKLQJ GR VRPHWKLQJ GR VRPHWKLQJ GR VRPHWKLQJ ```` ````
  • 103. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 15 Naming ā€œIn well-written code, comments are the icing on the readability cake.ā€ [McC.,p.456] How to choose an identifier? ā€¢ Adequacy ā€¢ Problem-orientation ā€¢ Readability ā€¢ Compactness ā€¢ Follow expectations ā€¢ Follow conventions
  • 104. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 16 Adequacy Accurately and completely describe the named item ā€¢ Variable, class, method, etc. E.g., a variable that represents the current date ā€¢ Good names: CurrentDate, CrntDate ā€¢ Bad names: CD, Current, C, X, X1, Date, PreDate OK to use single-character names for ā€œthrow-awayā€ local variables ā€¢ Loop counters and limits ā€¢ Unused exceptions ā€¢ Unused events Too cryptic Incomplete Cryptic AND incomplete Inaccurate Incomplete
  • 105. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 17 Problem-orientation The identifier should tell what the item does, not how it is implemented ā€¢ E.g. BookTitle rather than LongString ā€¢ Other examples?
  • 106. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 18 Compactness Where possible, keep it short ā€¢ Single-character names for local throw-away variables ā€¢ Avoid cryptic ā€œlicense-plateā€ acronyms (trmn8) Take time to read Look garbled ā€¢ A long name may indicate poor modularity getEmployeeSalaryAndBenefitsPolicyAndSetNewValuesDependingOnFlag(...) split into getEmployeeSalary(...), getEmployeeBenefits(...), setEmployeeSalary(...), setEmployeeBenefits(...), checkFlag(...), ... ā€¢ Method names tend to be longer than variable names For completeness reasons
  • 107. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 19 Follow expectations Principle of ā€œminimal surpriseā€ ā€¢ Use similar names for related things, opposite pairs, etc. Good: upperRight, lowerLeft Bad: UR, downcorner ā€¢ Think of the contexts of usage of a label 7UHH6HW7UHH6HW7UHH6HW7UHH6HW IUDFWDO QHZIUDFWDO QHZIUDFWDO QHZIUDFWDO QHZ 7UHH6HW7UHH6HW7UHH6HW7UHH6HW
  • 108. LI IUDFWDOLI IUDFWDOLI IUDFWDOLI IUDFWDOKDV'UDZ,QIRKDV'UDZ,QIRKDV'UDZ,QIRKDV'UDZ,QIR
  • 109.
  • 110. ^
  • 111.
  • 112. ^
  • 113.
  • 114. ^
  • 115.
  • 120. ```` Boolean return type used in condition label ā€œhasā€¦ā€ reads well after ā€œifā€ and noun ā€œTreeSetā€ reads well -before noun -after ā€œnewā€
  • 121. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 20 Follow conventions Classes, interfaces, types: ā€¢ Nouns ā€¢ Umbrella-label for all the elements (objects) of the class ā€œWheel3DEventā€, ā€œWindowā€, ā€œArrayOutOfBoundsExceptionā€, ā€œObjectā€ ā€¢ Mixed case, starting with a capital Methods, functions: ā€¢ Verbs: drawPicture, addElement, isInitialized ā€¢ Mixed case, starting with a lower case Constants: ā€¢ Upper case File names: ā€¢ README for directory content description; GNUmakefile or Makefile for conditional compilation files See Java conventions document
  • 122. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 21 Comments Are comments helpful? ā€¢ See play ā€œThe Commentoā€ [Handout - McC., pp.458-461] How to achieve good commenting? ā€¢ Relevance ā€¢ Maintainability ā€¢ Document surprises ā€¢ Hierarchy
  • 123. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 22 Relevance Use comments sparingly! ā€¢ Comments introduce redundancy maintenance overhead! ā€¢ Know which types of comments are worth including ā€¢ Keep each comment succint! ā€¢ Avoid comments that simply repeat the code E.g. [adapted from McC.] VHW SURGXFW WR EDVH VHW SURGXFW WR EDVH VHW SURGXFW WR EDVH VHW SURGXFW WR EDVH SURGXFW EDVHSURGXFW EDVHSURGXFW EDVHSURGXFW EDVH ORRS IURP WR QXP ORRS IURP WR QXP ORRS IURP WR QXP ORRS IURP WR QXP IRU L L QXP L
  • 124. ^IRU L L QXP L
  • 125. ^IRU L L QXP L
  • 126. ^IRU L L QXP L
  • 127. ^ SURGXFW SURGXFW EDVHSURGXFW SURGXFW EDVHSURGXFW SURGXFW EDVHSURGXFW SURGXFW EDVH ```` Redundant comment. Hard to maintain if num is changed to num-1
  • 128. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 23 Maintainability Comments need to be maintained just like the rest of the code ā€¢ Make comments easy to edit ā€¢ Except where they are not supposed to change Principle of proximity: keep comments close to the code they describe ā€¢ Avoid endline in general ā€¢ Use endline where tied to the line Data declarations, maintenance notes Include maintenance notes (date of revision, author, etc) ā€¢ Developerā€™s markers (ā€œto fix laterā€ flag)
  • 129. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 24 Other commenting practices Document surprises Distinguish major comments ā€¢ Underline, overline, use ellipses ā€¢ Hierarchy of subtitles
  • 130. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 25 Useful comments Subtitles (PDL) Assertions (pre-conditions, post-conditions, invariants) Data comments Maintenance notes (file headers, to-do, change log) Tags ā€¢ Documentation (e.g. Javadoc tags) ā€¢ Instrumentation (e.g. iContract tags)
  • 131. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 26 Subtitle comments Say what the code does, rather than how ā€¢ Give a higher level of abstraction than the code ā€¢ Use pseudocode (PDL) lines as subtitle-type comments E.g. 6HW ZLQGRZ SDUDPHWHUV 6HW ZLQGRZ SDUDPHWHUV 6HW ZLQGRZ SDUDPHWHUV 6HW ZLQGRZ SDUDPHWHUV ZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQVZLQGRZGLPHQVLRQV HGLW:LQGRZHGLW:LQGRZHGLW:LQGRZHGLW:LQGRZGLPHQVLRQVGLPHQVLRQVGLPHQVLRQVGLPHQVLRQV ZLQGRZWLWOHZLQGRZWLWOHZLQGRZWLWOHZLQGRZWLWOH HGLW:LQGRZHGLW:LQGRZHGLW:LQGRZHGLW:LQGRZWLWOHWLWOHWLWOHWLWOH 6HW FXUVRU SDUDPHWHUV 6HW FXUVRU SDUDPHWHUV 6HW FXUVRU SDUDPHWHUV 6HW FXUVRU SDUDPHWHUV FXUVRUVWDUWFXUVRUVWDUWFXUVRUVWDUWFXUVRUVWDUW VWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQHVWDUWLQJ6FDQ/LQH FXUVRUHQGFXUVRUHQGFXUVRUHQGFXUVRUHQG HQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQHHQGLQJ6FDQ/LQH FXUVRUFXUVRUFXUVRUFXUVRUEOLQN5DWHEOLQN5DWHEOLQN5DWHEOLQN5DWH HGLW0RGHHGLW0RGHHGLW0RGHHGLW0RGHEOLQN5DWHEOLQN5DWHEOLQN5DWHEOLQN5DWH ā€¢ Annotate data declarations: role, data invariants E.g. ā€œarray a contains distinct values onlyā€ Or, equivalently, ā€œforall i, j: a[i] != a[j]ā€
  • 132. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 27 Assertion comments Pre-conditions, post-conditions, invariants ā€¢ E.g. after [BD, p.239] +DVKWDEOH+DVKWDEOH+DVKWDEOH+DVKWDEOH FODVV 0DLQWDLQV PDSSLQJV IURP XQLTXH NHV WR DUELWUDU REMHFWVFODVV 0DLQWDLQV PDSSLQJV IURP XQLTXH NHV WR DUELWUDU REMHFWVFODVV 0DLQWDLQV PDSSLQJV IURP XQLTXH NHV WR DUELWUDU REMHFWVFODVV 0DLQWDLQV PDSSLQJV IURP XQLTXH NHV WR DUELWUDU REMHFWV FODVVFODVVFODVVFODVV +DVKWDEOH+DVKWDEOH+DVKWDEOH+DVKWDEOH ^^^^ 7KH QXPEHU RI HOHPHQWV LQ 7KH QXPEHU RI HOHPHQWV LQ 7KH QXPEHU RI HOHPHQWV LQ 7KH QXPEHU RI HOHPHQWV LQ +DVKWDEOH+DVKWDEOH+DVKWDEOH+DVKWDEOH LV DOZDV QRQLV DOZDV QRQLV DOZDV QRQLV DOZDV QRQQHJDWLYHQHJDWLYHQHJDWLYHQHJDWLYH SULYDWHSULYDWHSULYDWHSULYDWH LQWLQWLQWLQW QXP(OHPHQWVQXP(OHPHQWVQXP(OHPHQWVQXP(OHPHQWV 7KH SXW RSHUDWLRQ 7KH SXW RSHUDWLRQ 7KH SXW RSHUDWLRQ 7KH SXW RSHUDWLRQ DVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVHGDVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVHGDVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVHGDVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVHG $IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHG$IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHG$IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHG$IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHGWKH VSHFLILHG NH FDQ EH XVHGWKH VSHFLILHG NH FDQ EH XVHGWKH VSHFLILHG NH FDQ EH XVHGWKH VSHFLILHG NH FDQ EH XVHG WR WR WR WR UHFRYHU WKH HQWUUHFRYHU WKH HQWUUHFRYHU WKH HQWUUHFRYHU WKH HQWU ZLWK WKH JHWNH
  • 136. RSHUDWLRQ SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 137. ^SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 138. ^SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 139. ^SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 140. ^
  • 141. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 28 Data comments Role (meaning) of data fields and specific invariants ā€¢ At declaration For consistency ā€¢ Endline layout recommended here SURWHFWHG 3RLQWSURWHFWHG 3RLQWSURWHFWHG 3RLQWSURWHFWHG 3RLQW OOOOOOOO ORZHU OHIW FRUQHUORZHU OHIW FRUQHUORZHU OHIW FRUQHUORZHU OHIW FRUQHU [ ! [ ! [ ! [ ! SURWHFWHGSURWHFWHGSURWHFWHGSURWHFWHG LQWLQWLQWLQW ZLGWKZLGWKZLGWKZLGWK ! ! ! ! SURWHFWHGSURWHFWHGSURWHFWHGSURWHFWHG LQWLQWLQWLQW KHLJKWKHLJKWKHLJKWKHLJKW ! ! ! ! Meaning Invariant Meaning is self-documented
  • 142. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 29 Maintenance notes File headers ā€¢ Title, author, creation date ā€¢ Change log ā€¢ IP rights notice 0XOWLRUQHU%R[%HDQ0XOWLRUQHU%R[%HDQ0XOWLRUQHU%R[%HDQ0XOWLRUQHU%R[%HDQMDYDMDYDMDYDMDYD UHDWHG RQ 6HSWHPEHU $0 UHDWHG RQ 6HSWHPEHU $0 UHDWHG RQ 6HSWHPEHU $0 UHDWHG RQ 6HSWHPEHU $0 KDQJHV KDQJHV KDQJHV KDQJHV 51 6HSW DGG 51 6HSW DGG 51 6HSW DGG 51 6HSW DGG XUXUXUXU XSSHU5LJKWXSSHU5LJKWXSSHU5LJKWXSSHU5LJKW
  • 146. SURSHUW 51 6HSW DGG 51 6HSW DGG 51 6HSW DGG 51 6HSW DGG XOXOXOXO OUOUOUOU SURSHUWLHVSURSHUWLHVSURSHUWLHVSURSHUWLHV RSULJKW
  • 150. 5DGX 1HJXOHVFX5DGX 1HJXOHVFX5DGX 1HJXOHVFX5DGX 1HJXOHVFX To-do notes SULYDWHSULYDWHSULYDWHSULYDWH LQWLQWLQWLQW P,QWP,QWP,QWP,QW 7%' FKDQJH WR ORQJ LQ UHOHDVH 7%' FKDQJH WR ORQJ LQ UHOHDVH 7%' FKDQJH WR ORQJ LQ UHOHDVH 7%' FKDQJH WR ORQJ LQ UHOHDVH
  • 151. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 30 Documentation Tags Generate documentation from in-line comments ā€¢ Avoid redundancy Javadoc ā€¢ Java documentation comments /** ā€¦ */ As opposed to ā€œimplementationā€ comments /* ā€¦ */ and // Use // for unused code lines ā€¢ Can be converted to HTML by javadoc ā€¢ Used to describe classes, interfaces, vars, methods ā€¢ Placed just before the item commented ā€¢ Include special tags (@return, @param, @author, ā€¦) See Sun site for a list of tags and usage
  • 152. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 31 Instrumentation tags Generate code from in-line comments ā€¢ Avoids redundancy ā€¢ Use special language to specify instrumented code E.g. OCL assertions [BD, p.239] 7KH QXPEHU RI HOHPHQWV LQ 7KH QXPEHU RI HOHPHQWV LQ 7KH QXPEHU RI HOHPHQWV LQ 7KH QXPEHU RI HOHPHQWV LQ +DVKWDEOH+DVKWDEOH+DVKWDEOH+DVKWDEOH LV DOZDV QRQLV DOZDV QRQLV DOZDV QRQLV DOZDV QRQQHJDWLYHQHJDWLYHQHJDWLYHQHJDWLYH #LQY #LQY #LQY #LQY QXP(OHPHQWVQXP(OHPHQWVQXP(OHPHQWVQXP(OHPHQWV ! ! ! ! SULYDWHSULYDWHSULYDWHSULYDWH LQW QXP(OHPHQWVLQW QXP(OHPHQWVLQW QXP(OHPHQWVLQW QXP(OHPHQWV 7KH SXW RSHUDWLRQ DVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVH 7KH SXW RSHUDWLRQ DVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVH 7KH SXW RSHUDWLRQ DVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVH 7KH SXW RSHUDWLRQ DVVXPHV WKDW WKH VSHFLILHG NH LV QRW XVHGGGG $IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHGWKH VSHFLILHG NH FDQ $IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHGWKH VSHFLILHG NH FDQ $IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHGWKH VSHFLILHG NH FDQ $IWHU WKH SXW RSHUDWLRQ LV FRPSOHWHGWKH VSHFLILHG NH FDQ EH XVHGEH XVHGEH XVHGEH XVHG WR UHFRYHU WKH HQWU ZLWK WKH JHWNH
  • 153. RSHUDWLRQ WR UHFRYHU WKH HQWU ZLWK WKH JHWNH
  • 154. RSHUDWLRQ WR UHFRYHU WKH HQWU ZLWK WKH JHWNH
  • 155. RSHUDWLRQ WR UHFRYHU WKH HQWU ZLWK WKH JHWNH
  • 165. HQWU #SRVW JHWNH
  • 166. HQWU #SRVW JHWNH
  • 167. HQWU #SRVW JHWNH
  • 168. HQWU SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 169. ^SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 170. ^SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 171. ^SXEOLF YRLG SXW 2EMHFW NH 2EMHFW HQWU
  • 172. ^
  • 173. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 32 Instrumentation comments Assertion-checking with iContract tools ā€¢ Comment pre-conditions, post-conditions, and invariants in a subset of ā€œobject constraint languageā€ (OCL) ā€¢ iContract inserts Java code for run-time assertion checking (ā€œinstrumented codeā€) ā€¢ The instrumented code throws RuntimeExceptions if assertion is false ā€¢ The code can also be compiled for release without assertion checking ā€¢ Example of code generated from @pre (n = 0) _ _ _ _ LQWLQWLQWLQW BBUHWXUQBYDOXHBKROGHUBBBUHWXUQBYDOXHBKROGHUBBBUHWXUQBYDOXHBKROGHUBBBUHWXUQBYDOXHBKROGHUB _ _ _ _ ERROHDQERROHDQERROHDQERROHDQ BBSUHBSDVVHG IDOVH WUXH LI SUHBBSUHBSDVVHG IDOVH WUXH LI SUHBBSUHBSDVVHG IDOVH WUXH LI SUHBBSUHBSDVVHG IDOVH WUXH LI SUHFRQGFRQGFRQGFRQG SDVVHGSDVVHGSDVVHGSDVVHG _ LI _ LI _ LI _ LI Q !
  • 174. Q !
  • 175. Q !
  • 176. Q !
  • 177.
  • 178. BBSUHBSDVVHG WUXH VXFFHHGHG
  • 179. BBSUHBSDVVHG WUXH VXFFHHGHG
  • 180. BBSUHBSDVVHG WUXH VXFFHHGHG
  • 181. BBSUHBSDVVHG WUXH VXFFHHGHG _ LI _ LI _ LI _ LI BBSUHBSDVVHG
  • 185. ^ _ _ _ _ WKURZ QHZWKURZ QHZWKURZ QHZWKURZ QHZ 5XQWLPH([FHSWLRQ5XQWLPH([FHSWLRQ5XQWLPH([FHSWLRQ5XQWLPH([FHSWLRQ ' ' ' '????????WRROVWRROVWRROVWRROV????????,%09-DYD,%09-DYD,%09-DYD,%09-DYD????????,'(,'(,'(,'(????????SURMHFWBUHVRXUFHVSURMHFWBUHVRXUFHVSURMHFWBUHVRXUFHVSURMHFWBUHVRXUFHV????????]]]]????????LURRWLURRWLURRWLURRW????????,5RRW,5RRW,5RRW,5RRWMDYD HUURU SUHFRQGLWLRQMDYD HUURU SUHFRQGLWLRQMDYD HUURU SUHFRQGLWLRQMDYD HUURU SUHFRQGLWLRQ YLRODWHG YLRODWHG YLRODWHG YLRODWHG LURRWLURRWLURRWLURRW,5RRW,5RRW,5RRW,5RRWLURRWLURRWLURRWLURRWLQWLQWLQWLQW
  • 186.
  • 188.
  • 190.
  • 192.
  • 194. Q !
  • 195.
  • 196.
  • 197. Q !
  • 198.
  • 199.
  • 200. Q !
  • 201.
  • 202.
  • 203. Q !
  • 204.
  • 205. _
  • 206. _
  • 207. _
  • 208. _
  • 209. ````
  • 210. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 33 Other coding conventions Variable declarations ā€¢ One per line ā€¢ Keep related declarations together ā€¢ Combine declarations with initializations Unless a computed value is needed ā€¢ Good: 6WULQJ6WULQJ6WULQJ6WULQJ QHZ1XPQHZ1XPQHZ1XPQHZ1XP XVHU LQSXW GLJLWV RQO XVHU LQSXW GLJLWV RQO XVHU LQSXW GLJLWV RQO XVHU LQSXW GLJLWV RQO LQWLQWLQWLQW FXUVRU LQGH[ RI FXUUHQW FKDUDFWHUFXUVRU LQGH[ RI FXUUHQW FKDUDFWHUFXUVRU LQGH[ RI FXUUHQW FKDUDFWHUFXUVRU LQGH[ RI FXUUHQW FKDUDFWHU 2EMHFW2EMHFW2EMHFW2EMHFW FUW(QWUFUW(QWUFUW(QWUFUW(QWU FXUUHQWO VHOHFWHG WDEOH HQWU FXUUHQWO VHOHFWHG WDEOH HQWU FXUUHQWO VHOHFWHG WDEOH HQWU FXUUHQWO VHOHFWHG WDEOH HQWU LQWLQWLQWLQW OHYHO LQGHQWDWLRQ OHYHOOHYHO LQGHQWDWLRQ OHYHOOHYHO LQGHQWDWLRQ OHYHOOHYHO LQGHQWDWLRQ OHYHO ā€¢ Not so good (harder to change): 6WULQJ6WULQJ6WULQJ6WULQJ QHZ1XPQHZ1XPQHZ1XPQHZ1XP XVHU LQSXW GLJLWV RQO XVHU LQSXW GLJLWV RQO XVHU LQSXW GLJLWV RQO XVHU LQSXW GLJLWV RQO 2EMHFW2EMHFW2EMHFW2EMHFW FUW(QWUFUW(QWUFUW(QWUFUW(QWU FXUUHQWO VHOHFWHG WDEOH HQWU FXUUHQWO VHOHFWHG WDEOH HQWU FXUUHQWO VHOHFWHG WDEOH HQWU FXUUHQWO VHOHFWHG WDEOH HQWU LQWLQWLQWLQW FXUVRU LQGH[ RI FXUUHQW FKDUDFWHUFXUVRU LQGH[ RI FXUUHQW FKDUDFWHUFXUVRU LQGH[ RI FXUUHQW FKDUDFWHUFXUVRU LQGH[ RI FXUUHQW FKDUDFWHU OHYHO LQGHQWDWLRQ OHYHOOHYHO LQGHQWDWLRQ OHYHOOHYHO LQGHQWDWLRQ OHYHOOHYHO LQGHQWDWLRQ OHYHO ā€¢ Pretty bad: LQWLQWLQWLQW FXUVRU OHYHO FXUVRU OHYHO FXUVRU OHYHO FXUVRU OHYHO ā€¢ Put declarations at the beginning of a block
  • 211. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 34 Other coding conventions Order of the entries in class and interface declarations ā€¢ Data fields ā€¢ Constructor methods ā€¢ Observer methods ā€¢ Mutator methods ā€¢ Producer methods
  • 212. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 35 Component-based development Idea: What makes a component? Components vs. component instances Component = classes, resources, etc. Component instance = customized and connected objects Sebastianā€™sMegablocksComponentsĀ©RaduNegulescu,2003
  • 213. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 36 Component standards Origins: compound documents ā€¢ Xerox Star (-) ā€¢ Appleā€™s Hypercard (-) ā€¢ OpenDoc (-) ā€¢ Visual Basic: embed controls into forms ā€¢ OLE: allow controls to be arbitrary document servers and containers at the same time ā€¢ Web pages: step back to VB forms ā€¢ New VB: ActiveX controls can be containers too ā€¢ OMGā€™s CORBA, IDL ā€¢ Microsoft: COM, COM+, DCOM ā€¢ Sun: Java Beans ā€¢ Microsoft: .NET Assemblies Weā€™ll cover a few Java Beans features as an example
  • 214. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 37 Java Beans Java applets ā€¢ Mini applications launched by a browser or other environment ā€¢ Applets are isolated from whatever executes in the same environment Two applets can run in the same browser, but cannot interact except by talking to the server side ā€¢ Applets are not downloaded together with their own image or resource files Java Beans ā€¢ Java Beans specification (JavaSoft, 1996) ā€¢ Unlike applets, a Bean can talk to other components on a web page ā€¢ The term ā€œBeanā€ refers both to ā€œcomponentā€ and ā€œcomponent instanceā€
  • 215. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 38 Java Beans Java Beans have been conceived for dual usage ā€¢ ā€œDesign timeā€: assemble the beans with a tool E.g. set-up the properties through dialogs, customize behavior, graphically set up connections ā€¢ ā€œRun timeā€: normal functionality Used interactively (graphical and I/O operations) Used non-interactively (skip the GUI operations) ā€¢ A bean instance can inquire whether it is at design time or run time, and whether it is used interactively or not Any class can be a bean ā€¢ What makes a bean usable as a bean is the adherence to a set of conventions
  • 216. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 39 Java Beans properties Java Beans properties = attributes (fields) exposed by pairs of getter and setter methods SXEOLF FODVVSXEOLF FODVVSXEOLF FODVVSXEOLF FODVV 0ODVV0ODVV0ODVV0ODVV ^^^^ SURWHFWHGSURWHFWHGSURWHFWHGSURWHFWHG LQW YDOLQW YDOLQW YDOLQW YDO SXEOLFSXEOLFSXEOLFSXEOLF LQWLQWLQWLQW JHW9DOJHW9DOJHW9DOJHW9DO
  • 217. ^`
  • 218. ^`
  • 219. ^`
  • 220. ^` SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG VHW9DOVHW9DOVHW9DOVHW9DOLQW QHZYDOLQW QHZYDOLQW QHZYDOLQW QHZYDO
  • 221. ^`
  • 222. ^`
  • 223. ^`
  • 224. ^` ```` ā€¢ Can be accessed by property sheets (customization) Both at design time and run time ā€¢ Java Beans ā€œdesign patternā€: really a naming convention General ā€œdesign patternā€: setXyz, getXyz as above Boolean ā€œdesign patternā€: differs by method isPropertyName ā€¢ Maintainability: change implementation while keeping the interface C# calls getters and setters automatically on each evaluation assignment
  • 225. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 40 Java Beans properties An example SXEOLF FODVVSXEOLF FODVVSXEOLF FODVVSXEOLF FODVV 0%R[0%R[0%R[0%R[ ^^^^ SURWHFWHG 3RLQWSURWHFWHG 3RLQWSURWHFWHG 3RLQWSURWHFWHG 3RLQW OOOOOOOO ORZHU OHIW FRUQHU [ ! ORZHU OHIW FRUQHU [ ! ORZHU OHIW FRUQHU [ ! ORZHU OHIW FRUQHU [ ! SURWHFWHGSURWHFWHGSURWHFWHGSURWHFWHG LQWLQWLQWLQW ZLGWK ! ZLGWK ! ZLGWK ! ZLGWK ! SURWHFWHGSURWHFWHGSURWHFWHGSURWHFWHG LQWLQWLQWLQW KHLJKW ! KHLJKW ! KHLJKW ! KHLJKW ! QR XSSHU ULJKW FRUQHU QR XSSHU ULJKW FRUQHU QR XSSHU ULJKW FRUQHU QR XSSHU ULJKW FRUQHU SXEOLF 3RLQWSXEOLF 3RLQWSXEOLF 3RLQWSXEOLF 3RLQW JHW/OJHW/OJHW/OJHW/O
  • 226. ^`
  • 227. ^`
  • 228. ^`
  • 229. ^` SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG VHW/OVHW/OVHW/OVHW/O3RLQW3RLQW3RLQW3RLQW QHZOOQHZOOQHZOOQHZOO
  • 230. ^`
  • 231. ^`
  • 232. ^`
  • 233. ^` SXEOLFSXEOLFSXEOLFSXEOLF LQW JHW:LGWKLQW JHW:LGWKLQW JHW:LGWKLQW JHW:LGWK
  • 234. ^`
  • 235. ^`
  • 236. ^`
  • 237. ^` SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG VHW:LGWKVHW:LGWKVHW:LGWKVHW:LGWKLQW QHZ:LGWKLQW QHZ:LGWKLQW QHZ:LGWKLQW QHZ:LGWK
  • 238. ^`
  • 239. ^`
  • 240. ^`
  • 241. ^` SXEOLFSXEOLFSXEOLFSXEOLF LQW JHW+HLJKWLQW JHW+HLJKWLQW JHW+HLJKWLQW JHW+HLJKW
  • 242. ^`
  • 243. ^`
  • 244. ^`
  • 245. ^` SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG VHW+HLJKWVHW+HLJKWVHW+HLJKWVHW+HLJKWLQW QHZ+HLJKWLQW QHZ+HLJKWLQW QHZ+HLJKWLQW QHZ+HLJKW
  • 246. ^`
  • 247. ^`
  • 248. ^`
  • 249. ^` SXEOLF 3RLQWSXEOLF 3RLQWSXEOLF 3RLQWSXEOLF 3RLQW JHW8UJHW8UJHW8UJHW8U
  • 250. ^`
  • 251. ^`
  • 252. ^`
  • 253. ^` SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG VHW8UVHW8UVHW8UVHW8U3RLQW3RLQW3RLQW3RLQW QHZ8UQHZ8UQHZ8UQHZ8U
  • 254. ^`
  • 255. ^`
  • 256. ^`
  • 258. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 41 Java Beans properties Indexed properties ā€¢ Array attribute ā€¢ Permits access by getter and setter, plus an indexed form Bound properties ā€¢ Changes in a bound property will trigger events that will notify listeners of the change SXEOLF FODVVSXEOLF FODVVSXEOLF FODVVSXEOLF FODVV 3URSHUWKDQJH(YHQW3URSHUWKDQJH(YHQW3URSHUWKDQJH(YHQW3URSHUWKDQJH(YHQW H[WHQGV MDYDXWLOH[WHQGV MDYDXWLOH[WHQGV MDYDXWLOH[WHQGV MDYDXWLO(YHQW2EMHFW(YHQW2EMHFW(YHQW2EMHFW(YHQW2EMHFW ^^^^ SXEOLF 2EMHFWSXEOLF 2EMHFWSXEOLF 2EMHFWSXEOLF 2EMHFW JHW1HZ9DOXHJHW1HZ9DOXHJHW1HZ9DOXHJHW1HZ9DOXH
  • 259. SXEOLF 2EMHFWSXEOLF 2EMHFWSXEOLF 2EMHFWSXEOLF 2EMHFW JHW2OG9DOXHJHW2OG9DOXHJHW2OG9DOXHJHW2OG9DOXH
  • 260. SXEOLF 6WULQJSXEOLF 6WULQJSXEOLF 6WULQJSXEOLF 6WULQJ JHW3URSHUW1DPHJHW3URSHUW1DPHJHW3URSHUW1DPHJHW3URSHUW1DPH
  • 261. ```` ā€¢ To register/deregister a property change listener, call: SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG DGG3URSHUWKDQJH/LVWHQHUDGG3URSHUWKDQJH/LVWHQHUDGG3URSHUWKDQJH/LVWHQHUDGG3URSHUWKDQJH/LVWHQHU 3URSHUWKDQJH/LVWHQHU3URSHUWKDQJH/LVWHQHU3URSHUWKDQJH/LVWHQHU3URSHUWKDQJH/LVWHQHU [
  • 262. [
  • 263. [
  • 264. [
  • 265. SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG UHPRYH3URSHUWKDQJH/LVWHQHUUHPRYH3URSHUWKDQJH/LVWHQHUUHPRYH3URSHUWKDQJH/LVWHQHUUHPRYH3URSHUWKDQJH/LVWHQHU 3URSHUWKDQJH/LVWHQHU3URSHUWKDQJH/LVWHQHU3URSHUWKDQJH/LVWHQHU3URSHUWKDQJH/LVWHQHU [
  • 266. [
  • 267. [
  • 268. [
  • 269. ā€¢ On the listener side, implement method: SXEOLF YRLGSXEOLF YRLGSXEOLF YRLGSXEOLF YRLG 3URSHUWKDQJH3URSHUWKDQJH3URSHUWKDQJH3URSHUWKDQJH3URSHUWKDQJH(YHQW3URSHUWKDQJH(YHQW3URSHUWKDQJH(YHQW3URSHUWKDQJH(YHQW H
  • 270. ^ `H
  • 271. ^ `H
  • 272. ^ `H
  • 273. ^ ` Constrained properties ā€¢ Changes and events are vetoable and reversible
  • 274. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 42 Event-based control The state of the event source is communicated to the event listener ā€¢ Event object passed as parameter to event handler method ā€¢ Use an ā€œeventā€ object, parameter to handler method ā€¢ Used in many foundation class libraries ā€œGeneralization of Observer patternā€ Source register (Listener) unregister (Listener) cast (Event) Listener handle (Event) *1 ConcreteListener listenerState handle (Event) ConcreteSource subjectState cast (Event) * 1 listenerState = event.getState(); Event copyState getState () *1 create new Event e; for each registered Listener l l.handle(e); event (YHQW VRXUFH (YHQW OLVWHQHUV
  • 275. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 43 Java Beans events and connections Java Beans event model ā€¢ Event listeners Need to implement an interface that extends java.beans.EventListener Have a handler method for each event the listener listens to LQWHUIDFH :KHHO'/LVWHQHU H[WHQGV MDYDXWLOLQWHUIDFH :KHHO'/LVWHQHU H[WHQGV MDYDXWLOLQWHUIDFH :KHHO'/LVWHQHU H[WHQGV MDYDXWLOLQWHUIDFH :KHHO'/LVWHQHU H[WHQGV MDYDXWLO(YHQW/LVWHQHU(YHQW/LVWHQHU(YHQW/LVWHQHU(YHQW/LVWHQHU ^^^^ YRLG ZKHHO'
  • 279. ```` ā€¢ Event sources Provide pairs of register and unregister methods SXEOLF YRLG DGG:KHHO'/LVWHQHU:KHHO'/LVWHQHU O
  • 287. ā€¢ Event adapters Merge event streams Both listener and source Can perform arbitrary filtering functions
  • 288. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 44 JAR files JAR (Java Archive) files are compressed files that can package several beans and auxiliary resources ā€¢ PKZIP archive format ā€¢ Class files Possibly, several beans ā€¢ Serialized objects representing bean prototypes (instances) Contain state information (customization, field values) ā€¢ Optionally, a manifest file Contents of the archive ā€¢ Optional help files in HTML ā€¢ Optional localization information ā€¢ Resource files needed by the bean Icons GIF, JPEG, ...
  • 289. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 45 Technical documents Guidelines for: specifications, manuals, design, change plans, the code itself, notes, messages, etc. What is important for the technical documentation for software? ā€¢ Correctness, completeness, aspect, ... ā€¢ Maintainability, concision, navigability, consistency, clarity, ... Keep in mind the purpose - what needs to be done with the document ā€¢ Consult for detail information ā€“ precise, clear ā€¢ Browse for specific information ā€“ easy to navigate ā€¢ Modify often, keep consistency ā€“ maintainable ā€¢ Convey an image ā€¢ NOT entertainment...
  • 290. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 46 Technical documents Maintainability! ā€¢ Documentation needs to be updated and corrected, just like code Documentation should be modular, just like code ā€¢ Avoid: redundant, repetitious text Invites consistency problems whenever changes are made Good: say something in one place, insert cross-reference in the other place ā€œWindow envelopeā€ principle Redundancy is useful in some situations, but it better have a good excuse Support cross-checks Support quick high-level view ā€¢ Avoid: amalgamated text Good: isolate ideas, keep each sentence focused, summarize each paragraph in the opening sentence ā€¢ Avoid: update help files and user manuals independently Good: obtain manuals automatically from help files, or obtain both from code (e.g. by javadoc) Good: or, obtain both manually from the specification documents
  • 291. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 47 Technical documents Concision! ā€¢ ā€œConcision does not mean omission of detail, but that every word tellā€ ---Strunk White ā€¢ Bad: inclusion of lecture notes in a design document Good: rationale for your design decisions Navigability! ā€¢ How easy is it to find the relevant information? ā€¢ Bad: unstructured text Good: table of contents, cross-references, hyperlinks, index of terms Consistency! ā€¢ Consistent style facilitates information retrieval Unlike literary writing, technical writing is not made better by style variation Clarity! ā€¢ E.g. avoid ambiguous expressions: ā€œitā€, ā€œthisā€, ...
  • 292. McGill University ECSE 321 Ā© 2003 Radu Negulescu Introduction to Software Engineering Coding standardsā€”Slide 48 References Generic coding conventions ā€¢ Layout: McConnell ch. 18 ā€¢ Comments: McConnell ch. 19 ā€¢ Naming: McConnell ch. 9, sect. 5.2 Java coding conventions ftp://ftp.javasoft.com/docs/codeconv/CodeConventions.pdf Java Beans http://java.sun.com/products/javabeans/ C coding conventions http://www.cs.mcgill.ca/resourcepages/indian-hill.html Javadoc http://java.sun.com/products/jdk/javadoc/writingdoccomments.html iContract tools http://www.reliable-systems.com/tools/iContract/iContract.htm