(1) Coding Standards Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI 96822.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

Coding Standard: General Rules 1.Always be consistent with existing code. 2.Adopt naming conventions consistent with selected framework. 3.Use the same.
Tutorial 8: Developing an Excel Application
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.
Chapter 10 THINKING IN OBJECTS 1 Object Oriented programming Instructor: Dr. Essam H. Houssein.
HTML5 and CSS3 Illustrated Unit B: Getting Started with HTML
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
15-Jun-15 Beginning Style. 2 Be consistent! Most times, you will enter an ongoing project, with established style rules Follow them even if you don’t.
Programming Style a programs language gives you a lot of freedom how to write a program – too much? but some programming style is good goal: it must be.
16-Jun-15 javadoc. 2 Javadoc placement javadoc comments begin with /** and end with */ In a javadoc comment, a * at the beginning of the line is not part.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
26-Jun-15 Methods. About methods A method is a named group of declarations and statements If a method is in the same class, you execute those declarations.
26-Jun-15 Beginning Style. 2 Be consistent! Most times, you will enter an ongoing project, with established style rules Follow them even if you don’t.
1 Doc Comment Conventions. 2 Write for your audience Rule 32: Write documentation for– those who must use your code Users should not need to care how.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Objectives Explain the purpose and objectives of object- oriented design Develop design class diagrams Develop interaction diagrams based on the principles.
XP Tutorial 1 New Perspectives on JavaScript, Comprehensive1 Introducing JavaScript Hiding Addresses from Spammers.
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Algorithm Programming Coding Advices Bar-Ilan University תשס " ו by Moshe Fresko.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style ADVANCED PROGRAMING PRACTICES API documentation.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 12 Object-Oriented.
What is Sure BDCs? BDC stands for Batch Data Communication and is also known as Batch Input. It is a technique for mass input of data into SAP by simulating.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
JavaDoc1 JavaDoc DEPARTMENT OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING CONCORDIA UNIVERSITY July 24, 2006 by Emil Vassev & Joey Paquet revision 1.2 –
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
The Java Programming Language
Chapter 19. Copyright 2003, Paradigm Publishing Inc. CHAPTER 19 BACKNEXTEND 19-2 LINKS TO OBJECTIVES Affect Text Flow Hyphenate Words Change Hyphenation.
1 JavaScript in Context. Server-Side Programming.
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.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
SE: CHAPTER 7 Writing The Program
23-Oct-15 Abstract Data Types. 2 Data types A data type is characterized by: a set of values a data representation, which is common to all these values,
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Documentation and Programming Style Appendix A © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
Javadoc Comments.  Java API has a documentation tool called javadoc  The javadoc tool is used on the source code embedded with javadoc-style comments.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Software Documentation Section 5.5 ALBING’s Section JIA’s Appendix B JIA’s.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
CSC 212 – Data Structures Prof. Matthew Hertz WTC 207D /
Javadoc Dwight Deugo Nesa Matic
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
XP Tutorial 8 Adding Interactivity with ActionScript.
Code Conventions Tonga Institute of Higher Education.
Programmeren 1 6 september 2010 HOORCOLLEGE 2: INTERACTIE EN CONDITIES PROGRAMMEREN 1 6 SEPTEMBER 2009 Software Systems - Programming1 Programming.
Java Doc Guideline R.SANTHANA GOPALAN. Java Doc Guideline Audience Internal Developers PQA - who write test plans PPT – who write the documentation Customers.
Principles of Programming. Achieving an Object-Oriented Design  Abstraction and Information Hiding  Object-Oriented Design  Functional Decomposition.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
HTML5 and CSS3 Illustrated Unit B: Getting Started with HTML.
Advanced Programing practices
Working with Java.
Lecture 3: Operators, Expressions and Type Conversion
Introduction to C# Applications
Chapter 1: Computer Systems
Anatomy of a Java Program
Advanced Programing practices
Beginning Style 27-Feb-19.
Presentation transcript:

(1) Coding Standards Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI 96822

(2) Objectives Understand motivation for coding standards Write code that conforms to ICS SE coding standards. Recognize and repair non-compliant code. Learn to use automated tools: Checkstyle Eclipse formatter

(3) Why coding standards? Coding standards: improve readability by ensuring a “common look and feel” to the code regardless of how many people have worked on it. improve understandability by ensuring that basic documentation is always present. improve maintainability by improving the predictability of the code.

(4) Elements of Java Style Consolidates the best practices of the Java community gained from the past five years of language use (and experience with other languages before that). The “authoritative” source for coding style in this class. Additional coding standards available at the class web site.

(5) Coding standard principles and conventions General Principles Formatting conventions Naming conventions Documentation conventions Programming conventions Packaging conventions The next sections overview important rules from Elements of Java Style. However, these slides overview the rules, they do not contain enough information to implement them! You must still study the book.

(6) General principles 1. Adhere to the style of the original. 2. Adhere to the Principle of Least Astonishment. Simplicity, clarity, completeness, consistency, robustness 3. Do it right the first time. 4. Document any deviations.

