SlideShare une entreprise Scribd logo
1  sur  62
Coding Guideline 報告人: Nelson  Chuang 部  門: DC
簡報大綱 ,[object Object],[object Object],[object Object],[object Object]
簡報大綱 ,[object Object],[object Object],[object Object],[object Object]
什麼是好的程式碼  ? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
重要原則  ,[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
寫碼習慣 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
簡報大綱 ,[object Object],[object Object],[object Object],[object Object]
較佳的編碼方式 ,[object Object],[object Object],[object Object],[object Object]
何謂 重 構 ,[object Object],[object Object],[object Object],[object Object]
何謂 預 構 ,[object Object],[object Object]
[object Object],Refactor Sub printOwing() printBanner() ‘ print details Console.WriteLine(“name:”&_name) Console.WriteLine(“amount”& getOutstanding()) End Sub Refactoring 前 Sub printOwing() printBanner() printDetails(getOutstanding()) End Sub Sub printDetails (ByVal outstanding As double) Console.WriteLine(“name:”&_name) Console.WriteLine(“amount” & outstanding) End Sub Refactoring 後
[object Object],Refactor Function getPayAmount() As Double Dim result As Double lf_isDead Then result=deadAmount() Else lf_isSeparated Then result=separatedAmount() Else lf_isRetired Then result=retiredAmount() Else result=normalPayAmount() End lf End lf End lf Return result End Function Refactoring 前 Function getPayAmount() As Double lf_isDead Then Return deadAmount() End lf lf_isSeparated Then Return separatedAmount() End lf lf_isRetired Then Return retiredAmount() End lf Return normalPayAmount() End Function Refactoring 後
[object Object],Refactor Function disabilityAmount() As Double lf_seniority < 2 Then Return 0 End lf lf_monthsDisabled > 12 Then Return 0 End lf lf_isPartTime Then Return 0 End lf ‘ compute the disability amount End Function Refactoring 前 Function disabilityAmount() As Double lf isNotEligableForDisability() Then Return 0 End lf ‘  compute the disability amount End Function  Refactoring 後
[object Object],Refactor lf is SpecialDeal() Then total = price * 0.95 send() Else total = price * 0.98 send() End lf Refactoring 前 lf is SpecialDeal()  total = price * 0.95 Else total = pirce * 0.98 End lf Send() Refactoring 後
[object Object],Refactor lf Date.before(SUMMER_START) Or Date.after(SUMMER_END) Then charge = quantity * _winterRate + _winterServiceCharge Else charge = quantity * _summerRate End lf Refactoring 前 lf notSummer(date) Then charge = winterCharge(quantity) Else charge = summerCharge(quantity) End lf Refactoring 後
[object Object],Refactor Function lastReading() As Object Return readings.lastElement() End Function Refactoring 前 Function lastReading() As Reading Return CType(readings.lastElement(), Reading) End Function Refactoring 後
Refactor ,[object Object],Class Class 1 Public _name As String End Class Refactoring 前 Class Class 1 Private _name As String Public Function getName() As String Return _name End Function Public Sub setName(ByVal arg As String) _name = arg End Sub End Class Refactoring 後
Refactor ,[object Object],Function getRating() As lnteger Return llf(more ThanFiveLateDeliveries(), 2, 1) End Function Function more ThanFiveLateDeliveries() As Boolean Return_numberOfLateDeliveries > 5 End Function Refactoring 前 Function getRating() As lnteger Return llf(_numberOfLateDeliveries > 5, 2, 1) End Function Refactoring 後
[object Object],Refactor Dim basePrice As Double = anOrder.basePrice() Return (basePrice > 1000) Refactoring 前 Return anOrder.basePrice() > 1000 Refactoring 後
[object Object],Refactor If platform.ToUpper().lndexOf(“MAC”) > -1 And _ browser.ToUpper().lndexOf(“IE”) > -1 And _ wasInitialized() And resize > 0 Then ‘  do something End If Refactoring 前 Dim isMacOs As Boolean = platform.ToUpper().IndexOf(“MAC”) > -1 Dim is IE Browser As Boolean = browser.ToUpper().IndexOf(“IE”) > -1 Dim was Resized As Boolean = Resize > 0 If isMacOs && isIEBrowser && wasInitialized() && wasResized Then ‘  do something End If Refactoring 後
[object Object],Refactor Function getExpenseLimit() As Double ‘ should have either expense limit or a primary  project return IIF(_expenseLimit !=NULL_EXPENSE,_expenseLimit,_ _primaryProject.getMemberExpenseLimit()) End Function Refactoring 前 Function getExpenseLimit() As Double Debug.Assert(_expenseLimit != NULL_EXPENSE Or _primaryProject != null) return IIF(_expenseLimit != NULL_EXPENSE, _expenseLimit, _ _primaryProject.getMemberExpenseLimit()) End Function Refactoring 後
[object Object],Refactor Dim newStart As Date Time = New Date Time(previous End.Year(), _ previous End.Month(), previousEnd.Day() + 1) Refactoring 前 Dim newStart As DateTime = nextDay(previousEnd) Private Shared Function nextDay(ByVal arg As DateTime) As DateTime Return New DateTime(arg.Year(), arg.Month(), arg.Day() + 1) End Function Refactoring 後
[object Object],Refactor Dim low As Integer = daysTempRange().getLow() Dim high As Integer = daysTempRange().getHigh() withinPlan = plan.withinRange(low, high) Refactoring 前 withinPlan = plan.withinRange(daysTempRange()) Refactoring 後
[object Object],Refactor Public Class Manager Inherits Employee Public Sub New(ByVal name As String, ByVal id As String) _name = name _id = id End Sub End Class Refactoring 前 Public Class Manager Inherits Employee Public Sub New(ByVal name As String, ByVal id As String) MyBase.New(name, id) End Sub End Class Refactoring 後
[object Object],Refactor Sub foo() Dim I As Integer = 7 ‘  I is not used here If someCondition Then ‘  i is used only within this block End If ‘  i is not used here End Sub Refactoring 前 Sub foo() If someCondition Then Dim i as integer = 7 ‘  i is used only within this block End If End Sub Refactoring 後
[object Object],Refactor Function discount(ByVal inputVal As Integer, ByVal quantity As Integer, _ ByVal yearToDate As Integer) As Integer If inputVal > 50 Then inputVal-= 2 End If End Function Refactoring 前 Function discount(ByVal inputVal As Integer, ByVal quantity As Integer, _ ByVal yearToDate As Integer) As Integer Dim result As Integer = inputVal If inputVal > 50 Then result -= 2 End If End Function Refactoring 後
[object Object],Refactor If Not item.isNotFound() Then End If Refactoring 前 If item.isFound() Then End If Refactoring 後
[object Object],Refactor Function withdraw(ByVal amount As Integer) As Integer If amount > _balance Then Return -1 Else _balance -= amount Return 0  End If End Function Refactoring 前 Sub withdraw(ByVal amount As Integer) If amount > _balance Then Throw New BalanceException _balance -= amount  End If End Sub Refactoring 後
[object Object],Refactor Function getValueForPeriod(ByVal periodNumber As Integer) As Double Try Return _values(periodNumber) Catch ex As IndexOutOfRangeException Return 0 End Try End Function Refactoring 前 Function getValueForPeriod(ByVal periodNumber As Integer) As Double If periodNumber >= _values.Length Then Return 0 End If Return _values(periodNumber) End Function Refactoring 後
[object Object],Refactor Public Sub countDown(ByVal n As Integer) If n = 0 Then Return End If waitASecond() countDown(n - 1) End Sub Refactoring 前 Public Sub countDown(ByVal n As Integer) While n > 0 waitASecond() n -= 1 End While End Sub Refactoring 後
[object Object],Refactor Sub printValues() Dim i As Integer For i = 0 To people.Length - 1 Console.WriteLine(people(i).name & “ has salary “ & people(i).salary) Next End Sub Refactoring 前 Sub printValues(ByVal outfile As PrintStream) Dim i As Integer For i = 0 To people.Length - 1 outfile.printIn(people(i).name & “ has salary “ & people(i).salary) Next End Sub Refactoring 後
簡報大綱 ,[object Object],[object Object],[object Object],[object Object]
效能 (1) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
效能 (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASP  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASP  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASP  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASP.NET  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
ASP.NET  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
效能計數器重點觀察指標 計數器 說 明 # of Exceptions Thrown 引發例外的總次數 效能物件 .NET CLR Exceptions # Gen x Collections Gen x 物件被 Garbage Collector 回收的次數 .NET CLR Memory % Time In GC ASP.NET 程式花在回收物件 的時間比例 .NET CLR Memory Promoted Memory from Gen X Gen X 物件沒有被回收,而升級成為 Gen Y 物件所佔用的記憶體量 .NET CLR Memory Available MBytes 可用的記憶體數 ( 和 Memory Leak 有關 ) Memory % Processor Time 程式執行花掉的 CPU 時間比例 Process % Processor Time CPU 花在執行所有程式的時間比例 Processor User Connections 資料庫的使用者連線數 SQL Server : General Statistics
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object],[object Object],[object Object]
SQL  效能 ,[object Object],[object Object],[object Object]
相關資源 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thank You

Contenu connexe

Tendances

ES5 introduction
ES5 introductionES5 introduction
ES5 introductionotakustay
 
Deferred Execution (延遲執行)
Deferred Execution (延遲執行)Deferred Execution (延遲執行)
Deferred Execution (延遲執行)Zheng-Wei Lin
 
Scala function-and-closures
Scala function-and-closuresScala function-and-closures
Scala function-and-closureswang hongjiang
 
Keep your code clean
Keep your code cleanKeep your code clean
Keep your code cleanmacrochen
 
20131209 ms build_using_task By Anney
20131209 ms build_using_task By Anney20131209 ms build_using_task By Anney
20131209 ms build_using_task By AnneyLearningTech
 
Ecmascript
EcmascriptEcmascript
Ecmascriptjay li
 
Java script closures
Java script closuresJava script closures
Java script closuresskywalker1114
 
LazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHPLazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHPLin Yo-An
 
About closure
About closureAbout closure
About closureotakustay
 
Hello Javascript
Hello JavascriptHello Javascript
Hello JavascriptBaidu, Inc.
 
Php extension开发
Php extension开发Php extension开发
Php extension开发thinkinlamp
 
深入淺出 Web 容器 - Tomcat 原始碼分析
深入淺出 Web 容器  - Tomcat 原始碼分析深入淺出 Web 容器  - Tomcat 原始碼分析
深入淺出 Web 容器 - Tomcat 原始碼分析Justin Lin
 
Programming python - part 1
Programming python - part 1Programming python - part 1
Programming python - part 1Che-Cheng Hsu
 
A Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
A Brief Introduction to Regular Expression with Python 2.7.3 Standard LibraryA Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
A Brief Introduction to Regular Expression with Python 2.7.3 Standard LibraryWen Liao
 

Tendances (20)

ES5 introduction
ES5 introductionES5 introduction
ES5 introduction
 
Ch07
Ch07Ch07
Ch07
 
Deferred Execution (延遲執行)
Deferred Execution (延遲執行)Deferred Execution (延遲執行)
Deferred Execution (延遲執行)
 
Scala function-and-closures
Scala function-and-closuresScala function-and-closures
Scala function-and-closures
 
Keep your code clean
Keep your code cleanKeep your code clean
Keep your code clean
 
20131209 ms build_using_task By Anney
20131209 ms build_using_task By Anney20131209 ms build_using_task By Anney
20131209 ms build_using_task By Anney
 
functional-scala
functional-scalafunctional-scala
functional-scala
 
Python基本資料運算
Python基本資料運算Python基本資料運算
Python基本資料運算
 
Ecmascript
EcmascriptEcmascript
Ecmascript
 
Java script closures
Java script closuresJava script closures
Java script closures
 
LazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHPLazyRecord: The Fast ORM for PHP
LazyRecord: The Fast ORM for PHP
 
About closure
About closureAbout closure
About closure
 
Hello Javascript
Hello JavascriptHello Javascript
Hello Javascript
 
C語言應用前置處理
C語言應用前置處理C語言應用前置處理
C語言應用前置處理
 
Python分支作業
Python分支作業Python分支作業
Python分支作業
 
Php extension开发
Php extension开发Php extension开发
Php extension开发
 
深入淺出 Web 容器 - Tomcat 原始碼分析
深入淺出 Web 容器  - Tomcat 原始碼分析深入淺出 Web 容器  - Tomcat 原始碼分析
深入淺出 Web 容器 - Tomcat 原始碼分析
 
Programming python - part 1
Programming python - part 1Programming python - part 1
Programming python - part 1
 
A Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
A Brief Introduction to Regular Expression with Python 2.7.3 Standard LibraryA Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
A Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
 
建置Python開發環境
建置Python開發環境建置Python開發環境
建置Python開發環境
 

Similaire à Coding guideline

1 C入門教學
1  C入門教學1  C入門教學
1 C入門教學Sita Liu
 
PHPUnit + Xdebug 单元测试技术
PHPUnit + Xdebug 单元测试技术PHPUnit + Xdebug 单元测试技术
PHPUnit + Xdebug 单元测试技术hoopchina
 
第六章 函數與巨集
第六章 函數與巨集第六章 函數與巨集
第六章 函數與巨集shademoon
 
少年科技人雜誌 2015 年八月
少年科技人雜誌 2015 年八月少年科技人雜誌 2015 年八月
少年科技人雜誌 2015 年八月鍾誠 陳鍾誠
 
Sql培训 (1)
Sql培训 (1)Sql培训 (1)
Sql培训 (1)jhao niu
 
The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)jeffz
 
