是什么让某些编程语言比其他语言更强大?

发布于 2024-09-27 20:31:08 字数 275 浏览 2 评论 0原文

我将在这里揭露我的无知,但我要辩护的是,我是会计专业的,而且我从未上过计算机科学课程。

我即将开始一个新项目,我正在考虑使用 Python 而不是 PHP,尽管我更擅长 PHP,因为我听说 Python 是一种更强大的语言。这让我想知道,是什么让一种编程语言比另一种编程语言更强大?我认为 javascript 不是很强大,因为它(通常)在浏览器中运行。但是,为什么Python比PHP更强大呢?在每种情况下,我都会向计算机发出指令,那么为什么有些语言更擅长解释和执行这些指令呢?我如何知道特定项目实际需要多少“能力”?

I'm going to reveal my ignorance here, but in my defense, I'm an accounting major, and I've never taken a computer science class.

I'm about to start a new project, and I'm considering using Python instead of PHP, even though I am much more adept with PHP, because I have heard that Python is a more powerful language. That got me wondering, what makes one programming language more powerful than another? I figure javascript isn't very powerful because it (generally) runs inside a browser. But, why is Python more powerful than PHP? In each case, I'm giving instructions to the computer, so why are some languages better at interpreting and executing these instructions? How do I know how much "power" I actually need for a specific project?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

给我一枪 2024-10-04 20:31:08

当 Paul Graham 谈到 Lisp 是可用的最强大的语言时,他指的是最具表现力的语言。您可以用任何图灵完备语言表达任何程序。这就是重点。一种语言比另一种语言(对于特定任务)更好的原因在于它能够更简洁或更清晰地定义给定的程序。对于大多数编程任务来说,这才是最重要的。

偶尔(我的意思是非常偶尔)性能开始发挥作用,并且诸如在程序中轻松嵌入汇编语言的能力之类的功能很重要。但在大多数情况下,它是关于清晰、简洁地表达你的想法的能力。

When Paul Graham talked about Lisp being the most powerful language available, he meant most expressive. You can express any program in any turing complete language. That's the whole point. What makes one language better than another (for a particular task) is its ability to define a given program more concisely or clearly. For most programming tasks, that's what matters.

Occasionally (and I mean very occasionally) performance starts to play a role, and features like the ability to embed assembly language easily in your program matters. But for the most part, it's about the ability to express your ideas clearly and concisely.

不即不离 2024-10-04 20:31:08

我讨厌“X 语言比 Y 语言更强大”之类的说法。真正的问题是哪种语言可以让变得更强大。如果 X 语言允许你比 Y 更快地编写更好的代码(有效),那么,是的,X 更“强大”。

如果您正在寻找语言威力的客观解释……那么,祝您好运。

I hate statements of the sort "language X is more powerful than Y." The real question is which language makes you more powerful. If language X allows you to write better code (that works) faster than Y does then, yes, X is more "powerful".

If you are looking for an objective explanation of language powerful-ness ... well, good luck with that.

此生挚爱伱 2024-10-04 20:31:08

这实际上并不是权力的问题,而是你想要做什么以及如何去做的问题。你可以说 Python“更强大”,因为它带有大量内置库,或者说 C++“更强大”,因为它更快,或者 Haskell“更强大”,因为它使用惰性求值 -简而言之,这确实是一个见仁见智的问题。但我还没有看到很多用 PHP 编写的桌面应用程序,也没有看到用 C++ 编写的 Web 应用程序(当然可能有例外)。

有些语言只是提供一种被认为是“优雅”的方式来执行某些任务。例如,看一下 Haskell 中的阶乘函数:

factorial 0 = 1
factorial n = n * factorial (n-1)

有些人可能认为这很优雅,主要是因为它清楚地反映了数学定义。但这比其他实现更好吗?不。(特别是因为这会溢出堆栈。)

总之,使用您认为最适合您的任务的内容 - 如果您最擅长 PHP,并且您不想学习 Python,那么就不要学习。如果您对它是什么样的感兴趣,请检查一下。不要因为它“更强大”而学习它。

