SlideShare uma empresa Scribd logo
1 de 37
Programming Style Guidelines Nhat ‘Rich’ Nguyen Future  Computing  Lab February 2010
2 “You got to know the rules before you can break them. Otherwise it’s no fun.” Sonny Crockett (Miami Vice)
Benefits of well-written code Understanding Sharing Maintaining Being professional 3
Overview Naming Convention Organization Statements Documentation Extra Guidelines 4
1. Naming Convention 5 “What's in a name? That which we call a roseby any other name would smell as sweet.”  Juliet / WilliamShakespeare
Variables Mixed case starting with lower case  Small scope – short names Prefix n represent number of objects Suffix Array for plural convention Prefix i represent single entity number  6
Variables Prefixed i, j, k for iterator Negated Boolean name should be avoid Acronyms should be mixed or lower case Avoid keywords 7
Constants All UPPERCASE with underscore  Prefixed by a common type name 8
Structures Begin with capital letter Need not include structure name in field name 9
Functions Lower case (maybe with underscore) Meaningful names Single output - named for the output No output – named after what they do Avoid unintentional shadowing: unique name. 10
Function Prefixes get/set  - reserved for accessing a property  compute – where something is computed find– where something is looked up initialize – where object is established is – used for Boolean function has, can – alternative to is 11
Function Symmetry 12 Reduce complexity by symmetry
2. Organization 13 "A place for everything, everything in its place." Benjamin Franklin
.m Files Break it down to functions Enhance readability, understanding, testing Make interaction clear Have input, output arguments Use structures to avoid long list of arguments Your functions should do something very well 14
.m Files Use existing functions Quicker to find an existing function Package any block of code as a function  If it appears in more  than one .m-file. Write test scripts for every function Improve quality of  the initial version Enhance reliability of changed version 15
Input and Output Make input and output modules Input is subject to change and often messy Output is subject to change without notice Localize code to preprocess them. Format output for easy use For human: make it self descriptive and easy to read. For another function: make it easy to use as input. For both: make it easy to use as input and write a formatter function to produce a human readable version. 16
3. Statements 17 “A month from now, if I look at this code, will I understand what it’s doing?” Steve Lord – The MathWorks Inc.
General Avoid cryptic code Numbers in expressions should be named constants instead Indentation to reveal structure (Ctrl + I) Content should be kept in the first 80 columns 18
Variables and constants Document important variables near the start Document constant assignment Use .m or .mat file for global constant 19
20
Loops Loops variables should be initialized immediately before the loop end lines of nested loops can have comments 21
Conditionals Avoid complex conditional expressions 22
Conditionals Put the usual case in the if-part and the exception in the else-part Switch statement should include otherwise condition 23
4. Documentation 24 “Good documentation is a sign of the professional pride a programmer puts into a program.”  Steve McConnell
White Space Surround =, &, and | and operators Follow Commas One or more blank lines among Block of statement  Alignment 25
Comments Cannot justify poorly written code Do more than just restate  the code Should be easy to read Have same indentation as codes referred to Header comment should support the use of help and lookfor ,[object Object]
lookforsearches the first comment line of all m-files on the path. 26
27
28
Documentation Description: what the code is supposed to do  Design: how it works Interfaces: which functions it depends on and how it is used by other code Examples: how it is tested. Credits:who wrote, modified, and when. 29
30 Example Description Design Interface Example Credits
Documentation Tool: m2html 31
5. Extra Guidelines 32 “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”Bill Gates   
Design Guidelines	 Elegance always paid off. First make it work, then make it fast. Remember ‘divide and conquer’. Automate everything. Write the test code first. Make function as atomic as possible. Don’t repeat yourself. 33
Implementation Guidelines	 Follow coding conventions. Group standardize code. Use ‘get’, ‘set’, ‘is’ naming convention.  Don’t fall for premature optimization. Robust components make robust program. Avoid using ‘magic number’. Code is read much more than it is written. 34
Documentation Guidelines	 Write documentation first! Define what each function should do.  Define how it interact with other function. Include case testing scripts. 35
Use this presentation as a guide,  Refer to it often, and … Practice, practice, practice. Ask the group if you need a code review.  Good luck! 36

