良好的代码书写格式:适时的代码缩进

 

刚开始看到这样的代码时候,第一个瞬间是有点将其代码对齐的冲动,好吧,也许是有点强迫症。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

相关文章
相关标签/搜索