It's not really a matter of power, but a matter of what you're trying to do and how you try to do it. You could say that Python is "more powerful" because it comes with a large set of built-in libraries, or that C++ is "more powerful" because it's much faster, or that Haskell is "more powerful" because it uses lazy evaluation - in short, it's really a matter of opinion. But I haven't seen many desktop apps written in PHP, and I don't see web apps written in C++ (though there are probably exceptions, of course).

Some languages simply offer what is considered an "elegant" way to perform certain tasks. For instance, look at a factorial function in Haskell:

factorial 0 = 1
factorial n = n * factorial (n-1)

Some might consider this elegant mainly because it reflects the mathematical definition clearly. But is this better than another implementation? No. (Especially since this would overflow the stack.)

In conclusion, use what you feel is best for your task - if you're best with PHP, and you don't want to learn Python, than don't. If you're interested in what it's like, then check it out. Don't learn it because it's "more powerful."

意犹 2024-10-04 20:31:08

我不会说有“更强大”的计算机语言,只是更适合您的特定问题领域的语言。

也就是说,PHP 是一种从 hack 演变而来的语言,专门针对非常具体的问题领域而定制。这出现在多个地方,例如数据库接口之间的参数顺序不一致。恕我直言,随着时间的推移,PHP 社区对新的语法增强做出了一些非常悲伤的决定。

恕我直言,Python 更通用、设计精良、优雅,但你的问题通常会引发激烈争论。

I would not say that there are computer languages "more powerful", just languages more suited for your specific problem domain.

That said, PHP is a language that evolved from a hack and tailored for a very specific problem domain; this shows up in several places, like for example inconsistent parameter order across database interfaces. IMHO PHP community has made some very sad decisions for new syntax enhancements over the time.

IMHO Python is much more general, well designed and elegant, but your question is one that usually starts flamewars.

很酷不放纵 2024-10-04 20:31:08

一般的答案是,使某些语言比其他语言更强大的唯一功能是无法通过添加库轻松替换的语言功能。

这个定义几乎总是将 LISP 列在顶部,但会产生奇怪的副作用,即在顶部附近列出汇编,除非特别小心将其排除。

The stock answer is the only features that make certain languages more powerful than others are language features that cannot be easily replaced by adding libraries.

This definition will almost always list LISP on the top, but has the odd side effect of listing assembly near the top unless special care is taken to exclude it.

撩心不撩汉 2024-10-04 20:31:08

这是一个有趣的话题,在我的文字中我经常遇到这个话题。但我发现字面意义上的“力量”对于语言来说不再具有价值。我担心那些告诉你“Python 更强大”的人会与语言和实现混淆。

我最近才转向 python(最近两周),之前我是一名 PHP 编码员。基于 python 语言(即 django)构建的库有助于使该语言变得更强大,因为它的使用和构建速度更快。

PHP 有这样一个寓言:“如果你想做某事。”它有一个功能”,并且文档非常出色 - 因此从这个意义上来说很强大。

至于解释语言——同样取决于谁编写了它——这无关紧要。根据普遍共识,Python 可能被认为更快且 CPU 密集度更低,因为它会创建代码的编译版本。但是PHP可以有很好的缓存系统。

简而言之 - 选择您最喜欢的。

Its an interesting topic and in my line of word I come across this a lot. But I've discovered 'power' in the literal sense no longer has value when it comes to the language. What I fear those telling you 'python is more' powerful are getting mixed up with the language and the implementation.

I'm a recent convert to python (last 2 weeks) previously I was a PHP coder. The libraries made on top of the language of python - namely django -help make the language more powerful - as its faster to use and build upon.

PHP has the fable 'if you want to do something. there is a function for it' and the documentation is brilliant - therefore powerful in that sense.

And in regards to interpreting the language - again dependant upon who has been coding it - its no matter. By general consensus python may be considered quicker and less CPU intensive, is it creates compiled versions of your code. But PHP can have a good caching system.

In short - Pick you favorite.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文