Mais conteúdo relacionado

Destaque

Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingSachintha Gunasena
 
Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainWeb Directions
 
CS201- Introduction to Programming- Lecture 01
CS201- Introduction to Programming- Lecture 01CS201- Introduction to Programming- Lecture 01
CS201- Introduction to Programming- Lecture 01Bilal Ahmed
 
Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01hassaanciit
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overviewJong Soon Bok
 
New Programming Style of Java
New Programming Style of JavaNew Programming Style of Java
New Programming Style of JavaYuichi Sakuraba
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 

Destaque (10)

Applicative style programming
Applicative style programmingApplicative style programming
Applicative style programming
 
Programming style
Programming styleProgramming style
Programming style
 
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency ProgrammingConcurrency Programming in Java - 01 - Introduction to Concurrency Programming
Concurrency Programming in Java - 01 - Introduction to Concurrency Programming
 
Douglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your BrainDouglas Crockford - Programming Style and Your Brain
Douglas Crockford - Programming Style and Your Brain
 
CS201- Introduction to Programming- Lecture 01
CS201- Introduction to Programming- Lecture 01CS201- Introduction to Programming- Lecture 01
CS201- Introduction to Programming- Lecture 01
 
Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01Introduction to Computer and Programming - Lecture 01
Introduction to Computer and Programming - Lecture 01
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
 
New Programming Style of Java
New Programming Style of JavaNew Programming Style of Java
New Programming Style of Java
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Semelhante a Programming style guildelines

Coding standards
Coding standardsCoding standards
Coding standardsMimoh Ojha
 
Coding Best Practices.docx
Coding Best Practices.docxCoding Best Practices.docx
Coding Best Practices.docxShitanshuKumar15
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringEyob Lube
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applicationsChandra Sekhar Saripaka
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytechyannick grenzinger
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptVinayakHospet1
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016Søren Lund
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldDavid McCarter
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#Svetlin Nakov
 
Crafting high quality code
Crafting high quality code Crafting high quality code
Crafting high quality code Allan Mangune
 
Combating software entropy 2-roc1-
Combating software entropy 2-roc1-Combating software entropy 2-roc1-
Combating software entropy 2-roc1-Hammad Rajjoub
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Søren Lund
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...DevDay.org
 
Lotusphere 2007 AD505 DevBlast 30 LotusScript Tips
Lotusphere 2007 AD505 DevBlast 30 LotusScript TipsLotusphere 2007 AD505 DevBlast 30 LotusScript Tips
Lotusphere 2007 AD505 DevBlast 30 LotusScript TipsBill Buchan
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guidelineDhananjaysinh Jhala
 

Semelhante a Programming style guildelines (20)

Coding standard
Coding standardCoding standard
Coding standard
 
Coding standards
Coding standardsCoding standards
Coding standards
 
Coding Best Practices.docx
Coding Best Practices.docxCoding Best Practices.docx
Coding Best Practices.docx
 
C# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoringC# coding standards, good programming principles & refactoring
C# coding standards, good programming principles & refactoring
 
7-CodingAndUT.ppt
7-CodingAndUT.ppt7-CodingAndUT.ppt
7-CodingAndUT.ppt
 
Best practices in enterprise applications
Best practices in enterprise applicationsBest practices in enterprise applications
Best practices in enterprise applications
 
Software Craftmanship - Cours Polytech
Software Craftmanship - Cours PolytechSoftware Craftmanship - Cours Polytech
Software Craftmanship - Cours Polytech
 
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
 
Coding Standards
Coding StandardsCoding Standards
Coding Standards
 
