What to learn after PHP? Scala or Clojure?

I have a heavy web dev background with PHP. My reasons for learning a functional programming languages are:

  1. 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.
  2. learn a general purpose programming language to solve tasks like scripting (OS scripting, text manipulation etc..)
  3. to be used as an alternative for PHP in web development.

Also which has the better community support, tutorials and books and the better web application framework?

Feel free to suggest other languages.

Answers


For functional languages, learn both Scala and Clojure. You'll learn new ways of thinking from both of them. Go learn some Reia and Erlang while your at it too.

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.


I've tried both Scala and Clojure recently, based on similar motivations. Here's what I found:

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.

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.

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.

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.


My suggestion is to learn JavaScript.

I mean, really learn it.


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.

You may also be interested in what he has to say about PHP vs Clojure.


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.

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.

So, if you want an alternative to PHP, I'd bet on Scala. If you want to really learn functional programming, 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.


Get a bag of cement, harden up and Learn You a Haskell, for Great Good!

  1. It's purely functional, so you cannot fall off the ship.
  2. 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).

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

  1. 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

  2. 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.

  3. 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.

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.

Good luck!


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:

  • 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.

It is also one of the few languages that is specifically designed for building fault-tolerant, distributed software.


While it gets less press coverage than Clojure and Scala, I'd really recommend you to take a look at Fantom: http://fantom.org/

It's like the best of all both worlds and really should deserve more attention.


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.

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.

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.


Though Scala is my favorite language for now, i think it's not the best choice to learn FP. It's mainly OOPL with good support of FP. I would suggest to start from Haskell to quickly dive into FP. You will learn how the following concepts of FP work (which are not just supported, but enforced and ubiquitous in Haskell): 1) powerful static type system with type inference 2) lazy evaluation 3) side-effect free computing

After dynamically-typed "pragmatic" PHP and pure functional "academic" Haskell you will have quite full picture of programming languages landscape.


My $.02 is to check out Perl. I may sound like a geezer, but keep in mind that Perl has CPAN (http://cpan.org) and many very, very helpful online resources.


Ruby is probably the most "functional" mainstream language that's also good for scripting. Python is a close second, but ruby's habit of implicitly returning the result of the last expression in a function/block is the tiebreaker for me.

Both have excellent web frameworks (Rails and Django, respectively), and both will definitely broaden your horizons after programming PHP. At the same time they will allow a lot of opportunity for incremental learning.

Neither of them use S-expressions and both allow imperative programming, so there won't be anything to force you to give up the imperative style cold turkey.

Finally the much-lamented TCL is basically Scheme as a scripting and extension language. I'm not sure where it's at these days, but the ArsDigita Community System was written in TCL.


Web development depends ENTIRELY on: First, the quality of the web-framework and second the tools for development. I do not know why you want to move to functional languages for programming web applications.

Python allows some functional constructs for programming and it has frameworks and tools. Lua allows the same level of functional programming and it does not have either high quality frameworks for web development or tools, however its simplicity/primal-nature is its elegance.

Now as a puritan I'd say look at haskell, but that is counter-productive :D,. You my friend are looking for Python. I have not evaluated Ruby, but it might have some functional constructs.


May not appear so fancy, but I strongly suggest JavaScript.

A lot of years ago I was strong at PHP development, but then switched over to Java, C#, C, Objective-C. During my Java time I stepped deeply into JavaScript and did some pretty cool things with it. Someone I know developed an entire client-side temporary lightweight DBMS. Just have a look at Ext.js what they do with JavaScript. It's so underestimated, but doesn't deserve it. I suggest you google for "Douglas Crockford Video". At Yahoo he has created several excellent presentations about JavaScript, also I suggest you get the book "Javascript - The Good Parts" from Douglas Crockford, and "JavaScript - The Definitive Guide". Both the best JavaScript books available. And you'll be amazed what's possible and what a beautiful language it actually is. In fact, you can do AI with it, it has Lambda, there's actually nothing really "cooler" than that! What a pitty it's only used for clientside scripting. Few people know JavaScript can be used for serverside programming as well, but that's really rare / not well documented.

And thanks to Adobe Air you can bring JavaScript to the Desktop.

It would be an optimal addition to your PHP knowledge. It's always good to do related stuff. You can be the best Web Developer, or the best Desktop Software Architekt. But our brains are too slow to grasp all proffession needed nowadays to be the Guru in multiple directions. Beeing the Guru is essential for success, I think. Some friends of mine just do one thing: Beeing the Guru. They study their entire life one small subject and are extremely successful. They earn 5 times as much as any I-can-do-it-all-but-know-just-5%-in-this-topic-Developer in a quarter of the time only.

So I also suggest: Write a 600 pages PHP book before you forget your PHP knowledge while doing something totally different.

I did forget almost everything I knew about PHP and JavaScript, but in those early days I definitely was one of the expert guys who showed others a lot of stuff. Now it's a pain I have to ask so many basics again to recall them in my tiny brain. By writing your book, you'll recall your PHP expertise very fast even after a few years of doing something different, because it's your book, fitting your brain, from your brain. And you'll not loose your PHP-expert status even after several years of doing something else.

Good luck.


I tried Scala and found it a bit much (huge amount of operators that you have to recall how to use). But that could just be me. I've heard that Clojure is more functionally pure and closer to Lisp, but haven't checked it out.

F# is Microsoft's take on functional languages, you may want to check it out. I hear it has been used for several projects in industry.


I would suggest learning languages that have frameworks beyond the web front end such as Java EE (Java EE[JSP/JSF] + Java) or .NET (ASP.NET + C#, etc.). That would give you a bit more leeway with your career options, and you would be able to connect server components to a web front end with (relative) ease.


Need Your Help

Start Mail-Client with Attachment?

java email email-client jdic

I'm currently searching for a way (in Java) to start the default mail client with defined receiver, subject and body and with a predefined attachment.

Performance surprise with "as" and nullable types

c# performance clr nullable unboxing

I'm just revising chapter 4 of C# in Depth which deals with nullable types, and I'm adding a section about using the "as" operator, which allows you to write: