3.1 Computer Programming
(1)
Computer programming (often shortened to programming or coding) is the process of designing, writing, and debugging the source code of computer programs.
计算机编程(通常简称为编程或编码)是设计、编写和调试计算机程序源代码的过程。
This source code is written in a programming language.The purpose of programming is to create a program that exhibits a certain desired behavior.
该源代码是用编程语言编写的。编程的目的是创建一个表现出某种所需行为的程序。
The process of writing source code often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic.
编写源代码的过程通常需要许多不同学科的专业知识,包括应用程序领域的知识、专门的算法和形式逻辑。
(2)
Within software engineering,programming ( the implementation) is regarded as one phase in a software development process.
在软件工程中,编程(实现)被视为软件开发过程中的一个阶段。
Whatever the approach to software development may be, the final program must satisfy some fundamental properties.
无论软件开发的方法是什么,最终的程序都必须满足一些基本特性。
The following properties are among the most relevant:
以下属性是最相关的:
(3)
●Efficiency/ performance: the amount of system resources a program consumes (processor time, memory space, slow devices such as disks, network bandwidth and to some extent even user interaction): the less, the better.
效率/性能:程序消耗的系统资源量(处理器时间、内存空间、磁盘等慢速设备、网络带宽,在某种程度上甚至用户交互):越少越好。
This also includes correct disposal of some resources, such as cleaning up temporary files and lack of memory leaks.
这还包括正确处理一些资源,例如清理临时文件和缺少内存泄漏。
(4)
●Reliability: how often the results of a program are correct.
可靠性:程序结果正确的频率。
This depends on conceptual correctness of algorithms, and minimization of programming mistakes, such as mistakes in resource management (e. g., buffer overflows and race conditions) and logic errors (such as division by zero or off-by-one error).
这取决于算法的概念正确性,以及编程错误的最小化,例如资源管理中的错误(例如,缓冲区溢出和竞争条件)和逻辑错误(例如除以零或除以一错误)。
(5)
●Robustness: how well a program anticipates problems not due to programmer error.
健壮性:程序对非程序员错误问题的预测能力。
This includes situations such as incorrect, inappropriate or corrupt data, unavailability of needed resources such as memory, operating system services and network connections, and user error.
这包括数据不正确、不适当或损坏、所需资源(如内存、操作系统服务和网络连接)不可用以及用户错误等情况。
(6)
●Usability: the ergonomics of a program: the ease with which a person can use the program for its intended purpose, or in some cases even unanticipated purposes.
可用性:程序的人体工程学:一个人可以轻松地将程序用于其预期目的,在某些情况下甚至是出乎意料的目的。
Such issues can make or break its success even regardless of other issues.
即使不考虑其他问题,这些问题也可能决定其成功与否。
This involves a wide range of textual, graphical and sometimes hardware elements that improve the clarity, intuitiveness,cohesiveness and completeness of a program' s user interface.
这涉及到广泛的文本、图形元素,有时还有硬件元素,这些元素可以提高程序用户界面的清晰度、直观性、凝聚力和完整性。
(7)
●Portability: the range of computer hardware and operating system platforms on which the source code of a program can be compiled/ interpreted and run.
可移植性:一系列计算机硬件和操作系统平台,在这些平台上可以编译/解释和运行程序的源代码。
This depends on differences in the programming facilities provided by the different platforms, including hardware and operating system resources, expected behavior of the hardware and operating system, and availability of platform specific compilers (and sometimes libraries) for the language of the source code.
这取决于不同平台提供的编程设施的差异,包括硬件和操作系统资源、硬件和操作体系的预期行为,以及源代码语言的特定平台编译器(有时还有库)的可用性。
(8)
●Maintainability: the ease with which a program can be modified by its present or future developers in order to make improvements or customizations, fix bugs and security holes, or adapt it to new environments.
可维护性:当前或未来的开发人员可以轻松地修改程序,以便进行改进或自定义,修复漏洞和安全漏洞,或使其适应新环境。
Good practices during initial development make the difference in this regard. This quality may not be directly apparent to the end user but it can significantly affect the fate of a program over the long term.
在这方面,最初开发过程中的良好做法起着重要作用。这种质量对最终用户来说可能不是直接显而易见的,但从长远来看,它可能会显著影响程序的命运。
(9)
In computer programming, readability of the source code refers to the ease with which a human reader can comprehend the purpose, control flow, and operation of source code.
在计算机程序设计中,源代码的可读性是指人类读者能够轻松理解源代码的目的、控制流程和操作。
It affects the aspects of quality above, including portability, usability and most importantly maintainability.
它影响上述质量的各个方面,包括可移植性、可用性和最重要的可维护性。
Readability is important because programmers spend the majority of their time reading,trying to understand and modifying existing source code, rather than writing new source code.
可读性很重要,因为程序员的大部分时间都在阅读、尝试理解和修改现有的源代码,而不是编写新的源代码。
Unreadable code often leads to bugs, inefficiencies, and duplicated code.
无法读取的代码通常会导致错误、效率低下和重复代码。
A study found that a few simple readability transformations made code shorter and drastically reduced the time to understand it.
一项研究发现,一些简单的可读性转换使代码变得更短,并大大缩短了理解代码的时间。
(10)
Following a consistent programming style often helps readability. However, readability is more than just programming style.
遵循一致的编程风格通常有助于提高可读性。然而,可读性不仅仅是编程风格。
Many factors contribute to readability. Some of these factors include:
许多因素有助于提高可读性。其中一些因素包括:
(11-14)
●Different indentation styles (whitespace) 不同的缩进样式(空白)
●Comments 注解
●Decomposition 分解
●Naming conventions for objects (such as variables, classes, procedures, etc)
有许多因素影响代码的可读性。其中一些因素包括:
不同的缩进风格(空格)
注释
分解
对象的命名约定(例如变量、类、过程等)
(15)
The academic field and the engineering practice of computer programming are both largely concerned with discovering and implementing the most efficient algorithms for a given class of problem.
计算机编程的学术领域和工程实践都在很大程度上关注发现和实现给定类别问题的最有效算法。
For this purpose, algorithms are classified into orders using so-called Big O notation, O(n),which expresses resource use, such as execution time or memory consumption, in terms of the size of an input.
为此,使用所谓的大O表示法O(n)将算法分类为顺序,该表示法根据输入的大小来表示资源使用,例如执行时间或内存消耗。
Expert programmers are familiar with a variety of well-established algorithms and their respective complexities and use this knowledge to choose algorithms that are best suited to the circumstances.
专家程序员熟悉各种公认的算法及其各自的复杂性,并利用这些知识来选择最适合环境的算法。
(16)
Different programming languages support different styles of programming ( called programming paradigms).
不同的编程语言支持不同风格的编程(称为编程范式)。
The choice of language used is subject to many considerations.
所用语言的选择要经过许多考虑。
Ideally, the programming language best suited for the task at hand will be selected.
理想情况下,将选择最适合手头任务的编程语言。
(17)
It is very difficult to determine what are the most popular of modern programming languages.
很难确定现代编程语言中最流行的是什么。
Some languages are very popular for particular kinds of applications (e. g., COBOL is still strong in the corporate data center, often on large mainframes, FORTRAN in engineering applications, scripting languages in web development,and C in embedded applications), while some languages are regularly used to write many different kinds of applications.
有些语言在特定类型的应用程序中非常流行(例如,COBOL在公司数据中心仍然很强大,通常在大型大型机上,FORTRAN在工程应用程序中,脚本语言在web开发中,C在嵌入式应用程序中),而有些语言则经常用于编写许多不同类型的应用。
Also many applications use a mix of several languages in their construction and use.
此外,许多应用程序在构建和使用过程中混合使用多种语言。
(18)
Many computer languages provide a mechanism to call functions provided by libraries such as in .dlls. Provided the functions in a library follow the appropriate run time conventions (e. g., method of passing arguments), then these functions may be written in any other language.
许多计算机语言提供了一种调用库(如.dlls)提供的函数的机制。如果库中的函数遵循适当的运行时约定(例如,传递参数的方法),那么这些函数可以用任何其他语言编写。
(19)
Debugging is a very important task in the software development process, because an incorrect program can have significant consequences for its users.
在软件开发过程中,调试是一项非常重要的任务,因为不正确的程序可能会给用户带来重大后果。
Some languages are more prone to some kinds of faults because their specification does not require compilers to perform as much checking as other languages.
有些语言更容易出现某些类型的错误,因为它们的规范不需要编译器像其他语言那样执行大量检查。
Use of a static analysis tool can help detect some possible problems.
使用静态分析工具可以帮助检测一些可能的问题。