C Tutorial/Language/Convention

Материал из C\C++ эксперт
Перейти к: навигация, поиск

Clarity

<source lang="cpp">/* poor programming practice */

   temp = box_x1; 
   box_x1 = box_x2;   
   box_x2 = temp; 
   temp = box_y1; 
   box_y1 = box_y2;   
   box_y2 = temp;</source>

Indentation and Code Format

<source lang="cpp">while (! done) {

       printf("Processing\n");    
       next_entry();  
   }  
   if (total <= 0) {  
       printf("You owe nothing\n");   
       total = 0; 
   } else {   
       printf("You owe %d dollars\n", total); 
       all_totals = all_totals + total;   
   }</source>