潜力无限的编程语言Javascript
潜力无限的编程语言Javascript潜力无限的编程语言Javascript
潜力无限的编程语言Javascriptjay li
 
异步编程与浏览器执行模型
异步编程与浏览器执行模型异步编程与浏览器执行模型
异步编程与浏览器执行模型keelii
 
Slide 20120322
Slide 20120322Slide 20120322
Slide 20120322Yubei Li
 
Java script closures
Java script closuresJava script closures
Java script closuresskywalker1114
 
Sicmutils 介紹:Scmutils 的 Clojure 版函式庫
Sicmutils 介紹:Scmutils 的 Clojure 版函式庫Sicmutils 介紹:Scmutils 的 Clojure 版函式庫
Sicmutils 介紹:Scmutils 的 Clojure 版函式庫睿麒 王
 
改善程序设计技术的50个有效做法
改善程序设计技术的50个有效做法改善程序设计技术的50个有效做法
改善程序设计技术的50个有效做法crasysatan
 
My visual basic入門指引 5
My visual basic入門指引 5My visual basic入門指引 5
My visual basic入門指引 5Xavier Chou
 
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫Justin Lin
 

Similaire à Coding guideline (20)

1 C入門教學
1  C入門教學1  C入門教學
1 C入門教學
 
PHPUnit + Xdebug 单元测试技术
PHPUnit + Xdebug 单元测试技术PHPUnit + Xdebug 单元测试技术
PHPUnit + Xdebug 单元测试技术
 