c-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.pptc-coding-standards-and-best-programming-practices.ppt
c-coding-standards-and-best-programming-practices.ppt
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
 
Back-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real WorldBack-2-Basics: .NET Coding Standards For The Real World
Back-2-Basics: .NET Coding Standards For The Real World
 
Writing High Quality Code in C#
Writing High Quality Code in C#Writing High Quality Code in C#
Writing High Quality Code in C#
 
Crafting high quality code
Crafting high quality code Crafting high quality code
Crafting high quality code
 
Combating software entropy 2-roc1-
Combating software entropy 2-roc1-Combating software entropy 2-roc1-
Combating software entropy 2-roc1-
 
Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016Documenting Code - Patterns and Anti-patterns - NLPW 2016
Documenting Code - Patterns and Anti-patterns - NLPW 2016
 
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
[DevDay2018] Let’s all get along. Clean Code please! - By: Christophe K. Ngo,...
 
Lotusphere 2007 AD505 DevBlast 30 LotusScript Tips
Lotusphere 2007 AD505 DevBlast 30 LotusScript TipsLotusphere 2007 AD505 DevBlast 30 LotusScript Tips
Lotusphere 2007 AD505 DevBlast 30 LotusScript Tips
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
 

Mais de Rich Nguyen

Improving pollen classification with less training effort
Improving pollen classification with less training effortImproving pollen classification with less training effort
Improving pollen classification with less training effortRich Nguyen
 
An Accurate Cell Detection with Minimal Training Effort
An Accurate Cell Detection with Minimal Training EffortAn Accurate Cell Detection with Minimal Training Effort
An Accurate Cell Detection with Minimal Training EffortRich Nguyen
 
Wbc master thesisdefense
Wbc master thesisdefenseWbc master thesisdefense
Wbc master thesisdefenseRich Nguyen
 
Object tracking survey
Object tracking surveyObject tracking survey
Object tracking surveyRich Nguyen
 
Soccer Ball Tracking
Soccer Ball TrackingSoccer Ball Tracking
Soccer Ball TrackingRich Nguyen
 
Tracking Colliding Cells
Tracking Colliding CellsTracking Colliding Cells
Tracking Colliding CellsRich Nguyen
 

Mais de Rich Nguyen (8)

Improving pollen classification with less training effort
Improving pollen classification with less training effortImproving pollen classification with less training effort
Improving pollen classification with less training effort
 
An Accurate Cell Detection with Minimal Training Effort
An Accurate Cell Detection with Minimal Training EffortAn Accurate Cell Detection with Minimal Training Effort
An Accurate Cell Detection with Minimal Training Effort
 
Wbc master thesisdefense
Wbc master thesisdefenseWbc master thesisdefense
Wbc master thesisdefense
 
Wbc cmc talk
Wbc cmc talkWbc cmc talk
Wbc cmc talk
 
Object tracking survey
Object tracking surveyObject tracking survey
Object tracking survey
 
Wbc demo
Wbc demoWbc demo
Wbc demo
 
Soccer Ball Tracking
Soccer Ball TrackingSoccer Ball Tracking
Soccer Ball Tracking
 
Tracking Colliding Cells
Tracking Colliding CellsTracking Colliding Cells
Tracking Colliding Cells
 

Último

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Último (20)

