1 written by BAGE 날짜 JAVA Coding Pattern 코딩 규칙 2010.08.03 박혜웅.

Slides:



Advertisements
Similar presentations
Variables in C Amir Haider Lecturer.
Advertisements

Coding Standards for Java An Introduction. Why Coding Standards are Important? Coding Standards lead to greater consistency within your code and the code.
1 CS1001 Lecture Overview Java Programming Java Programming.
LESSON 3 - Identifiers JAVA PROGRAMMING. Identifiers All the Java components —classes, variables, and methods— need names. In Java these names are called.
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.
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.
Chapter 2: Introduction to C++.
Agile Lab 2008a Armin B. Cremers, Günter Kniesel, Pascal Bihler, Tobias Rho, Marc Schmatz, Daniel Speicher Sommersemester 2008 R O O T S Coding standards.
The Ruby Programming Language
3.1 Documentation & Java Language Elements Purpose of documentation Assist the programmer with developing the program Assist other programers who.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
(1) Coding Standards Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
Simple Programs from Chapter 2 Putting the Building Blocks All Together (corresponds with Chapter 2)
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
CSE 219 Computer Science III Testing. Testing vs. Debugging Testing: Create and use scenarios which reveal incorrect behaviors –Design of test cases:
07 Coding Conventions. 2 Demonstrate Developing Local Variables Describe Separating Public and Private Members during Declaration Explore Using System.exit.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
CSC204 – Programming I Lecture 4 August 28, 2002.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Computer Science 101 Introduction to Programming.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Style Guidelines. Why do we need style?  Good programming style helps promote the readability, clarity and comprehensibility of your code.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
Java Coding Standards and Best Practices Coding Standards Introduction: After completing this chapter, you will able to keep your code up to standards.
Chapter 2: Java Fundamentals
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Java development environment and Review of Java. Eclipse TM Intergrated Development Environment (IDE) Running Eclipse: Warning: Never check the “Use this.
Code Conventions Tonga Institute of Higher Education.
Copyright Curt Hill Variables What are they? Why do we need them?
Even More Java. Java Packages What is a package? Definition: A package is a grouping of related types providing access protection and name space management.
Java Class Structure. Class Structure package declaration import statements class declaration class (static) variable declarations* instance variable.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Chapter 2: Introduction to C++. Outline Basic “Hello World!!” Variables Data Types Illustration.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
What Is a Package? A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
------TAO, MARKUS Project IT. JavaDoc ‣ JavaDoc is a standard method of commenting source code (interfaces, classes, methods, instances variables). ‣
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Java Programming Fifth Edition
Yanal Alahmad Java Workshop Yanal Alahmad
Variables and Arithmetic Operators in JavaScript
University of Central Florida COP 3330 Object Oriented Programming
Statements, Comments & Simple Arithmetic
2.1 Parts of a C++ Program.
Variables in C Topics Naming Variables Declaring Variables
An overview of Java, Data types and variables
Unit-1 Introduction to Java
Documentation and Style
Anatomy of a Java Program
Beginning Style 27-Feb-19.
Tonga Institute of Higher Education
Chap 2. Identifiers, Keywords, and Types
Tonga Institute of Higher Education
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

1 written by BAGE 날짜 JAVA Coding Pattern 코딩 규칙 박혜웅

2 written by BAGE 이 문서는 권고안의 내용중 중요한 부분과 개인경험을 통해 정리하였다. Sun 의 권고안 – – 권고안을 따르는 Eclipse default formatter 를 기준으로 한다. Code Conventions-Basic

3 written by BAGE File Type –.java (UTF-8) –.class –README 설명을 위한 텍스트 파일 (UTF-8) Beginning Comments –?? Class and Interface Declarations –Variables, Method public, protected, private 순서로 나열 Indentation –tabs only (4 spaces), Eclipse default formatter 와 동일 Line Length –80 ~ 150 ( 모니터에 맞게 ) Wrapping Lines ( 줄 바꿈 ) –Eclipse default formatter 와 동일 Code Conventions

