views:

1419

answers:

7

I know alot of Java people have started looking at Scala since it runs on the JVM, and alot of people in the Microsoft world are looking at F#, but what does Ruby have as a natural functional successor?

In a pure FP sense Ruby doesn't lack anything, instead it has too much some may say. A functional language forces the programmer to not use global variables and other idioms so much (although it is possible to use globals in functional languages)

+6  A: 

Ruby it self is a kind of Functional programming language, So I don't see any special dialects for FP using ruby.

Teja Kantamneni
It's a kind of functional programming language in much the same way that a scratch-and-sniff sticker is a kind of fruit. The hallmark of functional programming is being free of side-effects. Ruby is one of the hardest languages (if not the hardest) to write truly functional code in. Just creating a truly immutable data structure is nigh impossible in Ruby (even Fixnums can have mutable attributes added to them). Also, writing lots of true functions (that is, lambda functions rather than methods) is unidiomatic in Ruby, and functions have to be constantly converted between Procs and blocks.
Chuck
See http://yellowlab.com.au/blog/2009/09/15/functional-programming-in-ruby/ Ruby doesn't really cut it in regard to FP.
Synesso
+6  A: 

Any version of Lisp should be fine.

Nemanja Trifunovic
-1: The question isn't "what functional programming language should I use?", it's asking "what language do rubyists tend to use?"
Andrew Grimm
Thanks for the downvote, but the question is (and I quote the original): "what does Ruby have as a natural functional successor?" not "what language do rubyists tend to use?".
Nemanja Trifunovic
@Nemanja: You're welcome.
Andrew Grimm
+13  A: 

Java people are using a language on the JVM and want a more functional one compatible with their runtime, so they go to Scala.

C# people are using a language on the CLR and want a more functional one compatible with their runtime, so they go to F#.

Ruby people are using a language that's already pretty functional, and they're using it on a number of underlying runtimes (JRuby, IronRuby, MRI, MacRuby, Rubinius, etc...). I don't think it has a natural functional successor, or even needs one.

Michael Greene
+2  A: 

In hype level, Haskell.

Tor Valamo
I've seen Haskell, and think it is a beautiful language, and its Type system, Monads and Software Transactional Memory are amazing. I'm not sure how good it is for distributed systems though, I need educating on that still.
Zubair
+2  A: 

Ruby isn't as functional as say Lisp, but it is just functional enough that you can do some functional programming in a good fun way. (unlike trying to do functional programming in something like C#)

Also, it actually forces you into functional paradigms in some of it's syntax, such as the heavy use of blocks and yield. (which I fell in love with after learning Ruby).

Earlz
Why can't you do functional programming in C# so easily (just for my personal knowledge, please don't start a flame war anyone!)?
Zubair
Sure, it's possible.. C# even has stuff like lambda and anonymous functions.. But really, it's fugly and the C# API for .Net is geared for non-functional coding. Sure you can fit a round peg in a square hole, but it makes more sense to use a square peg or an almost square(ie, ruby) peg
Earlz
Ok, that makes sense. But doesn't F# that use the same .NET runtime as C#?
Zubair
F# has a library of core functional data types and algorithms, as well as type inference and various syntactic niceties that make it much more pleasant to do FP in F# compared to C#. You still hit some impedence mismatch with various .Net APIs that are more imperative/OO, but these typically happen at the fringes of your F# app/library, rather than in the heart of what you're doing.
Brian
Interesting. I'll have to look into F# some more.
Zubair
+40  A: 
Jörg W Mittag
This is an amazing response -- I'm glad to see someone touching on the idea that functional programming is about more than just language constructs like closures and first-class functions. Whenever I hear people say that "Ruby is functional enough" I cringe a bit -- as your second bullet item notes, functional programming is more about a style and methodology than specific language features.
mipadi
Great answer. And to back up your suggestion of Erlang as a FP language Rubyists like: The creators of Ruby On Rails, 37signals, blogged a while back about how they had rewritten part of their apps in Erlang to get better performance.
Chuck
It depends. The term "functional programming" was invented for Lisp, which is very much impure, stateful, effectful, imperative or whatever you want to call it. (Except for Scheme and Clojure, both of which didn't exist yet when the term was invented.) The most widely used Lisp is CommonLisp, which isn't functional *at all* according to the mathematical definition of "function". People have proposed to call the second category "value-oriented programming" or "pure functional programming" to clear up the confusion. Martin Odersky (designer of Scala) calls them the "inclusive" and "exclusive"
Jörg W Mittag
... definitions, because the first one *includes* a lot of languages, even ones that are usually *not* considered functional (like Ruby), while the second one *excludes* a lot of languages that *are* usually considered functional, like ML, OCaml, Scala, F#, Erlang and Lisp. Proponents of the second definition also often include things like pattern matching, higher-rank parametric polymorphism, astract datatypes, algebraic datatypes, powerful expressive static type systems and type inference, currying, partial functions in their definition, which excludes even *more* languages.
Jörg W Mittag
Lisp does not force functional programming as strongly as other languages, but it still does a lot more to enable it than most languages, and certainly more than Ruby. And though Common Lisp is more popular, it's generally considered a hybrid language, while Scheme is more strongly functional. Anyway, Lisp is quite old. C was once considered a high-level language too, but that doesn't make it a paragon of that philosophy.
Chuck
Jörg, thank you for your detailed response, probably the best to any quesiton I have asked on StackOverflow yet. I learnt alot from it.
Zubair
+2  A: 

Assuming Ruby people don't just go to the JVM themselves, I think most would adopt Erlang, being another dynamically typed language.

Shaun
Yes, I have seen alot of Ruby people move to Erlang.
Zubair