学完 PHP 学什么?Scala 还是 Clojure?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1843924/
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
What to learn after PHP? Scala or Clojure?
提问by samsung
I have a heavy web dev background with PHP. My reasons for learning a functional programming languages are:
我有很重的 PHP 网络开发背景。我学习函数式编程语言的原因是:
- to improve my programming skills. It was heavily suggested that learning a FPL helps. this has high priority because I want to be better and better.
- learn a general purpose programming language to solve tasks like scripting (OS scripting, text manipulation etc..)
- to be used as an alternative for PHP in web development.
- 以提高我的编程技能。有人强烈建议学习 FPL 有帮助。这是高度优先的,因为我想变得越来越好。
- 学习通用编程语言来解决诸如脚本编写(操作系统脚本编写、文本操作等)之类的任务。
- 在 Web 开发中用作 PHP 的替代品。
Also which has the better community support, tutorials and books and the better web application framework?
还有哪个有更好的社区支持、教程和书籍以及更好的 Web 应用程序框架?
Feel free to suggest other languages.
随意建议其他语言。
回答by Ryan McGeary
For functional languages, learn both Scalaand Clojure. You'll learn new ways of thinking from both of them. Go learn some Reiaand Erlangwhile your at it too.
对于函数式语言,学习Scala和Clojure。你会从他们俩身上学到新的思维方式。在你学习的同时去学习一些Reia和Erlang。
Seriously, the more languages you have under your belt, the better off you'll be as a programmer regardless of the language you end up using.
说真的,你掌握的语言越多,无论你最终使用哪种语言,你作为一名程序员都会变得越好。
Rant:"What language should I learn?" questions are getting tiresome. The answers should be the same every time, yet no one gives the correct sage advice. Instead, everyone spreads FUD and suggests that the language they happen to use for their day job is the one you should learn. Poppycock.
咆哮:“我应该学什么语言?” 问题越来越烦人。答案应该每次都一样,但没有人给出正确的明智建议。相反,每个人都在传播 FUD,并建议他们在日常工作中碰巧使用的语言是您应该学习的语言。胡说。
回答by Carl Smotricz
I've tried both Scala and Clojure recently, based on similar motivations. Here's what I found:
基于类似的动机,我最近尝试了 Scala 和 Clojure。这是我发现的:
Scala is enormously versatile and powerful; Scala lets you define types with great precision and it allows you to define DSLs that are terse and clean. Scala has a lot of cool constructs that one wishes Java had, including a bunch of functional extensions. But when it came right down to it, I ended up coding imperative Java in the Scala language because the complexity of all that cool stuff overwhelmed me.
Scala 非常通用且功能强大。Scala 允许您非常精确地定义类型,并允许您定义简洁明了的 DSL。Scala 拥有许多人们希望 Java 拥有的很酷的构造,包括一堆功能扩展。但是当它归结起来时,我最终用 Scala 语言编写了命令式 Java,因为所有这些很酷的东西的复杂性让我不知所措。
I did some Lisp back in University, and always had a hankering to get back to it again. Some really cool cutting-edge stuff is done by very smart people in Lisp, and in very few lines. I wanted to be one of those smart people, or at least try to be like them. But I never really understood Scheme, and I missed my "infinite supply of libraries" from Java. I couldn't see myself writing a GUI in Scheme, and had trouble envisioning a Web application.
我在大学时做过一些 Lisp,并且总是渴望再次回到它。一些非常酷的前沿东西是由非常聪明的人在 Lisp 中完成的,而且代码很少。我想成为那些聪明人中的一员,或者至少尝试像他们一样。但是我从来没有真正理解过 Scheme,而且我错过了 Java 的“无限的库供应”。我看不到自己在 Scheme 中编写 GUI,并且在构想 Web 应用程序时遇到了麻烦。
Then I tried Clojure and it seemed like everything clicked into place. Clojure was intentionally made more outsider-friendly: There is an attempt to cut down on the parentheses and to use different parenthetical punctuation for different situations. Treating things like arrays, text and XML as sequences, combined with a powerful set of sequence functions, made a lot of problems quite simple, as does the support for arrays and hashmaps. It's (intentionally) like functional Java. The functional mindeset takes a bit of getting used to, but nowhere did I find it as approachable or as enjoyable as in Clojure. My code hardly needs loops any more, yet it's more clear about where it's looping/sequencing, and more concise. I can do mutable state if I really need to, but I have to be explicit about it; in exchange, that state is protected by Clojure's concurrency mechanisms. Concurrency, then, becomes almost a no-brainer, sometimes my code executes safely in parallel with no conscious effort of my own.
然后我尝试了 Clojure,看起来一切都到位了。Clojure 有意让局外人更加友好:尝试减少括号并在不同情况下使用不同的括号标点符号。将数组、文本和 XML 等事物视为序列,结合一组强大的序列函数,使很多问题变得非常简单,对数组和哈希图的支持也是如此。它(有意地)就像函数式 Java。函数式思维模式需要一点时间来适应,但我发现它不像 Clojure 中那样平易近人或令人愉快。我的代码几乎不再需要循环,但它更清楚循环/排序的位置,也更简洁。如果我真的需要,我可以做可变状态,但我必须明确说明它;作为交换,该状态受 Clojure 的并发机制保护。然后,并发几乎变得轻而易举,有时我的代码可以安全地并行执行,而无需我自己的有意识的努力。
Not coming from Java, this will not seem very useful to you, but Clojure can do anything that Java can, including fully compatible .class files. Most importantly, it can interface with all Java libraries, and that ability alone will make PHP seem like a toy language to you.
不是来自 Java,这对您来说似乎不是很有用,但是 Clojure 可以做 Java 可以做的任何事情,包括完全兼容的 .class 文件。最重要的是,它可以与所有 Java 库交互,而且仅凭这种能力就可以让 PHP 看起来像是一种玩具语言。
回答by Scott Evernden
My suggestion is to learn JavaScript.
我的建议是学习 JavaScript。
I mean, reallylearn it.
我的意思是,真正学习它。
回答by Joel Mueller
Here's what a self-professed Clojure advocate has to say about Scala. Make up your own mind, of course, but you may find his perspective useful.
以下是一位自称是 Clojure 拥护者的关于 Scala 的评论。当然,你自己下定决心,但你可能会发现他的观点很有用。
You may also be interested in what he has to say about PHP vs Clojure.
您可能还对他对PHP 与 Clojure 的看法感兴趣。
回答by Daniel C. Sobral
That's a very difficult call. Personally, I think Scala is more useful as a general language for web developers. There are many web frameworks for it, or adapted to it. On the very quick&dirty side, for instance, there's Play. On the full-fledged with excellent Comet support side, there's Lift.
这是一个非常困难的电话。就个人而言,我认为 Scala 作为 Web 开发人员的通用语言更有用。有许多 Web 框架适用于它,或适用于它。例如,在非常快速和肮脏的方面,有Play。在完善且出色的 Comet 支持方面,有Lift。
But you talked about learning to program in a functional style. In that regard, there is no way Scala can compete with Clojure. Scala can be used in a functional style, but it makes sure you don't have to. With Clojure, on the other hand, doing anything but functional style is painful.
但是你谈到了学习以函数式风格编程。在这方面,Scala 无法与 Clojure 竞争。Scala 可以以函数式风格使用,但它确保您不必这样做。另一方面,对于 Clojure,除了函数式风格之外,做任何事情都是痛苦的。
So, if you want an alternative to PHP, I'd bet on Scala. If you want to really learn functional programming, Clojure.
因此,如果您想要 PHP 的替代品,我会打赌 Scala。如果你想真正学习函数式编程,Clojure。
Finally, let me state that I do not think Clojure isn't a general purpose language, or that it can't be used for web development. I just think Scala is more on both regards.
最后,让我声明我不认为 Clojure 不是一种通用语言,或者它不能用于 Web 开发。我只是认为 Scala 在这两个方面更胜一筹。
回答by Apocalisp
Get a bag of cement, harden up and Learn You a Haskell, for Great Good!
拿一袋水泥,变硬,向你学习 Haskell,为伟大的利益!
- It's purelyfunctional, so you cannot fall off the ship.
- It's general-purpose with loads of libraries (including a web application stack), and no VM startup time penalty (JVM languages are not great for OS scripting and the like, since you have to start the JVM every time).
- 它纯粹是功能性的,所以你不会从船上掉下来。
- 它具有大量库(包括 Web 应用程序堆栈)的通用用途,并且没有 VM 启动时间损失(JVM 语言不适用于 OS 脚本等,因为您每次都必须启动 JVM)。
回答by Vijay Mathew
If you are looking for a good alternative for PHP, I suggest Python and Ruby. If you need a Functional language with good support for web development - learn Erlang. Here are some projects/frameworks that will help you create highly scalable web applications in Erlang:
如果您正在寻找 PHP 的良好替代品,我建议您使用 Python 和 Ruby。如果您需要一种对 Web 开发有良好支持的函数式语言 - 学习 Erlang。这里有一些项目/框架可以帮助你在 Erlang 中创建高度可扩展的 Web 应用程序:
- Yaws- An Erlang webserver particularly well suited for dynamic-content webapplications. (Also see this Apache vs Yaws benchmark)
- Erlyweb- A component-oriented web development framework written in Erlang and designed to work with Yaws.
- Erlang Web- The Erlang Web is an open source framework for applications based on HTTP protocols, giving the developer better control of content management.
- Nitrogen- An event-driven web framework for Erlang.
- Yaws- 一个 Erlang 网络服务器,特别适合动态内容网络应用程序。(另请参阅此 Apache 与 Yaws 基准测试)
- Erlyweb- 用 Erlang 编写的面向组件的 Web 开发框架,旨在与 Yaws 一起使用。
- Erlang Web- Erlang Web 是基于 HTTP 协议的应用程序的开源框架,使开发人员可以更好地控制内容管理。
- Nitrogen- Erlang 的事件驱动的 Web 框架。
It is also one of the few languages that is specifically designed for building fault-tolerant, distributed software.
它也是为数不多的专为构建容错分布式软件而设计的语言之一。
回答by Alan Storm
Jumping form PHP to Scala or Clojure is going to be a huge culture shock. PHP is very focused on quick/dirty getting things done (or 90% clean with the last 10% dirty (-:), whereas functional programming languages force a certain correctness and abstractness onto your thinking. Before you get to Scala or Clojure, you're going to want something inbetween. If it was me, I'd
从 PHP 跳到 Scala 或 Clojure 将是一个巨大的文化冲击。PHP 非常专注于快速/肮脏地完成工作(或 90% 干净,最后 10% 脏 (-:),而函数式编程语言强制您的思维具有一定的正确性和抽象性。在您使用 Scala 或 Clojure 之前,您想要介于两者之间的东西。如果是我,我会
Pick my final target as Clojure, since (as I understand it) you get the entire Java standard library with Clojure, making it immediately more useful than something pure like Scala
I'd spend some time building something in Java, just to get a feel for a strongly typed OO language. I picked Java over C# (or even ZendFramework style PHP) because it will prove useful once you arrive at Clojure. Google Web Tools might be a good place to start with this. It's kind of web development, but very very Java like and not at all PHP/HTML like.
Spend some time looking at the guts of jQuery, and either develop your own jQuery module or add a core feature. This will get you used to the functional way of thinking, while applying it to a problem you're familiar with.
选择我的最终目标作为 Clojure,因为(据我所知)你使用 Clojure 获得了整个 Java 标准库,这使它立即比像 Scala 这样的纯粹的东西更有用
我会花一些时间用 Java 构建一些东西,只是为了感受一下强类型的 OO 语言。我选择 Java 而不是 C#(甚至 ZendFramework 风格的 PHP),因为一旦你到达 Clojure,它就会被证明是有用的。Google Web Tools 可能是一个很好的起点。这是一种 Web 开发,但非常非常像 Java,完全不像 PHP/HTML。
花一些时间了解 jQuery 的本质,然后开发您自己的 jQuery 模块或添加核心功能。这将使您习惯功能性思维方式,同时将其应用于您熟悉的问题。
Final bit of advice: Try to embrace the common methods of the language/platform you've chosen. Don't try to bring your style of PHP coding to either language. Although it will seem easier at first and let you get some kind of results, you'll miss the point of the exercise, which is to think differently and more broadly about problems.
最后一点建议:尝试采用您选择的语言/平台的常用方法。不要试图将您的 PHP 编码风格带到任何一种语言中。虽然一开始看起来更容易并且让你得到某种结果,但你会错过练习的重点,即以不同的方式更广泛地思考问题。
Good luck!
祝你好运!
回答by Frank Denis
While it gets less press coverage than Clojure and Scala, I'd really recommend you to take a look at Fantom: http://fantom.org/
虽然它的新闻报道比 Clojure 和 Scala 少,但我真的建议你看看 Fantom:http: //fantom.org/
It's like the best of all both worlds and really should deserve more attention.
它就像两全其美,真的应该得到更多关注。
回答by Carl Smotricz
I'm a new convert to Clojure. It's making me expand my mind but it's approachable enough to be fun and productive. I'm a happy customer.
我是Clojure的新转换者。它让我开阔了我的视野,但它足够平易近人,既有趣又富有成效。我是一个快乐的顾客。
But
但
PHP and Clojure live in different universes. I've had some introductory dabbling in FP languages, and a few false starts into other Lisps before embracing Clojure. For a less experienced developer coming straight from PHP, Clojure might be too much of a culture shock.
PHP 和 Clojure 生活在不同的世界中。在使用 Clojure 之前,我对 FP 语言进行了一些介绍性的尝试,并且对其他 Lisps 进行了一些错误的尝试。对于直接来自 PHP 的经验不足的开发人员来说,Clojure 可能是一种文化冲击。
As a reasonable compromise between the two, and a language that is scripty enough to let you approach FP on a gradient rather than a plunge, I recommend Ruby. Ruby is modern, clean and elegant. In its JRuby incarnation, it's even fast. Learning Ruby and playing with Rails is enjoyable and instructive.
作为两者之间的合理折衷,以及一种足够脚本化的语言,可以让您在渐变而不是暴跌上接近 FP,我推荐Ruby。Ruby 是现代、干净和优雅的。在 JRuby 版本中,它甚至更快。学习 Ruby 和使用 Rails 既有趣又有益。

