Source code is the list of human-readable instructions that a programmer writes—often in a word processing program—when he is developing a program. The source code is run through a compiler to turn it into machine code, also called object code, that a computer can understand and execute. Object code consists primarily of 1s and 0s, so it isn't human-readable.
源代码是程序员在开发程序时通常在文字处理程序中编写的人类可读指令的列表。 源代码通过编译器运行,以将其转换为计算机可以理解和执行的机器代码,也称为目标代码。 目标代码主要由1和0组成,因此它不是人类可读的。
源代码示例 ( Source Code Example )
Source code and object code are the before and after states of a computer program that is compiled. Programming languages that compile their code include C, C++, Delphi, Swift, Fortran, Haskell, Pascal and many others. Here is an example of C language source code:
源代码和目标代码是被编译的计算机程序的前后状态。 编译代码的编程语言包括C,C ++,Delphi,Swift,Fortran,Haskell,Pascal和许多其他语言。 这是C语言源代码的示例:
/* Hello World program */
#include<stdio.h>
main()
{
printf("Hello World")
}
You don't have to be a computer programmer to tell that this code has something to do with printing "Hello World." Of course, most source code is much more complex than this example. It is not unusual for software programs to have millions of lines of code. Windows 10 operating system is reported to have about 50 million lines of code.
您不必是计算机程序员就可以告诉您此代码与打印“ Hello World”有关。 当然,大多数源代码都比该示例复杂得多。 软件程序具有数百万行代码的情况并不少见。 据报道,Windows 10操作系统具有大约5000万行代码。
源代码许可 ( Source Code Licensing )
Source code can be either proprietary or open. Many companies closely guard their source code. Users can use the compiled code, but they cannot see or modify it. Microsoft Office is an example of proprietary source code. Other companies post their code on the internet where it is free to anyone to download. Apache OpenOffice is an example of open source software code.
源代码可以是专有的,也可以是开放的。 许多公司密切保护其源代码。 用户可以使用已编译的代码,但无法查看或修改它。 Microsoft Office是专有源代码的示例。 其他公司在互联网上发布其代码,任何人都可以免费下载。 Apache OpenOffice是开源软件代码的示例。
口译程序语言代码 ( Interpreted Program Languages Code )
Some programming languages such as JavaScript are not compiled into machine code but are interpreted instead. In these cases, the distinction between source code and object code does not apply because there is only one code. That single code is the source code, and it can be read and copied. In some cases, developers of this code may intentionally encrypt it to prevent viewing. Programming languages that are interpreted include Python, Java, Ruby, Perl, PHP, Postscript, VBScript and many others.
某些编程语言(例如JavaScript)不会编译为机器代码,而是会被解释。 在这些情况下,源代码和目标代码之间的区别不适用,因为只有一个代码。 单个代码就是源代码,可以读取和复制。 在某些情况下,此代码的开发人员可能会故意对其进行加密以防止查看。 可以解释的编程语言包括Python, Java ,Ruby,Perl, PHP ,Postscript,VBScript等。
翻译自: https://www.thoughtco.com/source-code-definition-958200