SlideShare a Scribd company logo
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

More Related Content

Viewers also liked

Applicative style programming
Applicative style programmingApplicative style programming
Applicative style programming
José Luis García Hernández
 
Programming style
Programming styleProgramming style
Programming style
Sebastian Pożoga
 
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
Sachintha 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 Brain
Web Directions
 
CS201- Introduction to Programming- Lecture 01
CS201- Introduction to Programming- Lecture 01CS201- Introduction to Programming- Lecture 01
CS201- Introduction to Programming- Lecture 01
Bilal 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 01
hassaanciit
 
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 Java
Yuichi Sakuraba
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 

Viewers also liked (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
 

Similar to Programming style guildelines

Coding standards
Coding standardsCoding standards
Coding standards
Mimoh Ojha
 
Coding Best Practices.docx
Coding Best Practices.docxCoding Best Practices.docx
Coding Best Practices.docx
ShitanshuKumar15
 
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
Eyob 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 Polytech
yannick grenzinger
 
9-Coding.ppt
9-Coding.ppt9-Coding.ppt
9-Coding.ppt
KomalSinghGill
 
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
VinayakHospet1
 
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
David McCarter
 
Documenting code yapceu2016
Documenting code yapceu2016Documenting code yapceu2016
Documenting code yapceu2016
Sø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 World
David 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 2016
Sø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 Tips
Bill Buchan
 
Coding standard and coding guideline
Coding standard and coding guidelineCoding standard and coding guideline
Coding standard and coding guideline
Dhananjaysinh Jhala
 

Similar to 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
 

More from 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 Effort
Rich Nguyen
 
Wbc master thesisdefense
Wbc master thesisdefenseWbc master thesisdefense
Wbc master thesisdefense
Rich Nguyen
 
Wbc cmc talk
Wbc cmc talkWbc cmc talk
Wbc cmc talk
Rich Nguyen
 
Object tracking survey
Object tracking surveyObject tracking survey
Object tracking survey
Rich Nguyen
 
Wbc demo
Wbc demoWbc demo
Wbc demo
Rich Nguyen
 
Soccer Ball Tracking
Soccer Ball TrackingSoccer Ball Tracking
Soccer Ball Tracking
Rich Nguyen
 
Tracking Colliding Cells
Tracking Colliding CellsTracking Colliding Cells
Tracking Colliding Cells
Rich Nguyen
 

More from 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
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 

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