What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Programming style guildelines

  • 1. Programming Style Guidelines Nhat ‘Rich’ Nguyen Future Computing Lab February 2010
  • 2. 2 “You got to know the rules before you can break them. Otherwise it’s no fun.” Sonny Crockett (Miami Vice)
  • 3. Benefits of well-written code Understanding Sharing Maintaining Being professional 3
  • 4. Overview Naming Convention Organization Statements Documentation Extra Guidelines 4
  • 5. 1. Naming Convention 5 “What's in a name? That which we call a roseby any other name would smell as sweet.” Juliet / WilliamShakespeare
  • 6. Variables Mixed case starting with lower case Small scope – short names Prefix n represent number of objects Suffix Array for plural convention Prefix i represent single entity number 6
  • 7. Variables Prefixed i, j, k for iterator Negated Boolean name should be avoid Acronyms should be mixed or lower case Avoid keywords 7
  • 8. Constants All UPPERCASE with underscore Prefixed by a common type name 8
  • 9. Structures Begin with capital letter Need not include structure name in field name 9
  • 10. Functions Lower case (maybe with underscore) Meaningful names Single output - named for the output No output – named after what they do Avoid unintentional shadowing: unique name. 10
  • 11. Function Prefixes get/set - reserved for accessing a property compute – where something is computed find– where something is looked up initialize – where object is established is – used for Boolean function has, can – alternative to is 11
  • 12. Function Symmetry 12 Reduce complexity by symmetry
  • 13. 2. Organization 13 "A place for everything, everything in its place." Benjamin Franklin
  • 14. .m Files Break it down to functions Enhance readability, understanding, testing Make interaction clear Have input, output arguments Use structures to avoid long list of arguments Your functions should do something very well 14
  • 15. .m Files Use existing functions Quicker to find an existing function Package any block of code as a function If it appears in more than one .m-file. Write test scripts for every function Improve quality of the initial version Enhance reliability of changed version 15
  • 16. Input and Output Make input and output modules Input is subject to change and often messy Output is subject to change without notice Localize code to preprocess them. Format output for easy use For human: make it self descriptive and easy to read. For another function: make it easy to use as input. For both: make it easy to use as input and write a formatter function to produce a human readable version. 16
  • 17. 3. Statements 17 “A month from now, if I look at this code, will I understand what it’s doing?” Steve Lord – The MathWorks Inc.
  • 18. General Avoid cryptic code Numbers in expressions should be named constants instead Indentation to reveal structure (Ctrl + I) Content should be kept in the first 80 columns 18
  • 19. Variables and constants Document important variables near the start Document constant assignment Use .m or .mat file for global constant 19
  • 20. 20
  • 21. Loops Loops variables should be initialized immediately before the loop end lines of nested loops can have comments 21
  • 22. Conditionals Avoid complex conditional expressions 22
  • 23. Conditionals Put the usual case in the if-part and the exception in the else-part Switch statement should include otherwise condition 23
  • 24. 4. Documentation 24 “Good documentation is a sign of the professional pride a programmer puts into a program.” Steve McConnell
  • 25. White Space Surround =, &, and | and operators Follow Commas One or more blank lines among Block of statement Alignment 25
  • 26.
  • 27. lookforsearches the first comment line of all m-files on the path. 26
  • 28. 27
  • 29. 28
  • 30. Documentation Description: what the code is supposed to do Design: how it works Interfaces: which functions it depends on and how it is used by other code Examples: how it is tested. Credits:who wrote, modified, and when. 29
  • 31. 30 Example Description Design Interface Example Credits
  • 33. 5. Extra Guidelines 32 “Measuring programming progress by lines of code is like measuring aircraft building progress by weight.”Bill Gates   
  • 34. Design Guidelines Elegance always paid off. First make it work, then make it fast. Remember ‘divide and conquer’. Automate everything. Write the test code first. Make function as atomic as possible. Don’t repeat yourself. 33
  • 35. Implementation Guidelines Follow coding conventions. Group standardize code. Use ‘get’, ‘set’, ‘is’ naming convention. Don’t fall for premature optimization. Robust components make robust program. Avoid using ‘magic number’. Code is read much more than it is written. 34
  • 36. Documentation Guidelines Write documentation first! Define what each function should do. Define how it interact with other function. Include case testing scripts. 35
  • 37. Use this presentation as a guide, Refer to it often, and … Practice, practice, practice. Ask the group if you need a code review. Good luck! 36
  • 38. References Richard Johnson – MATLAB Programming Style Guidelines. Bruce Eckel– Thinking in Java. Piotr Dollar – Image&Video Toolbox. 37