Скачать презентацию Slide 6 1 Software Engineering Lili ICEC NEFU Скачать презентацию Slide 6 1 Software Engineering Lili ICEC NEFU

3eefd129d17d8b27c46f50e779939f9b.ppt

  • Количество слайдов: 28

Slide 6. 1 Software Engineering Lili ICEC NEFU Slide 6. 1 Software Engineering Lili ICEC NEFU

CHAPTER 6 CODING Slide 6. 2 CHAPTER 6 CODING Slide 6. 2

Overview l l l l Slide 6. 3 Choice of programming language(编程语言的选择) Fourth generation Overview l l l l Slide 6. 3 Choice of programming language(编程语言的选择) Fourth generation languages (第四代编程语言) Good programming practice (良好的编程实践) Coding standards (编码标准) Code reuse (代码重用) Integration (集成) The implementation workflow (实现阶段) The implementation workflow: The Osbert Oglesby case study (实现阶段: Osbert Oglesby实例研究)

6. 1 Choice of Programming Language Slide 6. 4 l The language is usually 6. 1 Choice of Programming Language Slide 6. 4 l The language is usually specified in the contract (合同中通常规定编程语言) l But what if the contract specifies that 4 The product is to be implemented in the “most suitable” programming language l What language should be chosen?

Choice of Programming Language (contd) Slide 6. 5 l Example 4 QQQ Corporation has Choice of Programming Language (contd) Slide 6. 5 l Example 4 QQQ Corporation has been writing COBOL programs for over 25 years 4 Over 200 software staff, all with COBOL expertise 4 What is “the most suitable” programming language? l Obviously COBOL

Choice of Programming Language (contd) Slide 6. 6 l What happens when new language Choice of Programming Language (contd) Slide 6. 6 l What happens when new language (C++, say) is introduced 4 C++ professionals must be hired 4 Existing COBOL professionals must be retrained 4 Future products are written in C++ 4 Existing COBOL products must be maintained 4 There are two classes of programmers » COBOL maintainers (despised) » C++ developers (paid more) 4 Expensive software, and the hardware to run it, are needed 4100 s of person-years of expertise with COBOL are wasted

Choice of Programming Language (contd) Slide 6. 7 l The only possible conclusion 4 Choice of Programming Language (contd) Slide 6. 7 l The only possible conclusion 4 COBOL is the “most suitable” programming language l And yet, the “most suitable” language for the latest project may be C++ 4 COBOL is suitable for only data processing applications l How to choose a programming language 4 Cost–benefit analysis 4 Compute costs and benefits of all relevant languages

Choice of Programming Language (contd) Slide 6. 8 l Which is the most appropriate Choice of Programming Language (contd) Slide 6. 8 l Which is the most appropriate object-oriented language? 4 C++ is (unfortunately) C-like (遗憾的是, 很多人把C++的普及归结为它与C的相似(事实并不完全这样)) 4 Thus, every classical C program is automatically a C++ program (任何带有C编译器的计算机本质上都可以处理C++程序) 4 Java enforces the object-oriented paradigm (Java是一种纯粹的面向对象编程语言) l What about choosing a fourth generation language (4 GL)?

6. 2 Fourth Generation Languages l Slide 6. 9 First generation languages 4 Machine 6. 2 Fourth Generation Languages l Slide 6. 9 First generation languages 4 Machine languages l Second generation languages 4 Assemblers (汇编语言) l Third generation languages 4 High-level languages (COBOL, FORTRAN, C++, Java)

Fourth Generation Languages (contd) l Slide 6. 10 Fourth generation languages (4 GLs) 4 Fourth Generation Languages (contd) l Slide 6. 10 Fourth generation languages (4 GLs) 4 One 3 GL statement is equivalent to 5– 10 assembler statements (一个第 3代语言的语句等效于5 -10个汇编语句) 4 Each 4 GL statement was intended to be equivalent to 30 or even 50 assembler statements (一个第 4代语言的语句的目标是: 等效于30甚至 50个汇编语句)

Fourth Generation Languages (contd) l Slide 6. 11 It was hoped that 4 GLs Fourth Generation Languages (contd) l Slide 6. 11 It was hoped that 4 GLs would 4 Speed up application-building 4 Result in applications that are easy to build and quick to change » Reducing maintenance costs 4 Simplify debugging 4 Make languages user friendly » Leading to end-user programming

Fourth Generation Languages (contd) l Slide 6. 12 Example : for every surveyor(对于每个检查官) if Fourth Generation Languages (contd) l Slide 6. 12 Example : for every surveyor(对于每个检查官) if rating is excellent (如果等级为“优良”) add 6500 to salary ( 资增加 6500) l The power of a nonprocedural (非过程的) language, and the price

Productivity Increases with a 4 GL? l Slide 6. 13 The picture is not Productivity Increases with a 4 GL? l Slide 6. 13 The picture is not uniformly rosy (不同公司应用第 4代语言的效果不一) l Playtex used ADF(IBM: Application Development Facility), obtained an 80 to 1 productivity increase over COBOL 4 However, Playtex then used COBOL for later applications l 4 GL productivity increases of 10 to 1 over COBOL have been reported 4 However, there are plenty of reports of bad experiences

Actual Experiences with 4 GLs l Slide 6. 14 Many 4 GLs are supported Actual Experiences with 4 GLs l Slide 6. 14 Many 4 GLs are supported by powerful CASE tools 4 This is a problem for organizations at CMM level 1 or 2 4 Some reported 4 Gl failures are due to the underlying CASE environment (一些报道过的4 GL失败可以归因于与此有关的CASE环境的结果, 而 不是 4 GL本身)

