日期:2014-05-20  浏览次数:20772 次

全球前十强,年薪15万的面试题
程序风格的作用主要是使代码容易阅读。代码应该时清楚的和简单的-------具有直截了当的逻辑、自然的表达式、通行的语言使用方式、有意义的名字和有帮助作用的注释等,应该避免耍小聪明,绝不使用非正规的结构。  
下面的代码具有很多缺陷,请从风格的角度评论并改正下面各个代码片断:  
/*       return       SUCCESS       */  
return       SUCCESS;  

----------------------------------------------------  
if       (!(block_id       <       actblks)       &brvbar;   &brvbar;       !(block_id       > =       unblocks))  

-----------------------------------------------------  
int       count       =       0;  
while       (count       <       total)       {  
                count++;  
                if       (this.getName(count)       ==       nametable.userName())       {  
                                                return       (true);  
                                }  
}  

-------------------------------------------------------  
i=       0;  
while(i       <=       n-1)  
                array[i++]       =       1.0;  

----------------------计算n的阶乘---------------------------------  
int       factorial(int       n)      
{  
                int       fac;  
                fac       =       1;  
                while       (n--)      
                                fac       *=       n;  
                return       fac;  
}  

-----------C函数,但是Java开发人员也可以做-----------------------------------------  
if       (i       >       j)  
                printf(“%d       is       greater       than       %d.\n”,       i,       j)  
else  
                printf(“%d       is       smaller       than       %d.\n”,       i,       j)  

--------------------------------------       C语言--------------------------------------------  
#define       MAX(a,       b)           a   > b?       a:b