(7) Formatting conventions 5. Indent nested code. 2 spaces Open brace at end of line. Close brace appears by itself on a line. 6. Break up long lines. 100 characters per line maximum. 7. Include whitespace. 8. Do not use tabs.

(8) Naming conventions 9. Use meaningful names. No one character names (except index vars). 10. Use familiar names. Learn the application domain, talk to users. 11. Question excessively long names. May indicate need to refactor/redesign. 12. Join the vowel generation. putSoundFile, not ptSndFl

(9) Naming conventions 13. Capitalize only the first letter in acronyms. getXmlNode, not getXMLNode 14. Do not use names that differ only in case. theInstance and TheInstance 15. Use reversed internet domain names as package prefix. “edu.hawaii.” for this class 16. Use a single lowercased word as the root name for each package. not edu.hawaii.serverkernelfilesystem;

(10) Naming conventions 18. Capitalize the first letter of each word in a class or interface name. ex: ServerProperties 19. Use nouns when naming classes. CustomerAccount, not MaintainCustomerData

(11) Naming conventions 20. Pluralize class names that group related attributes. ex: ServerProperties 21. Use nouns or adjectives when naming interfaces. ActionListener, or Runnable 22. Use lowercase first word and capitalize first letter of subsequent words in method names. getServerHostName

(12) Naming conventions 23. Use verbs when naming methods. ex: withdraw, reset, clear, 24. Follow JavaBeans conventions for property accessor methods. is/get/set 25. Lowercase first word and capitalize remaining words in variable names daytimePhone

(13) Naming conventions 26. Use nouns to name variables daytimeAddress, not getDaytimeAddress 27. Pluralize names of collection references. Customer [] customers; 28. Use standard “throwaway” variable names. index: i, j, k exception: e generic type variable: S, T

(14) Naming conventions 29. Quantify field variables with ‘this’ to distinguish them from local variables. ex: this.address = address; 30. When a parameter assigns a value to a field, use the same name for the parameter and the field. ex: this.address = address; 31. Use uppercase for words and separate with underscore for naming constants. ex: MAX_VALUE

(15) Documentation conventions 32. Write comments for those who use and for those who maintain your code. Assume familiarity with Java, but not with your application. 33. Keep comments and code in sync. 34. Use the active voice and omit needless words. Use forceful, clear, concise language.

(16) Documentation conventions 35. Use documentation comments to describe the programming interface. Defines a “contract” between a client and a supplier of a service. 36. Use standard comments to hide code without removing it. 37. Use one-line comments to explain implementation details. Assume the reader knows Java. Do not repeat what the code does.

(17) Documentation conventions 38. Describe the programming interface before you write the code. This can be your “design phase”. 39. Document public, protected, private, and package private members. Private documentation comments not currently enforced by Checkstyle settings in Ant. 40. Provide a summary description and overview of each package. package.html

(18) Documentation conventions 41. Provide a summary description for your application. overview.html 42. Use a consistent format and organization for all JavaDoc comments. 43. tags.> Do not do this for this class

(19) Documentation conventions 44. Wrap code with tags. 45. Consider tags. Optional for this class. 46. Use a fixed ordering for JavaDoc tags. 47. Write in third-person narrative form. ex: “Gets...”, “Sets...”, “Allocates...”

(20) Documentation conventions 48. Write summary descriptions that stand alone. First sentence must summarize behavior. 49. Omit the subject in summary descriptions. Not: “This method clears the foo.” Instead: “Clears the foo.” 60. Describe why the code is doing what it’s doing, not what it does.

(21) Programming conventions 71. Make all fields private. 74. Encapsulate enumerations as classes. No! In Java 5, use the enum class! 75. Always use block statements in control flow constructs. Not: if (foo) bar( ); Instead: if (foo) { bar( ) };

(22) Programming conventions 79. Use equals, not ==, to test for equality. 80. Always construct objects in a valid state. 82. Use nested constructors to eliminate redundant code. (Others) Do not use wildcards in import. Not: import java.util.*; Instead: import java.util.Set; (will be enforced by Checkstyle.)

(23) Programming conventions 83. Use unchecked, runtime exceptions to report serious unexpected errors that may indicate an error in the program’s logic. 84. Use checked exceptions to report errors that may occur, however rarely, under normal program operation. 85. Use return values to report expected state changes. 87. Do not silently absorb a runtime or error exception.

(24) Packaging conventions 104. Place types that are commonly used, changed, and released together into the same package. Observe build packaging conventions for this class (see upcoming lecture).

(25) Checkstyle Automated support for certain coding style issues including: variables, parameters, and methods conform to regular expressions. lines do not exceed a specified length. JavaDocs are present and provide parameter and return type information. We will get to Checkstyle in the Automated QA lecture.

(26) Eclipse Source Formatter Can save you time by automatically: indenting correctly formatting braces inserting JavaDoc *templates* Issues: Eclipse format settings are not correct “out of the box”. You must manually configure them. Eclipse creates JavaDoc templates, but they are not (typically) useful documentation. You must replace template text even though it will pass Checkstyle!

(27) ICS SE Coding Standards

(28)