Feb. 8, 2008 UHCO Graduate Course in MATLAB Core Programming Module Best Practices Core Grant Programming Module Best Practices (Coding Conventions) General.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

PHP Reusing Code and Writing Functions.
M AT L AB Programming: scripts & functions. Scripts It is possible to achieve a lot simply by executing one command at a time on the command line (even.
Unit 3 Day 4 FOCS – Web Design. No Journal Entry.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
The Web Warrior Guide to Web Design Technologies
Coding Standards for Java An Introduction. Why Coding Standards are Important? Coding Standards lead to greater consistency within your code and the code.
Objects First With Java A Practical Introduction Using BlueJ Designing object-oriented programs How to write code in a way that is easily understandable,
IS 1181 IS 118 Introduction to Development Tools VB Chapter 06.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
1 Introduction to Software Engineering Lecture 42 – Communication Skills.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
CSE1301 Computer Programming: Lecture 13 Documentation.
Chapter 1 Principles of Programming and Software Engineering.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Fruitful functions. Return values The built-in functions we have used, such as abs, pow, int, max, and range, have produced results. Calling each of these.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Comp 245 Data Structures Software Engineering. What is Software Engineering? Most students obtain the problem and immediately start coding the solution.
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
How to think through your program [ principles of good program design ] Rachel Denison MATLAB for Cognitive Neuroscience ICN, 13 December 2007.
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Loops: Handling Infinite Processes CS 21a: Introduction to Computing I First Semester,
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Introduction to Exception Handling and Defensive Programming.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
Abstract The Center for Remote Sensing of Ice Sheets (CReSIS) has collected hundreds of terabytes of radar depth sounder data over the Greenland and Antarctic.
Advanced Topics- Functions Introduction to MATLAB 7 Engineering 161.
CPS120: Introduction to Computer Science Functions.
Feb. 9, 2010 UHCO Graduate Course in MATLAB Core Programming Module Best Practices Core Grant Programming Module Best Practices (Coding Conventions) General.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Getting Started with MATLAB (part2) 1. Basic Data manipulation 2. Basic Data Understanding 1. The Binary System 2. The ASCII Table 3. Creating Good Variables.
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Starting Out with C++ Early Objects ~~ 7 th Edition by Tony Gaddis, Judy Walters, Godfrey Muganda Modified for CMPS 1044 Midwestern State University 6-1.
A (VERY) SHORT INTRODUCTION TO MATLAB J.A. MARR George Mason University School of Physics, Astronomy and Computational Sciences.
XP New Perspectives on XML, 2 nd Edition Tutorial 7 1 TUTORIAL 7 CREATING A COMPUTATIONAL STYLESHEET.
EGR 115 Introduction to Computing for Engineers MATLAB Basics 6: Debugging in MATLAB Monday 15 Sept 2014 EGR 115 Introduction to Computing for Engineers.
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Functions in C++ Top Down Design with Functions. Top-down Design Big picture first broken down into smaller pieces.
And other languages…. must remember to check return value OR, must pass label/exception handler to every function Caller Function return status Caller.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Today… Modularity, or Writing Functions. Winter 2016CISC101 - Prof. McLeod1.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Outline of Script Import Modules Setup Workspace Environment and Assign Data Path Variables Summary of Script Title and Author Info.
User-Written Functions
CSCI-235 Micro-Computer Applications
Matlab Training Session 4: Control, Flow and Functions
Principles of Programming and Software Engineering
About the Presentations
Variables, Expressions, and IO
Using Procedures and Exception Handling
Use of Mathematics using Technology (Maltlab)
T. Jumana Abu Shmais – AOU - Riyadh
Communication and Coding Theory Lab(CS491)
CISC124 Labs start this week in JEFF 155.
How to write good code Part 2
Simulation And Modeling
Coding practices For IT and Computing students 2014.
Unit 3: Variables in Java
Presentation transcript:

Feb. 8, 2008 UHCO Graduate Course in MATLAB Core Programming Module Best Practices Core Grant Programming Module Best Practices (Coding Conventions) General Best Practices MATLAB Best Practices

Feb. 8, 2008 UHCO Graduate Course in MATLAB Acknowledgements Originally compiled by Raja Nadar (an RA from Computer Science) and Hope Queener –Macadamian Technologies Inc., a software engineering and consulting firm based in Ottawa, Canada. –Industrial Strength C++ by Mats Henricson, Erik Nyquist and Ellemtel Utvecklings.

Feb. 8, 2008 UHCO Graduate Course in MATLAB Core Grant Programming Module NIH Funded support for software development for NIH investigators One of 4 Modules –Instrument Design, Biostatistics, Imaging Hope Queener is Principal of Programming Module

Feb. 8, 2008 UHCO Graduate Course in MATLAB Best Practices Conventions for writing software Avoid typical pitfalls Strategies for long-term maintenance Provide consistency for single developer Provide consistency between developers

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Source Code Organization Naming Conventions Programming Conventions Source Code Documentation Error Checking and Debugging

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Source Code Organization Give source code (.m) files meaningful names Add “version” notes to archives of files, not your working copy –work with: StereoStimulus.m –store old versions as: StereoStimulus m –avoid adding words like “final” or “old” to a file name –if using several files, copy all to an archive folder Avoid hard-coded path names in source files –use uiputfile and uigetfile to let the user select the files

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Source Code Organization (continued) Maintain only project source files in the source code folder –Copy old versions of files to archive folders –Maintain extensive data in a separate folder –Maintain separate folders for projects Maintain daily backup development folders –StereoStimulusArchive\ –What did I do yesterday when everything worked? Back up files to another device or backup media

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Naming Conventions Use full, meaningful names for variables and functions For variable names choose adjectives and nouns. –spatialFrequency For variable names and function arguments use “camel” notation For function names, use a strong verb followed by an object. –PrepareStimulus(stimulusParameters) For function or method names, use title (Pascal) case Note that MATLAB help shows a different naming convention, but by using a different one it is easier to distinguish user-defined variables and functions

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Naming Conventions (continued) Use consistent naming patterns for similar operations –Choose one: compute, calculate, or find Include units in variables representing physical quantities (pixels, mm, Hz, ms) Use “temp” in a variable only within short blocks of code Avoid the use of underscores in variable or function names (awkward to type)

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Naming Conventions (continued) Use only well-accepted acronyms or abbreviations and do so sparingly. Avoid arbitrary abbreviations in variable names –Keep all the vowels –The longer name is much easier to understand for the poor soul that inherits your code Use single-character variables sparingly and with clear purpose –use (row, col) rather than (i, j) or (x, y)

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Programming Conventions Avoid hard-coding values –Store fixed values in a variable, and use the variable –Obtain values from the available files and user input, rather than hard-coding Avoid global variables –Global variables are rarely needed and make code harder to maintain and reuse Use loop or index variables consistently in your program (same variable for same purpose) Check all possible conditions in a switch/case statement Declare one variable per line

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Programming Conventions Maintain a consistent layout style. For long expressions, put separate conditions on separate lines –Use MATLAB... syntax to extend a statement to multiple lines Compare numeric values from lowest to highest to mimic math expressions –((0 < col) & (col < widthOfImage)) Indent argument lists for functions that wrap to the next line

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Programming Conventions When you start to copy and paste a block (multiple lines) of code: –Consider redundancy: Am I doing something that could be in a loop? –Consider a new function: Are the two blocks identical except for a few parameters? Aim for source code modules of 1000 lines or less

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Documentation (Comments) Include an introduction comment at the top of the source file: author, date, purpose Include copyright information, if applicable When declaring variables, add comments on the same line Comment on the purpose of a conditional block of code or loop Describe each routine briefly at the top of the routine. Document the source of algorithms that are used Comment on the routine's limitations

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Error Checking/Debugging Check the arguments that come in to a function Use messages to signal code that should never be executed (if/then/else or switch/case) Detect and handle an error that affects the rest of a routine –return status from functions that others depend upon Remember that error handling code is vulnerable to errors Use meaningful, polite and grammatically correct messages

Feb. 8, 2008 UHCO Graduate Course in MATLAB MATLAB Best Practices Source Code Organizaton Use functions rather than scripts Use separate m-files for generic operations Keep specific functions in the same m-file that calls them Add only general toolboxes to the MATLAB path –avoid building up many folders in path

Feb. 8, 2008 UHCO Graduate Course in MATLAB MATLAB Best Practices Naming Conventions Use general conventions, usually When using GUIDE –rename the tag property of each control –retain the automatic function names –use the handles structure carefully

Feb. 8, 2008 UHCO Graduate Course in MATLAB MATLAB Best Practices Programming Conventions Remember that MATLAB was developed to do math –Use vectors and matrices rather than loops –MATLAB examples read like math papers Remember that for-loops in MATLAB differ than for-loops in C –MATLAB loops operate for each item in list –C loops increment a variable

Feb. 8, 2008 UHCO Graduate Course in MATLAB General Best Practices Hope’s Favorites Add “version” notes to archives of files, not your working copy Maintain daily backup development folders Back up to other media Avoid hard-coded path names in source files Avoid hard-coding values Use full, meaningful names for variables and functions Consider before you start to copy and paste a block of code