Comic
Fay's Diary Comic
Kanji Transformer Series
Our Android Apps
Paper Toy
Animation
Dharma Cartoon
Figure Photo Collection
Flash Game
Embedded Systems
Old Work
Toy & Gadget
Game & Software
About Us
Links
Ataya's Embedded Systems Blog
Green Tea Story
Play with BeagleBoneBlack
Studio Wallpaper
Studio Wallpaper
The Sky Flower & The Temple Dog
Written by : Ataya P
Date : 30 June 2007
Language : Thai
มาแล้วครับ
-> Prefer int over char and short
สำหรับภาษา
char sum_char(char a,char b) int sum_int(int a,int b)
{ char c; { int c;
c=a+b; ====> c=a+b;
return c; return c;
} }
-> Define lightweight constructors
เราควรจะกำ หนดให้ constructor
มีขนาด เล็กที่สุด เท่าที่จะท ำได้ เพราะการสร ้าง Object
ทุกครั้ จะต้องเกี ยวข้องกับ construcor ทุกครั้ง การทำการปร ับแต่ง
constructor จะทำให้ได้ การทำงานที ่เร็วขึ้นม ากทีเดียว
-> Prefer initialization over assigment
เราควรทำกา ร initial
ค่าให้ก บตัวแปรมา กว่าการ assign ค่าในภายหล ัง
void foo( ) void foo_optimize( )
{ complex c; {
c=(complex) 5;   ;   ;   ;   ;
======>
  ; complex c=5;
  ; }
  ;   ;   ;   ;   ;   ;   ;   ;
}
->Use constructor initialization list
ควรใช้ constructor initialization list ในการ initial ตัวแปร การทำ assignment ไว้ใน constructor body จะทำให้ป ะสิทธิภาพ ดลง
Employee :: Employee(string name,string desig) Employee :: Employee(string name,string desig) :   ;   ;   ;
  ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;   ;
m_name(name),m_desig(desig)
{ m_name = name; ======> {
เราควรจะกำ
-> Prefer initialization over assigment
เราควรทำกา
void foo( ) void foo_optimize( )
{ complex c; {
c=(complex) 5;  
 
->Use constructor initialization list
ควรใช้ constructor initialization list ในการ initial ตัวแปร การทำ assignment ไว้ใน constructor body จะทำให้ป
Employee :: Employee(string name,string desig) Employee :: Employee(string name,string desig) :  
 
{ m_name = name; ======> {
m_desig=desig;
}
}
-> In-line 1 to 3 line functions
ควรขยาย function ขนาดเล็ก( 1,3 บรรทัด)ให้ ป็น
function แบบ In-line(เขียนโค ดตรงๆไม่ต องเรียกฟั ก์ชัน)เพื่ อขจัด
overhead ของการ call function และ parameter ที่ต้องส่ง ผ่าน
อย่าง รก็ดีการใ ้วิธี in-line function
นี้กับฟ ังก์ชันอื่ นๆที่มีขนา ดใหญ่อาจให ้ผลที่เป็น ลบมากกว่า
นื่องจากก รเพิ่มขึ้ ของโด้ด
int func(int y) int func(int y)
{ { int temp=0;
return pred(y)+pred(0)+pred(y+ 1);
======>
if(y==0)
temp+=0; else temp+y;
}   ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ; :
:
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ; return temp;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ;
  ; }
-> In-line 1 to 3 line functions
ควรขยาย function ขนาดเล็ก( 1,3 บรรทัด)ให้
int func(int y) int func(int y)
{ { int temp=0;
return pred(y)+pred(0)+pred(y+
}  
:
 
 
- Login to post comments
Custom Search