4 written by BAGE Block Comments, Single-Line comments, Trailing Comments (/* */) –Do not use for commenting code. Search 명령의 검색결과가 소스인지 코멘트인지 불분명하므로. End-Of-Line Comments (//) –Use for commenting code. Code Conventions-Comments //if (bar > 1 ) { // // // To do: //... //} // else // return false;

5 written by BAGE One declaration per line –Eclipse default formatter 와 동일 Avoid declarations that hide declaratioins. – 동일한 변수명을 가능한 사용하지 말아라 – 단, Constructor, Setter, Getter 는 예외다. Code Conventions-Declarations int level;// Good int size;// Good int level, size;// Avoid int count;... func() { if (condition) { int count;// Avoid... int count;... func() { if (...) { int countSome;... int count;... setCount(int count) { if (...) { this.count=count;...

6 written by BAGE Class and Interface Declarations –Eclipse default formatter 와 동일 –Methods are separated by blank line Code Conventions-Declarations class Sample extends Object { int ivar1; int ivar2; Sample(int i, int j){ ivar1=i; ivar2=j; } int emptyMethod() {}... }

7 written by BAGE Simple Statements –Each line should contain at most one statement –Do not use the comma operator return Statements –Use simple expression –Do not use ternary expression (?) Code Conventions-Statements argv++; argc--; argv++; argc--;// Avoid System.out.println("error"); System.exit(1); System.out.println("error"), System.exit(1);// Avoid return: myDisk.size(); return (size ? size : defaultSize);// Avoid if( size > 0 ) { return size; } return 0; return;

8 written by BAGE if-else Statements –if statements always use braces {}. for, while Statements –An empty for, whlie statement should have the following form Blank Lines, Blank Spaces –Eclipse default formatter Code Conventions-Statements, Blank if ( condition ) { statement; } if ( condition ) // Avoid statement; for ( initialization; condition; update ); while ( condition ); for ( initialization; condition; update ) {} ; //Avoid while ( condition ) {}; //Avoid

9 written by BAGE Java Project(?), Classes, Interfaces Naming –Should be noun with the first letter capitalized. –Avoid acronyms( 머리글자어 ) and abbreviatioins( 약어 ) except URL, HTML... –Example class URLEncoder; interface Storing; –Use Whole words. –Example class MatrixCalculation; // OK class MatCalc; // AVOID! Methods –Should be verbs with the first letter lowercase. –Omit class or interface name. –Example MatrixCalculation calculation = new MatrixCaculation(); calculation.getData(); // OK calculation.getMatrixCalculationData(); // AVOID! Code Conventions-Naming

10 written by BAGE Variables –Should be noun with the first letter lowercase. –If instance variable(public, protected, private, default), always use keyword “this”. –Example private long instanceVariable; this.instanceVariable = 10L; // OK instanceVariable = 10L; // AVOID! –Avoid acronyms( 머리글자어 ) and abbreviatioins( 약어 ) –Example BufferedReader bufferedReader = new BufferedReader(); // OK BufferedReader reader = new BufferedReader(); // OK BufferedReader br = new BufferedReader(); //AVOID! –if name is so long, can be shortten. –Example int difference; // OK int diff; // OK int d; // AVOID Code Conventions-Naming

11 written by BAGE Constants (static final) –Should be all uppercase with words separated by underscores(_). –Ends with noun. –Example static final int MIN_WIDTH = 4; // OK static final int minWidth = 4; // AVOID! Code Conventions-Naming

12 written by BAGE Referring to Class Variables and Methods –Avoid using an object to access a static variable or method. –Example AClass.classMethod(); // OK anObject.classMethod(); // AVOID! Variable Assignments –Avoid assigning several variables to the same value in a single statement. –Example fooBar.fChar = barFoo.lchar = ‘c’; //AVOID! d = (a = b + c) + r; //AVOID! Parenthese( 소괄호 ) –Use parentheses liberally. –Example if(a == b && c == d) //AVOID! if((a ==b) && (c == d)) // OK Code Conventions-Programming