Actual Experiences with 4 GLs (contd) l Slide 6. 15 Attitudes of 43 organizations Actual Experiences with 4 GLs (contd) l Slide 6. 15 Attitudes of 43 organizations to 4 GLs 4 Use of 4 GL reduced users’ frustrations(提升用户效率) 4 Quicker response from DP department (加快数据处理部门 的响应) 44 GLs are slow and inefficient, on average(缓慢低效) 4 Overall, 28 organizations using 4 GL for over 3 years felt that the benefits outweighed the costs(收益大于成本)

Fourth Generation Languages (contd) l Market share Slide 6. 16 (第四代语言在市场的分享) 4 No one Fourth Generation Languages (contd) l Market share Slide 6. 16 (第四代语言在市场的分享) 4 No one 4 GL dominates the software market 4 There are literally hundreds of 4 GLs(市场上有数以百计的第 四代语言) 4 Dozens with sizable user groups(拥有一定规模的用户群) 4 Oracle, DB 2, and Power. Builder are extremely popular l Reason 4 No one 4 GL has all the necessary features l Conclusion 4 Care has to be taken in selecting the appropriate 4 GL

6. 3 Good Programming Practice l Slide 6. 17 Use of consistent and meaningful 6. 3 Good Programming Practice l Slide 6. 17 Use of consistent and meaningful variable names (使用一致和有意义的变量名) 4“Meaningful” to future maintenance programmers 4“Consistent” to aid future maintenance programmers

6. 3. 1 Use of Consistent and Meaningful Variable Names 6. 18 Slide l 6. 3. 1 Use of Consistent and Meaningful Variable Names 6. 18 Slide l A code artifact includes the variable names freq. Average, l frequency. Maximum, min. Fr, frqncy. Totl A maintenance programmer has to know if freq, frequency, frqncy all refer to the same thing 4 If so, use the identical word, preferably frequency, perhaps freq or frqncy, but not fr 4 If not, use a different word (e. g. , rate) for a different quantity

Consistent and Meaningful Variable Names Slide 6. 19 l We can use frequency. Average, Consistent and Meaningful Variable Names Slide 6. 19 l We can use frequency. Average, frequency. Myaximum, frequency. Minimum, frequency. Total l We can also use average. Frequency, maximum. Frequency, minimum. Frequency, total. Frequency l But all four names must come from the same set

6. 3. 2 The Issue of Self-Documenting Code Slide 6. 20 l Self-documenting code(自文档代码) 6. 3. 2 The Issue of Self-Documenting Code Slide 6. 20 l Self-documenting code(自文档代码) is exceedingly rare l The key issue: Can the code artifact be understood easily and unambiguously by 4 The SQA team 4 Maintenance programmers 4 All others who have to read the code

Prologue Comments(序言性注释) l Slide 6. 21 Minimal prologue comments for a code artifact Figure Prologue Comments(序言性注释) l Slide 6. 21 Minimal prologue comments for a code artifact Figure 14. 1

Other Comments(行内注释) l Slide 6. 22 Suggestion 4 Comments are essential whenever the code Other Comments(行内注释) l Slide 6. 22 Suggestion 4 Comments are essential whenever the code is written in a non-obvious way, or makes use of some subtle aspect of the language (行内注释应当仅用在代码是用一种不显而易见的方式编写, 或者使用 了该语言中某些难以理解的方面时)

6. 3. 3 Use of Parameters(参数) l Slide 6. 23 There almost no genuine 6. 3. 3 Use of Parameters(参数) l Slide 6. 23 There almost no genuine constants(很少有真正 的常量) l 如果产品中多个模块将常量固定编写在代码中, 那么当对该常 量进行修改时, 则容易遗漏部分代码, 造成错误 l One solution: 4 Use const statements (C++), or 4 Use public static final statements (Java) l A better solution: 4 Read the values of “constants” from a parameter file

6. 3. 4 Code Layout for Increased Readability(为增加可读性的代码编排) Slide 6. 24 l Use indentation 6. 3. 4 Code Layout for Increased Readability(为增加可读性的代码编排) Slide 6. 24 l Use indentation (缩进) l Better, use a pretty-printer(例如: 一行中不出现多个语句) l Use plenty of blank lines (空行) 4 To break up big blocks of code

6. 3. 5 Nested if Statements (嵌套的if语句) Slide 6. 25 l Example 4 A 6. 3. 5 Nested if Statements (嵌套的if语句) Slide 6. 25 l Example 4 A map consists of two squares. Write code to determine whether a point on the Earth’s surface lies in map square 1 or map square 2, or is not on the map Figure 14. 2

Nested if Statements (contd) l Slide 6. 26 Solution 1. Badly formatted Figure 14. Nested if Statements (contd) l Slide 6. 26 Solution 1. Badly formatted Figure 14. 3 l Solution 2. Well-formatted, badly constructed Figure 14. 3

Nested if Statements (contd) l Slide 6. 27 Solution 3. Acceptably nested Figure 14. Nested if Statements (contd) l Slide 6. 27 Solution 3. Acceptably nested Figure 14. 5

Nested if Statements (contd) Slide 6. 28 l A combination of if-if and if-else-if Nested if Statements (contd) Slide 6. 28 l A combination of if-if and if-else-if statements is usually difficult to read l Simplify: The if-if combination if if l if && if statements nested to a depth of greater than three should be avoided as poor programming practice (嵌套语句超过3级是一个较差的编程习惯)