良好的代碼書寫格式:適時的代碼縮進

 

剛開始看到這樣的代碼時候,第一個瞬間是有點將其代碼對齊的衝動,好吧,也許是有點強迫症。ide

  
  
  
  
  1. // start the slide up animation 
  2. [UIView beginAnimations:nil context:NULL]; 
  3.     [UIView setAnimationDuration:0.3]; 
  4.  
  5.     // we need to perform some post operations after the animation is complete 
  6.     [UIView setAnimationDelegate:self]; 
  7.  
  8.     self.pickerView.frame = pickerRect; 
  9.  
  10.     // shrink the table vertical size to make room for the date picker 
  11.     CGRect newFrame = self.tableView.frame; 
  12.     newFrame.size.height -= self.pickerView.frame.size.height; 
  13.     self.tableView.frame = newFrame; 
  14. [UIView commitAnimations]; 

 但是在同一頁面上,又看到了這樣的一處相似的代碼。post

我才瞬間意思到什麼。由於這些代碼是官方的實例代碼。學習

良好的代碼書寫格式除了命名以外,必要的格式縮進,可以良好的表達一段功能邏輯代碼的開始和結束。spa

在書寫代碼的時候,除了if,for語句等的縮進,這種獨立功能的寫法,委實是比較好的方式,值得好好體會學習。orm

相關文章
相關標籤/搜索