Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 39 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
39
Dung lượng
291,99 KB
Nội dung
ソフトウェアテスト [9] プログラミング技術 Software Testing [9] Programming Tips and Techniques あまん ひろひさ ひろひさ 阿萬 裕久 裕久( AMAN Hirohisa ) aman@ehime-u.ac.jp (C) 2007-2022 Hirohisa AMAN Positioning of programming The role of programming is to realize “P rogram specification” on a computer Program specification programming Make something like this human world The key is how accurately it can be described (C) 2007-2022 Hirohisa AMAN program Formal execution instructions computer world The computer faithfully executes the contents of the program Software development ≠ program program ming People tend to think that “Programming is software dev elopment” In the case of small-scale development, requirement s analysis & design are done only in the developer's head, & programming is suddenly started However, this is not enough for Large-scale develop ment Programming skills are important Don't underestimate design and management For example, OS for smartphones: millions of lines or more When printed more than 100,000 sheets of A4 paper (over 10m in height) (C) 2007-2022 Hirohisa AMAN Important thing in programming Writing programs that correctly reflect the sp ecification (error-free) Be careful not to make the mistake (error) of crea ting a bug Write Easy to understand program Idea: “I just need to know myself” Is not good Maintenance is impossible unless the program is u nderstood by others (Even the person who wrote it may not be able to un derstand it after months) (C) 2007-2022 Hirohisa AMAN How to write and make a program Easy to see and understand To prevent mistakes To a simple structure Be environment independent Comment text appropriately Make it easy to change (C) 2007-2022 Hirohisa AMAN (1) Easy to see and understand Indent to visually indicate the beginni ng and end of block To prevent forgetting, Write “{” “ }” at the same time & insert code between it sum = 0; for ( i = 0; i < n; i++ ){ if ( a[i] > ){ sum += a[i]; } } Intentionally add empty lines to appeal to switch printf("%dn", sum); execution contents (C) 2007-2022 Hirohisa AMAN Make variable names meaningful A name that explains what the variables rep resent is desirable However, with a few lines of program, you can immediately understand the meaning If you look at the content (Ex) Variable i on the previous page, etc index, position, count or idx, pos, cnt for short When asking Yes/No, the question form is also used To separate words, use is_empty, hasNext underscore (_) or use capital letters Example: If the set is Example: In the list, the empty 1, Otherwise following node is if present, otherwise (C) 2007-2022 Hirohisa AMAN variable name, function name snake case and camel case snake case Use underscore (_) to connect words Ex: file_name, get_file_size For C language, camel case snake case is often used use capital letters for word breaks Ex: fileName, getFileSize (C) 2007-2022 Hirohisa AMAN Be aware of function and return value in function names A name that indicates what the functi on does and what it returns (example) int get_length (char str[ ]){void move_to (int x, int y){ ・・・文字列の長さを調べるの長さを調べる長さを調べるさを調べる調べるべる ・・・ (x,y) へ移動移動 } } void sort (int array[ ], int length){To separate words, use underscore (_) ・・・ array を調べるソーティング or use capital letters } (C) 2007-2022 Hirohisa AMAN [Exercise 1] Think of a function n ame get help void () leap year int (int year) Copy the contents of an array to another ar ray void (int src[], int dest[], int length) Original (C) 2007-2022 Hirohisa AMAN Copy to 10 length