第六章 函數與巨集
第六章 函數與巨集第六章 函數與巨集
第六章 函數與巨集
 
少年科技人雜誌 2015 年八月
少年科技人雜誌 2015 年八月少年科技人雜誌 2015 年八月
少年科技人雜誌 2015 年八月
 
Sql培训 (1)
Sql培训 (1)Sql培训 (1)
Sql培训 (1)
 
第4章函数
第4章函数第4章函数
第4章函数
 
The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)The Evolution of Async Programming (GZ TechParty C#)
The Evolution of Async Programming (GZ TechParty C#)
 
潜力无限的编程语言Javascript
潜力无限的编程语言Javascript潜力无限的编程语言Javascript
潜力无限的编程语言Javascript
 
Ppt 120-126
Ppt 120-126Ppt 120-126
Ppt 120-126
 
Ppt 120-126
Ppt 120-126Ppt 120-126
Ppt 120-126
 
异步编程与浏览器执行模型
异步编程与浏览器执行模型异步编程与浏览器执行模型
异步编程与浏览器执行模型
 
Python變數與資料運算
Python變數與資料運算Python變數與資料運算
Python變數與資料運算
 
Slide 20120322
Slide 20120322Slide 20120322
Slide 20120322
 
Java script closures
Java script closuresJava script closures
Java script closures
 
Sicmutils 介紹:Scmutils 的 Clojure 版函式庫
Sicmutils 介紹:Scmutils 的 Clojure 版函式庫Sicmutils 介紹:Scmutils 的 Clojure 版函式庫
Sicmutils 介紹:Scmutils 的 Clojure 版函式庫
 
改善程序设计技术的50个有效做法
改善程序设计技术的50个有效做法改善程序设计技术的50个有效做法
改善程序设计技术的50个有效做法
 
My visual basic入門指引 5
My visual basic入門指引 5My visual basic入門指引 5
My visual basic入門指引 5
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
getPDF.aspx
getPDF.aspxgetPDF.aspx
getPDF.aspx
 
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
Java SE 8 的 Lambda 連鎖效應 - 語法、風格與程式庫
 

Coding guideline

  • 1. Coding Guideline 報告人: Nelson Chuang 部 門: DC
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50. 效能計數器重點觀察指標 計數器 說 明 # of Exceptions Thrown 引發例外的總次數 效能物件 .NET CLR Exceptions # Gen x Collections Gen x 物件被 Garbage Collector 回收的次數 .NET CLR Memory % Time In GC ASP.NET 程式花在回收物件 的時間比例 .NET CLR Memory Promoted Memory from Gen X Gen X 物件沒有被回收,而升級成為 Gen Y 物件所佔用的記憶體量 .NET CLR Memory Available MBytes 可用的記憶體數 ( 和 Memory Leak 有關 ) Memory % Processor Time 程式執行花掉的 CPU 時間比例 Process % Processor Time CPU 花在執行所有程式的時間比例 Processor User Connections 資料庫的使用者連線數 SQL Server : General Statistics
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.

Notes de l'éditeur

  1. 這是我們的簡報大綱
  2. 這是我們的簡報大綱
  3. 這是我們的簡報大綱
  4. 這是我們的簡報大綱
  5. 這是我們的簡報大綱