php 什么是“真正的”编程语言?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3222316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 09:03:13  来源:igfitidea点击:

What is a "real" programming language?

phpprogramming-languagesterminology

提问by Hyman

Recently a teacher said "PHP isn't a real programming language", but only gave, in my opinion, weak justification:

最近一位老师说“PHP 不是真正的编程语言”,但在我看来只是给出了无力的理由:

  • It's not compiled.
  • It's scripted.
  • It doesn't run on every platform.
  • 它没有编译。
  • 它是脚本化的。
  • 它不会在每个平台上运行。

Is PHP not considered a "real" programming language? What is a "real" programming language? Must a language be compiled to be taken seriously?

PHP 不被认为是“真正的”编程语言吗?什么是“真正的”编程语言?一种语言必须经过编译才能被认真对待吗?

Background

背景

I did an induction lesson into my A-Level Computing Class in school two days ago – we're using Java for the first year of the course. I'm unfamiliar with Java but have a pretty good grasp on general programming fundamentals (variables, functions, object-orientation, loops, etc.).

两天前,我在学校的 A-Level 计算机课上上了一节入门课——我们在课程的第一年使用 Java。我不熟悉 Java,但对一般编程基础知识(变量、函数、面向对象、循环等)有很好的掌握。

Our first task the teacher ran through ridiculously fast. She didn't bother to explain any of the concepts, how they work, or what you would realistically use them for, and seemed to take great pleasure in watching most of the students (who were, on the whole, new to programming) squirm in their seats at not having the vaguest idea what she was on about. In hindsight, I reckon she went through it incredibly quickly to see who could really "handle" taking Computing A-Level, since students still have a chance to change their subjects before September begins.

我们的第一个任务老师完成得快得离谱。她没有费心去解释任何概念,它们是如何工作的,或者你将它们实际用于什么,并且似乎很高兴看到大多数学生(总的来说,他们是编程新手)蠕动在他们的座位上,对她在说什么一无所知。事后看来,我认为她以惊人的速度完成了它,看看谁能真正“处理”计算机 A-Level,因为学生仍有机会在 9 月开始之前改变他们的科目。

The first and only task was to write a Java command-line application to convert binary to denary (decimal). We had a two-hour taster session to do this, and after explanation how the binary system works we had to begin, despite, on the whole, nobody really having the foggiest idea where to begin. After an hour some were further than others, but nobody had really achieved anything significant. The teacher herself became so confused she called in another teacher from next door. He came round to help people and see where to go next.

第一个也是唯一的任务是编写一个 Java 命令行应用程序来将二进制转换为十进制(十进制)。我们有一个两小时的品尝会来做这件事,在解释了二进制系统的工作原理之后,我们不得不开始,尽管总的来说,没有人真正有最模糊的想法从哪里开始。一个小时后,有些人比其他人走得更远,但没有人真正取得任何重大成就。老师自己也糊涂了,她叫来了隔壁的另一位老师。他过来帮助人们,看看下一步该去哪里。

Without bragging, I probably did have the most experience in the class and had gotten the furthest in the exercise. He asked me if I'd had any previous experience; I said yes, particularly in PHP, and jokingly commented that I could write something to convert binary to denary in just a few lines of PHP, whilst the Java application was rapidly growing into several screens of code.

不吹牛,我可能确实是班上经验最多的人,并且在练习中走得最远。他问我以前是否有过任何经验;我说是的,尤其是在 PHP 中,并开玩笑地评论说我可以写一些东西,只需几行 PHP 就可以将二进制转换为 denary,而 Java 应用程序正在迅速成长为几个代码屏幕。

He replied, "PHP isn't a real programming language!"...! After some discussion, he gave the three reasons above. However, I pointed out you can run PHP on any platform that runs Apache, but I don't think he really knows what Apache is and was having none of that!

他回答说:“PHP 不是真正的编程语言!”...!经过一番讨论,他给出了上述三个原因。但是,我指出您可以在任何运行 Apache 的平台上运行 PHP,但我认为他并不真正了解 Apache 是什么,并且一无所知!

回答by Mark Byers

First we need to know what a programming language is. At its minimum, a programming languageis something that is read by the computer and instructs it to perform certain operations. Many people would also expect a general purpose programming languageto be Turing complete. However there could be situations where a domain-specific languageisn't Turing complete but is still a useful programming language for that specific domain. Programming languages can be compiled or interpreted, and they could run on many platforms or just one specific one. Different needs require different programming languages. Clearly PHP is a programming language.

