原 文:What Language Do I Use
译 者:Sunlxy
版 本:the first edition(Ver 1.0)
这是每个游戏编程FAQ里都有的问题。这个问题每星期都会在游戏开发论坛上被问上好几次。这是个很好的问题,但是,没人能给出简单的答案。在某些应用程序中,总有一些计算机语言优于其他语言。下面是几种用于编写游戏的主要编程语言的介绍及其优缺点。希望这篇文章能帮助你做出决定。
This is a question that belongs in every game programming FAQ. It seems to be asked in a game development forum several times a week. It's a good question, though, and not one with an easy answer. There are computer languages that work better for some applications than others. Here is a list of the major programming languages used to write games along with descriptions, advantages, and disadvantages. Hopefully this list will help you make a decision.
1、C语言
如果说FORTRAN和COBOL是第一代高级编译语言,那么C语言就是它们的孙子辈。C语言是Dennis Ritchie在七十年代创建的,它功能更强大且与ALGOL保持更连续的继承性,而ALGOL则是COBOL和FORTRAN的结构化继承者。C语言被设计成一个比它的前辈更精巧、更简单的版本,它适于编写系统级的程序,比如操作系统。在此之前,操作系统是使用汇编语言编写的,而且不可移植。C语言是第一个使得系统级代码移植成为可能的编程语言。
If FORTRAN and COBOL were the first compiled high-level languages, then C is their grandchild. It was created in the 70's by Dennis Ritchie as a tighter and more coherent successor to ALGOL, which was a structured successor to COBOL and FORTRAN. It was designed to be a smaller and simpler version of its predecessors, suitable for writing system-level programs, like operating systems. Before then, operating systems were hand-coded in assembly and were not portable. C was the first programming language that made portability a reality for system-level code.
C语言支持结构化编程,也就是说C的程序被编写成一些分离的函数呼叫(调用)的集合,这些呼叫是自上而下运行,而不像一个单独的集成块的代码使用GOTO语句控制流程。因此,C程序比起集成性的FORTRAN及COBOL的“空心粉式代码”代码要简单得多。事实上,C仍然具有GOTO语句,不过它的功能被限制了,仅当结构化方案非常复杂时才建议使用。
C is a language that supports structured programming. That is to say that C programs are written as collections of disconnected function calls that run top-down rather than a single monolithic block of code with program control-flow happening via GOTO statements. Hence, C programs are generally easier to follow than monolithic FORTRAN and COBOL spaghetti-code. Actually, C still has a GOTO statement, but its functionality is limited and it is only recommended as a last resort if structured solutions are much more complicated.
正由于它的系统编程根源,将C和汇编语言进行结合是相当容易的。函数调用接口非常简单,而且汇编语言指令还能内嵌到C代码中,所以,不需要连接独立的汇编模块。
True to its system-programming roots, it is fairly easy to interface C with assembly languages. The function-calling interface is very simple, and assembly language instructions can be embedded within C code, so linking in separate assembly-language modules is not necessary.
优点:有益于编写小而快的程序。很容易与汇编语言结合。具有很高的标准化,因此其他平台上的各版本非常相似。
Advantages: Good for writing small fast programs. Easy to interface with assembly language. Very standardized, so versions on other platforms are similar.
缺点:不容易支持面向对象技术。语法有时会非常难以理解,并造成滥用。
Disadvantages: Does not easily support object-oriented techniques. Syntax can be difficult and lends itself to abuse.
移植性:C语言的核心以及ANSI函数调用都具有移植性,但仅限于流程控制、内存管理和简单的文件处理。其他的东西都跟平台有关。比如说,为Windows和Mac开发可移植的程序,用户界面部分就需要用到与系统相关的函数调用。这一般意味着你必须写两次用户界面代码,不过还好有一些库可以减轻工作量。
Portability: While the core of the language and the ANSI function calls are very portable, they are limited to control-flow, memory management, and simple file-handling. Everything else is platform-specific. Making a program that's portable between Windows and the Mac, for instance, requires that the user-interface portions be using system-specific function calls. This generally means that you need to write the user-interface code twice. There are libraries, though, that make the process a bit easier.
用C语言编写的游戏:非常非常多。
Games Written in C: Lots and lots.
资料:C语言的经典著作是《The C Programming Language》,它经过多次修改,已经扩展到最初的三倍大,但它仍然是介绍C的优秀书本。一本极好的教程是《The Waite Group's C Primer Plus》。
Resources: The classic book about C is [The C Programming Language].It's gone through several iterations and has expanded to about three times its original size, but it's still a good introduction to the language. An excellent tutorial is [The Waite Group's C Primer Plus].