views:

1574

answers:

17

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. Thanks!

A: 

I would suggest learning languages that have frameworks beyond the web front end such as J2EE (J2EE[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.

monksy
So are you saying he shouldn't learn Scala or Clojure? I'm confused, because both of them meet your criteria. What does this have to do with the question?
Joel Mueller
Be constructive the guys asked for a viable solution not fuz.
Hassan Syed
I have no experience with Scala or Clojure, so I can't recommend either of those. I did however recommend 2 fairly large platforms that are used in enterprise systems.
monksy
you recommended two languages that had nothing to do with his question. He wants to learn new ways of thinking and programming. Enterprise systems rot your brain they don't expand it. I use functional languages to regain my sanity after programming on enterprise systems all day.
Jeremy Wall
You are wrong in many ways. He asked for suggestions about what to learn after PHP. [see the title] He suggested Scala or Clojure, however as I said before I have no experience with the languages, and I can only make judgements on the languages I have. Enterprise systems are not sexy, but they do pay the bills and they do cover more topics than most hack and slash projects.
monksy
You answer is irrelevant since he asked for a language recommendation, but you suggested two platforms - and since both Clojure and Scala are implemented on the JVM (and I think to some extent .Net) they have access to "frameworks beyond the web front end".
Dave Kirby
Please reread the question, not just the title.
monksy
A: 

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.

Kaleb Brasee
programming .NET in F#. That sounds like a lot of fun.
Hassan Syed
It is, actually. When the question is about Scala vs Clojure, responding "F#" is no more wrong than responding "Python".
Joel Mueller
he wants an alternative to PHP for OS scripting and web development. I doubt he had WMI and COM in mind for scripting :P or the convuluted .NET environment - for which I doubt he would find much user-friendly documentation.
Hassan Syed
+1 to reverse the downvote for this answer. I abhor anything touched by Microsoft but I wouldn't let that personal choice inform someone else's decision to learn a new programming language, nor lead me to downvote someone just for mentioning it.
Carl Smotricz
A: 

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.

Hassan Syed
Scala and Clojure are both far better than Python in the area of multi-threading support, which may be a consideration going forward as CPU's continue to sprout more cores without getting much faster in the clock speed department.
Joel Mueller
Multi-process rules the UNIX environment. threading is not an issue. I Use real life experience on 32 core machines here :D
Hassan Syed
BTW the JVM uses CPU memory barier primitives to support synchronization primitives. Those are counter-productive to performance - if you really want to get into the nitty-gritty of it:D
Hassan Syed
I'm a big fan of Clojure and Scala, but they're systems languages, and from his requirements, it sounds like he'd be happier with a polished scripting language like Python or Ruby. Concurrency is important, but there's a lot to learn first.
Mike Douglas
@Vainstah - That's fine, but how are the JVM's synchronization primitives relevant to the performance of a functional program with no mutable state?
Joel Mueller
I don't know much about these new JVM front-end languages; however, just because programming languages provide constructs to express concurrent programs does not mean the libraries they depend on do not use any shared state. At the end of the day the infrastructure libraries constitute most of the code present in a process image. In terms of dynamic language implementations (the resulting application code), Python uses a global lock and Lua likes to only have one thread active in an environment. I wonder what Scala And clojure do ? From what I know MT and "no-mutable-state" don't mix.
Hassan Syed
If you really wonder what Scala and Clojure do, you can scroll down to Concurrency for the Clojure perspective: http://www.bestinclass.dk/index.php/2009/10/python-vs-clojure-evolving/
Joel Mueller
Thank you, I will have a look when time permits.
Hassan Syed
+11  A: 

my suggesting is to learn javascript ..

i mean really learn it

Scott Evernden
server side javascript, thats not very productive....
Hassan Syed
you've not heard of Rhino i guess .. http://ejohn.org/blog/bringing-the-browser-to-the-server/
Scott Evernden
a good grasp of javascript seems to really go well with PHP because of the web platform. it'll also be important for any other web language. i think a plunge into javascript is a healthy step.
Good Time Tribe
I agree, but spitting out the correct pages comes first. Python:Pylons (for the spitting) + and client-side Javascript:mootools = love from my experience.
Hassan Syed
A: 

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!

Alan Storm
I'd suggest a trajectory PHP -> Ruby -> Scala -> O'Caml -> Haskell, because to my thinking Scala is basically a better Java unless you're *really* committed to treating it like a functional language, so it shouldn't really be considered an endpoint. You can post Clojure as a possible endpoint, but some people prefer more syntactic differentiation than LISPs can give you on a day-to-day basis.
Ken Bloom
I disagree. Take the plunge. Why ease into it. The point is to challenge and expand your mind so just jump into it and let the shock of everything new teach you.
Jeremy Wall
Because some people (not all people, and clearly not you) can only learn something if it has direct application to the kind of things they're already working on. If the OP was a take teh plunge kind of person, they'd have already plunged :)
Alan Storm
The Pragmatic Programmers recommend learning one new language every year. At that rate, this program would occupy what, 4 years? Sounds a bit ambitious to me.
Carl Smotricz
+3  A: 

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.

Frank Schmitt
+10  A: 

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.

Joel Mueller
Scala/Clojure - level of indirection built upon on the JVM. Java has some frameworks and some tools, but the level of indirection screws with those. A PHP programmer wanting to move onto something better does not want a level of indirection messing with him.
Hassan Syed
The OP asks if he should learn Scala or Clojure, tags the question with scala and clojure tags, and in addition specifically says he wants to learn functional programming, and I get a downvote for linking to a comparison of Scala and Clojure? Why don't you let the PHP programmer decide what he wants?
Joel Mueller
Yeah I think Vainstah downvoted just about all of us, LOL.
Kaleb Brasee
If you think that Scala/Clojure on JVM adds a "level of indirectment" when compared to Java on JVM you simply don't understand what you're talking about. The JVM executes bytecode and NOT Java. It may be tailored to the needs of Java, but that's a different thing.
ziggystar
I, too, strongly object to Vainstah's comment as... uninformed, to put it politely. Clojure's integration with the JVM and Java libraries is VERY smooth and complete. There are many instances where it's more painless to call Java code from Clojure than from Java!
Carl Smotricz
A: 

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.

Matt Champagne
and a natural transition from php, since php is loosely based-on perl
warren
Personal opinion, of course, but I'd consider this jumping from the frying pan to the griddle. Perl is popular because of its ubiquity, but in terms of learning useful techniques of sound, clean programming Perl is a train wreck on its way down a volcano.
Carl Smotricz
+5  A: 

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.

Daniel
+16  A: 

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.

Ryan McGeary
Yes, this is the only correct answer. Learn everything and pick the one you like the most. There is no downside to doing so.
Brian Carper
I work in Java and I love Scala, but there's only two languages one should learn: Lisp and Haskell
GClaramunt
I agree with Ryan, but disagree with Brian and GClaramunt. Every problem has more than one correct answer, but sometimes choosing the best answer involves using a different language. THAT's why you should have as many languages under your belt as possible.
Dolph
There is no doubt that the more languages we know the better. I wonder how someone could think otherwise. It is important to only a question of the order of learning them.
Maciek Sawicki
+4  A: 

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.

Vijay Mathew
+4  A: 

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).
Apocalisp
+8  A: 

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.

Carl Smotricz
+1  A: 

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.

Carl Smotricz
+1  A: 

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.

Alexey
+1  A: 

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.

openfrog
+1  A: 

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.

Frank Denis