首先我们需要知道什么是编程语言。至少,编程语言是由计算机读取并指示其执行某些操作的东西。许多人还期望通用编程语言图灵完备的。然而,在某些情况下,特定领域的语言不是图灵完备的,但对于该特定领域仍然是一种有用的编程语言。编程语言可以被编译或解释,并且它们可以在多种平台或仅一种特定平台上运行。不同的需求需要不同的编程语言。显然,PHP 是一种编程语言。

My definition of "real" programming language would be any programming language that has at least one practical usage in the real world. This is opposed to an esoteric programming languagewhich typically has no practical usage. Since PHP is used widely to solve real problems it easily meets this requirement for being a real programming language, although it is arguably not a particularly beautiful language.

我对“真正的”编程语言的定义是在现实世界中至少具有一种实际用途的任何编程语言。这与通常没有实际用途的深奥编程语言相反。由于 PHP 被广泛用于解决实际问题,因此它很容易满足成为真正编程语言的要求,尽管它可以说不是一种特别漂亮的语言。

PHP is a pragmatic language. It was created out of a specific need to be able to quickly make web pages (the name originally stood for Personal Home Pages) and the language was extended as required. Since there was no theoretical background or strong design principles driving its creation (there isn't even a formal specification of the language) it is less clean than many other more modern languages. Features like correct handling of foreign characters / unicode characters are obviously added on afterwards and not cleanly integrated with the rest of the language. This untidiness and lack of theoretical rigour causes many people (especially academics) to dislike the language and this may be part of the reason why your teacher doesn't regard PHP as "real" language.

PHP 是一种实用语言。它是出于能够快速制作网页(该名称最初代表个人主页)的特定需求而创建的,并且根据需要扩展了语言。由于没有理论背景或强大的设计原则来推动它的创建(甚至没有语言的正式规范),它不像许多其他更现代的语言那么干净。诸如正确处理外来字符/unicode 字符之类的功能显然是在之后添加的,并且没有与语言的其余部分完全集成。这种不整洁和缺乏理论严谨性导致许多人(尤其是学者)不喜欢该语言,这可能是您的老师不将 PHP 视为“真正”语言的部分原因。

However PHP is good at what it was designed for and many sites use it, even very large sites like Facebook, Yahoo! and Wikipedia.

然而,PHP 很擅长它的设计目的,许多网站都在使用它,甚至是像 Facebook、雅虎这样的大型网站!和维基百科。

回答by Quentin

It's not compiled

它没有编译

PHP can be compiled (e.g. through HHVM).

PHP 可以编译(例如通过HHVM)。

It's scripted

这是脚本

That's just another way of saying that PHP is not compiled.

这只是 PHP 未编译的另一种说法。

It doesn't run on every platform

它不会在每个平台上运行

Neither does Java.

Java也不行。

Sounds like you have a really bad teacher there.

听起来你那里有一个非常糟糕的老师。

回答by Dipstick

Of course PHP is a programming language. He probably meant it isn't a "real" programming languagein the same sense that "real" men don't eat quiche.

当然,PHP 是一种编程语言。他可能是说它不是“真正的”编程语言,就像“真正的”男人不吃乳蛋饼一样

回答by TNi

define:programming language

定义:编程语言

It seems, according to this, that PHP is a programming language. Whether it's a realprogramming language is entirely subjective. Whether it's a goodlanguage is also subjective. Certainly, it is most commonly not used as an applicationprogramming language, but it canbe used to develop shell applications via CLI. I have never done this, so my understanding of it is sketchy, but it's possible.

据此看来,PHP 是一种编程语言。它是否是一种真正的编程语言完全是主观的。它是否是一门语言也是主观的。当然,它最常不用作应用程序编程语言,但用于通过CLI开发 shell 应用程序。我从来没有这样做过,所以我对它的理解是粗略的,但它是可能的

Now, is PHP "scripted" (I take this to mean a scripting language), and does it run on every platform? You judge:

现在,PHP 是“脚本化的”(我认为这是一种脚本语言),它是否在每个平台上运行?你判断:

PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document. As a general-purpose programming language, PHP code is processed by an interpreter application in command-line mode performing desired operating system operations and producing program output on its standard output channel. It may also function as a graphical application. PHP is available as a processor for most modern web servers and as standalone interpreter on most operating systems and computing platforms.

Source: http://en.wikipedia.org/wiki/PHP

PHP:超文本预处理器是一种广泛使用的通用脚本语言,最初设计用于 Web 开发以生成动态网页。为此,PHP 代码被嵌入到 HTML 源文档中,并由带有 PHP 处理器模块的 Web 服务器解释,从而生成网页文档。作为一种通用编程语言,PHP 代码由命令行模式下的解释器应用程序处理,执行所需的操作系统操作并在其标准输出通道上生成程序输出。它还可以用作图形应用程序。PHP 可用作大多数现代 Web 服务器的处理器以及大多数操作系统和计算平台上的独立解释器。

来源:http: //en.wikipedia.org/wiki/PHP

Does Java even run on every platform? No. Only those for which there exists a JVM.

Java 甚至可以在每个平台上运行吗?不。只有那些存在 JVM 的。

Finally, does a language need to be compiled? Many aren't. Even Java isn't compiled in the same way C or C++ is. And then you'd also need to take a look at Perl, Python, etc.

最后,需要编译语言吗?许多不是。甚至 Java 的编译方式也与 C 或 C++ 不同。然后你还需要看看 Perl、Python 等。

Personally, I think PHP is a real programming language. I started there and easily moved on to C/C++ and Java. I wouldn't use it for the same purpose as Java, and its design is different from Java, but that doesn't mean much. It was easierto learn than Java for me.

就个人而言,我认为 PHP 是一种真正的编程语言。我从那里开始,然后轻松地转向了 C/C++ 和 Java。我不会将它用于与 Java 相同的目的,它的设计与 Java 不同,但这并没有多大意义。对我来说,它比 Java更容易学习。

回答by TNi

First of all, not being compiled and being interpreted (what he surely meant by scripted, which is somewhat vague and used for different purposes anyway) are different sides of the same coin, and thus really the same reason.

首先,不被编译和被解释(他肯定是指脚本化,这有点模糊并且用于不同的目的)是同一枚硬币的不同方面,因此实际上是相同的原因。

The last reason, that it doesn't run on every platform, is just confusing. It sounds like he's trying to tout Java's portability and PHP simply isn't Java. However, Java runs on one very specific platform: the JVM. That platform in turn runs on many other platforms, and thus gives Java its portability, but it's not quite the same as the traditional use of "portable". For example, C is portable and runs on everything from a PDP-11 to the latest embedded devices.

最后一个原因,它不能在每个平台上运行,只是令人困惑。听起来他是在吹捧 Java 的可移植性,而 PHP 根本就不是 Java。然而,Java 运行在一个非常特殊的平台上:JVM。该平台又可以在许多其他平台上运行,从而赋予 Java 可移植性,但它与“可移植”的传统用法并不完全相同。例如,C 是可移植的,可以在从 PDP-11 到最新的嵌入式设备的所有设备上运行。

However, C does that by specifying rules of its own abstract platform, and compilers transform C code into assembly according to those rules. This is how Java's portability is similar to C's: they both define rules which are translated into instructions for a specific, concrete machine (processor); the difference is when that occurs.

但是,C 通过指定其自身抽象平台的规则来实现这一点,编译器根据这些规则将 C 代码转换为汇编代码。这就是 Java 的可移植性与 C 的相似之处:它们都定义了规则,这些规则被翻译成特定的、具体的机器(处理器)的指令;不同的是什么时候发生。

All problems in computer science can be solved with another level of indirection.
  — David Wheeler

计算机科学中的所有问题都可以通过另一个间接层次来解决。
  — 大卫·惠勒

In reality, even assembly or "machine code" is interpreted by the processor into its native actions. (I don't have a good source at hand for this, but I recall that it's lightly covered by A Crash Course in Modern Hardware, which is a good presentation anyway.) As processor speeds get faster, we hardly notice on our underused boxes whether a given program is in asm or run through an interpreter, but this is where the definition of "real programming language" comes into play.

实际上,即使是汇编或“机器代码”也被处理器解释为它的本机操作。(我手头没有很好的资料来源,但我记得它被现代硬件速成课程稍微涵盖了,无论如何这是一个很好的演示。)随着处理器速度越来越快,我们几乎没有注意到我们未充分利用的盒子给定的程序是在 asm 中还是通过解释器运行,但这就是“真正的编程语言”的定义发挥作用的地方。

The only sensible way to define a "real programming language" is as "a language to get real work done", but that really punts on the definition of "real", too. (It does, however, establish a distinction with esoteric programming languages, because nobody does real work, for example, in Malbolge, for any definition of "real" you could get ten people to agree upon.) And, compared to today, your choices of a programming language were much more limited by their implementation strategy and overhead (e.g. a runtime interpreter) in the past. However, even today, some languages are more "real" than others for certain applicationsand expected loads, it all depends on your requirements.

定义“真正的编程语言”的唯一明智方法是“一种完成实际工作的语言”,但这也确实与“真实”的定义有关。(然而,它确实建立了与深奥的编程语言的区别,因为没有人从事真正的工作,例如,在Malbolge 中,对于“真实”的任何定义,您都可以得到十个人的同意。)而且,与今天相比,您的过去,编程语言的选择受到其实现策略和开销(例如运行时解释器)的更多限制。然而,即使在今天,对于某些应用程序和预期负载,某些语言比其他语言更“真实” ,这完全取决于您的要求。

It sounds like your teacher has only experienced PHP through toy web applications (and maybe using 'application' is a stretch for what he's seen). Toy programs aren't real work. PHP definitely has a lot of problems, but I could not say it isn't a real programming language, except in jest.

听起来您的老师只通过玩具 Web 应用程序体验过 PHP(对于他所看到的,使用“应用程序”可能是一种延伸)。玩具程序不是真正的工作。PHP 肯定有很多问题,但我不能说它不是一种真正的编程语言,除了开玩笑。

Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.
  — Dan Kaminsky

调试被期待而厌恶,不情愿地执行,并且永远吹嘘。
  — 丹·卡明斯基

There is a certain association of "real" with "hard to do" (related to "real work") and your teacher may have been expressing this sentiment. This has always appeared to me as a form of bikeshedding(there's a better term for this exactly, but I can't remember it), where one's estimation of the value of a thing is related to the effort one had to put into it (e.g. a bikeshed is more important when I provided input on the color of the roof and whether it should have a sign). We intrinsically value our own effort more than that of others – just because we're familiar with it, if for no other reason – even when it doesn't make sense to do so. PHP, despite its faults, does make some things easy, and it and programs written in it can consequently be perceived as worth less.

“真实”与“难做”(与“实际工作”相关)有一定的联系,你的老师可能已经表达了这种情绪。在我看来,这一直是自行车棚的一种形式(确切地说,有一个更好的术语,但我不记得了),其中一个人对事物价值的估计与必须付出的努力有关(例如,当我提供有关屋顶颜色以及是否应该有标志的输入时,自行车棚更为重要)。我们本质上比其他人更重视自己的努力——仅仅因为我们熟悉它,如果没有其他原因——即使这样做没有意义。PHP,尽管有它的缺点,但确实让一些事情变得简单,

回答by Daniel

Facebook, Digg, Wikipedia, Yahoo. I guess those aren't real websites.

Facebook、Digg、维基百科、雅虎。我猜那些不是真正的网站。

回答by Matt Ellen

Back when I was learning PHP, I too didn't believe PHP to be a programming language.

当我学习 PHP 时,我也不相信 PHP 是一种编程语言。

I'm not sure where I picked the idea up, but I learned somewhere that a scripting language is not a programming language. So I applied this thinking to other languages, such as JavaScript and SQL.

我不确定我是从哪里找到这个想法的,但我在某处了解到脚本语言不是编程语言。所以我把这个想法应用到了其他语言,比如 JavaScript 和 SQL。

Since then I have changed my mind and understand now that there is a spectrum of languages that goes from high level (e.g. PHP, Javascript) to low level (e.g. c, assembler) with things like C# and Java somewhere in between.

从那时起,我改变了主意,现在明白了从高级(例如 PHP、Javascript)到低级(例如 c、汇编程序)的语言范围,其中 C# 和 Java 之类的语言介于两者之间。

回答by Your Common Sense

You are right. These reasons are too weak. Actually you don't even need Apache to run PHP.
And first two reasons are just repeat themselves as it's only one reason actually. So, one can say 'PHP is not compiled language' but that doesn't mean it's 'not real programming language'. Java programs doesn't compile into machine codes too - well, it's not a real language as well. q.e.d.

你是对的。这些理由太弱了。实际上,您甚至不需要 Apache 来运行 PHP。
前两个原因只是重复自己,因为它实际上只是一个原因。因此,可以说“PHP 不是编译语言”,但这并不意味着它“不是真正的编程语言”。Java 程序也不能编译成机器码——好吧,它也不是一种真正的语言。qed

回答by Pete Wilson

Sorry for the OT, but there are so, so many things wrong with this picture! I just hope that you will bail out of that class, that department, and that school just as quickly as you can. I promise that you'll have nothing near to a semester's worth of knowledge when February comes. And, if you're like me, you'll spend your classroom hours in frustration, resentment, and rage at the time your teacher is wasting for you.

很抱歉 OT,但是这张照片有很多问题!我只希望你能尽快脱离那个班级、那个部门和那所学校。我保证,当二月到来时,你将一无所获。而且,如果你像我一样,当你的老师为你浪费时间时,你会在沮丧、怨恨和愤怒中度过你的课堂时间。

That woman is no teacher! Decimal to binary as an intro to coding? Gruesome!

那个女人不是老师!十进制到二进制作为编码的介绍?可怕!

Is it the University (ha!) of Phoenix?

是凤凰城大学(哈!)吗?

回答by BobTurbo

There is no such thing as a real programming language, real man, or real world. You are a programmer if you can program in PHP.

没有真正的编程语言、真实的人或真实世界这样的东西。如果你能用 PHP 编程,你就是一名程序员。