วันอังคารที่ 15 กุมภาพันธ์ พ.ศ. 2554

15 Good Programming Habits(คุณลักษณ์ของโปรแกรมเมอร์ที่ดี 15 ประการ)

15 Good Programming Habits



คุณลักษณ์ของโปรแกรมเมอร์ที่ดี 15 ประการ
 
http://ezinearticles.com/?15-Good-Programming-Habits&id=45825


1. Before sitting down for coding, you must have formal or a paper-napkin design of the solution to be coded. Never start coding without any design unless the code is trivial one.
(ก่อนที่จะมานั่งเขียนโปรแกรมคุณจะต้องมีการออกแบบที่เป็นทางการโดยจะต้องทำโค๊ตลงกระดาษไม่มีการเริ่มต้นเขียนโปรแกรมใดที่ไม่มีการออกแบบ ยกเว้น กรณีที่โค๊ตที่ง่ายๆ)

2. Good code documentation is as important as good knowledge of a programming language. Write brief logic for each major block of your code as comments in source code file itself. Its good to mention creation and modification dates of your program along-with why modification was required.

3. Maintaining versions of your program is another important task. Some present-day programming tools already have a built-in version management. Whenever you make any change to your program, they save its copy as.bak file.

My approach is to maintain 3 versions of a program. Say, I have a file program.c which is used by other project team members also. I copy this file as program.c.old as backup and make another copy as program.c.wrk where I do modifications. When modifications are successfully compiled, replace program.c with.wrk file.

You can also append a date or some explanation phrase to your program versions like program260505.c or programReadFnWrking.c.

4. If your project contains multiple source files then maintain a README file stating purpose of each source files, data files, intermediate and log files (if any). You may also mention the compilation and execution steps.

5. Ever wondered why your IF statement is not working as it should do. May be your are using single equal i.e. "=" instead of "==" in the condition check. A good approach is to write condition in reverse order. So, your condition should read something like this:

if ( 10==i).... So, if you put single equal sign by mistake then it will be detected at compilation time only as an error.

6. While using loops and conditional statements, always first put closing braces corresponding opening braces and then write the inner statements i.e.


1) for(int i=0;i<10;i++)


2) {


4) printf("i=%dn",i);


3) }

The numbers at the starting of each line indicate sequence of writing loop code.

7. Avoid using magic numbers. For example, instead of writing

circleArea = 3.14 * pow(radius,2);

use following code:

#define PI 3.14

circleArea = PI * pow(radius,2);

8. Use meaningful variable and function names. For e.g. instead of using 'r' use 'radius' to represent radius of a circle. Similarly, function name 'calculateArea' is better than any cryptic short name. In a hurry, we may use short variable names but the time saved leads to double wastage of time later when you guess for what that short variable name stands for.

9. Using print statements for later debugging is a good habit. But, removing them when final code is ready is, sometimes, a risky task. So, make a function that displays debugging information passed to it. When your final version is ready, simply comment the internals of this function. So, this requires changes only at one place.

10. Once you are done with coding, start optimizing your code. Some of the variables you declared earlier may not be of use at this stage. Similarly, statements which are not loop dependent can be moved out of loop block. Sound knowledge of compiler can also help in optimizing the code further.

11. With good knowledge of your operating system and hardware, you can improve performance of your program in terms of resource requirements etc.

12. Always indent your code for clarity and easy readability.

13. You will also like the idea of organizing project files in into various folders like SOURCE, HEADERS, MAKE, EXES etc.

14. Study the code written by others. This will bring to you new programming techniques and what approach they have followed for the task for which you have also coded.

15. Last but not least important, take backup of your source-code files so that your effort don't go waste if hard-disk crashes or a similar mishappening occurs.

Al-katib has obtained M.Tech. (Comp Sc & Engg) degree from Indian Institute of Technology, Delhi (INDIA). His areas of interests are distributed computing, computer graphics and Internet Technologies. Currently, he is involved in Software Project Planning, Development and Management. His other interests include writing for magazines and contributing utility softwares on Magazine's CDs. He also have flair for teaching computer science with new teaching methodologies. His web-page URL is http://www.computer-science-notes.blogspot.com

Article Source: http://EzineArticles.com/?expert=Al_Kaatib

วันพฤหัสบดีที่ 3 กุมภาพันธ์ พ.ศ. 2554

ความรู้เกี่ยวกับ การเขียนโปรแกรมภาษาซี เบื้องต้น

Blogger Buzz: Express yourself with the Blogger Template Designer

ปรับแต่ง Blogger Template Designer


ตัวอย่าง โค๊ด ภาษาซี(C) | คำนวณภาษีอย่างง่ายมาก

คำนวณภาษีอย่างง่าย


#include <stdio.h>
void main(){

    float commiss,sales;
    printf("\t\tProgram Total sales.\n");
    printf("\t\tInsert You's Total sales:");
    scanf("%f",&sales);
    printf("\t\t%You's Total sales.: %.2lf\n",sales);
    if(sales>=25000){
        commiss=(sales*10)/100;
        printf("\t\tYou's sales commission.: %.2f",commiss);
    }else if(sales<25000&&sales>=10000){
        commiss=(sales*7)/100;
        printf("\t\tYou's sales commission.: %.2f",commiss);
    }else{
        commiss=0;
        printf("\t\tYou's sales commission.: %.2f",commiss);

    }

}

ตัวอย่าง โค๊ด ภาษาซี(C) | คูณเลขสองตัวแล้วหาตัวที่หารลงตัว

ตัวอย่าง โค๊ด ภาษาซี(C)

#include <stdio.h>
          void main(){
                       int a,b,over,mod;
                                 printf("\t\tProgram Multiply number 2 digit.\n");
                                 printf("\n");
                                 printf("\t\t\tInsert number1:");
                                 scanf("%d",&a);
                                 printf("\t\t\tInsert number2:");
                                 scanf("%d",&b);
                                 over=a/b;
                                 mod=a%b;
                                 if(mod==0){
                                        printf("\t\t\tInput %d and %d\n",a,b);
                                        printf("\t\t\t%d X %d = %d\n",b,over,a);
                                 }else{
  printf("%d Can't multiply's %d . becuase %d Can't multiply with anynumber result is %d .\n",b,a,b,a);
          }
}

ฝึกฝนและพัฒนาการเขียนโปรแกรมภาษาซี C

ฝึกฝนและพัฒนาการเขียนโปรแกรมภาษาซี C 
( Introduction to C Programming)
           การพัฒนาโปรแกรมคอมพิวเตอร์  เขียนโปรแกรมด้วยตัวเอง เพื่อให้มีผู้ที่สนใจนำไปใช้งาน และเพิ่มประสิทธิ์ภาพในการทำงาน และ ความสะดวกสบายๆ ต่างๆมากขึ้น ว่าไปแล้วนักโปรแกรมเมอร์เหล่านี้ ก็ไม่แตกต่างจากผู้ที่ปิดทองหลังพระมากนัก เพราะหลายๆ โปรแกรมที่มีให้ใช้งานกันในปัจจุบัน จะมีใครทราบบ้างไหมว่า ผู้เขียนโปรแกรมเหล่านั้นมีใครกันบ้าง ดังนั้น ผู้ที่คิดจะก้าวมาเป็นนักพัฒนาโปรแกรมมืออาชีพ คงต้องอาศัยใจรักที่จะอยากจะพัฒนา และฝึกฝนฝืมือในการเป็นโปรแกมเมอร์มืออาชีพมาเป็นอันดับหนึ่ง สำหรับบทความนี้จากผู้เขียน Tickcomsci การพัฒนาโปรแกรมในภาษา C ความรู้และความเข้าใจที่จำเป็นต่อการเป็นโปรแกรมเมอร์มืออาชีพในอนาคต เราลองเริ่มมาเรียนรู้กันอย่างคร่าวๆ กันเลยล่ะกัน โดยผู้

เขียนจะอธิบายเป็นตอนๆ ทั้งหมด 8 ตอนด้วยกันได้แก่
 
1. พื้นฐานโปรแกรมภาษา C (Introduction to C Programming)
2. การเขียนโปรแกรมทางเลือก (Selection Structures)
3. การเขียนโปรแกรมแบบ วนซ้ำ (Repetition & Loop)
4. ฟังก์ชัน และการเขียนโปรแกรมแยกเป็นโมดูล (Functions & Modular Programming)
5. ตารางอาเรย์ (Arrays)
6. ตัวแปรพอยเตอร์ (Pointers)
7. ตัวแปรสตริง (String)
8. โครงสร้างสตักเจอร์ (Structure)



แนะนำสำหรับการเริ่มต้นใช้ Program CODEBLOCKS
 การศึกษาผ่านทางวีดีโอ เป็นอีกวิธีที่ช่วยให้ผู้ศึกษา จดจำและเข้าใจได้ดีอีกวิธีหนึ่งครับ.