The Artima Developer Community
Sponsored Link

Artima Developer Spotlight Forum
Will Functional Programming Go Mainstream?

61 replies on 5 pages. Most recent reply: Aug 16, 2006 10:50 AM by Alex Fabijanic

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 61 replies on 5 pages [ 1 2 3 4 5 | » ]
Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Will Functional Programming Go Mainstream? Posted: Aug 3, 2006 3:55 PM
Reply to this message Reply
Advertisement

In Can Your Programming Language Do This?, Joel Spolsky shows a few examples in JavaScript of using a function as a value. In one example, he demonstrates the use of anonymous functions, which are unnamed and defined right where they are used. He claims that:

...Programming languages with first-class functions let you find more opportunities for abstraction, which means your code is smaller, tighter, more reusable, and more scalable.

While not a purely functional language, the Ruby language does facilitate a functional style of programming, and it has seen a rather significant rise in popularity of late. In the Java world, the Scala language facilitates a functional programming style on the JVM.

To what extent do you think functional programming will become more mainstream in commercial development?


Morgan Conrad

Posts: 307
Nickname: miata71
Registered: Mar, 2006

Re: Will Functional Programming Go Mainstream? Posted: Aug 3, 2006 5:58 PM
Reply to this message Reply
All those "easy" little anonymous function blocks are a maintenance and scalability nightmare. In OO terms, they can't be readily extended or subclassed.

If parallelizing all of Google is worthwhile, declaring a simple Java interface for the functions is really a tiny, tiny price to pay to do it in an extensible and maintainable fashion.

Dick Ford

Posts: 149
Nickname: roybatty
Registered: Sep, 2003

Re: Will Functional Programming Go Mainstream? Posted: Aug 3, 2006 6:41 PM
Reply to this message Reply
C# and VB programmers will be when C# 3.0 and VB 9 comes out. I have no idea what is in store for Java.

Leandro Oliveira

Posts: 21
Nickname: lao
Registered: Aug, 2003

Re: Will Functional Programming Go Mainstream? Posted: Aug 3, 2006 9:08 PM
Reply to this message Reply
AFAIK, little named functions can also become a nightmare. When all you need to do is apply a simple function to every element in a list (e.g. multiply by a constant), why name the function? How would you name it? multiplyByFour? :-)
A good programmer will know when to use a named or unnamed function. Just because it's not the Java way, that doesn't mean it's bad or unmaintainable.

Leandro Oliveira

Posts: 21
Nickname: lao
Registered: Aug, 2003

Re: Will Functional Programming Go Mainstream? Posted: Aug 3, 2006 9:23 PM
Reply to this message Reply
> <p>To what extent do you think functional programming will
> become more mainstream in commercial development?
> </p>

I think it is an evolution of current programming languages (and practices). Some (good) ideas of functional programming will get mainstream acceptance, but that will not really change the way we write software. It will just make us, programmers, a little more productive.

Kannan Goundan

Posts: 18
Nickname: cakoose
Registered: Nov, 2005

Re: Will Functional Programming Go Mainstream? Posted: Aug 3, 2006 11:14 PM
Reply to this message Reply
Why do you think they hinder maintenance or scalability? Good abstraction improves maintainability.

Just as with any other complex computation, if you use it more than one place give it a name and keep it in a common location. But if you only ever use it once, and it is short enough that its purpose is clear, I don't see why creating a class or interface for it is helpful.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 12:07 AM
Reply to this message Reply
> All those "easy" little anonymous function blocks are a
> maintenance and scalability nightmare. In OO terms, they
> can't be readily extended or subclassed.
>
Well, I think you wouldn't use an anonymous function unless it was a one-shot that you didn't need to override someday in a subclass. Why do you think that would be a maintenance nightmare? If you later decided you indeed want to use it in more than one place, couldn't you simply give it a name? If you even later decide that it belongs in a class that you can subclass, couldn't you move it there? But meanwhile, the one-shots that remain can be expressed succinctly.

> If parallelizing all of Google is worthwhile, declaring a
> simple Java interface for the functions is really a
> tiny, tiny price to pay to do it in an extensible
> and maintainable fashion.
>
Well, it may be a small price to pay once, but the price accumlates each time you have to pay. And I think that the succinctness of anonymous functions has a maintainability benefit: there's just less clutter in your face when trying to understand the code. Moreover, you aren't prevented from overriding it someday. At that point, when you actually need it, you can pay the price of making the class or interface and class, and naming the function.

Roland Pibinger

Posts: 93
Nickname: rp123
Registered: Jan, 2006

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 1:35 AM
Reply to this message Reply
> While not a purely functional language, the <a
> href="http://www.ruby-lang.org/">Ruby language</a> does
> facilitate a functional style of programming, and it has
> seen a rather significant rise in popularity of late. In
> the Java world, the <a href="http://scala.epfl.ch/">Scala
> language</a> facilitates a functional programming style on
> the JVM.
> </p>
> <p>To what extent do you think functional programming will
> become more mainstream in commercial development?
> </p>

The last functional programming language that was expected to hit the mainstream was XSLT. We were supposed to write XML tagged text to be converted by XSLT into different output formats (HTML, PDF, ...). But people preferred and prefer PHP for that kind of work.
IMO, functional programming is too difficult to become mainstream (JavaScript isn't used primarily for it's support for functional programming).

Kannan Goundan

Posts: 18
Nickname: cakoose
Registered: Nov, 2005

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 2:15 AM
Reply to this message Reply
The last functional programming language that was expected to hit the mainstream was XSLT.

It's not fair to take a crappy domain-specific language like XSLT and use it to make conclusions about all of functional programming.

Higher-order fucntions (what Joel was talking about) are great. Try them out. I think most people would eventually prefer the "map" function over an explicit loop; they just need to get used to it.

Roland Pibinger

Posts: 93
Nickname: rp123
Registered: Jan, 2006

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 2:23 AM
Reply to this message Reply
> The last functional programming language that was
> expected to hit the mainstream was XSLT.

>
> It's not fair to take a crappy domain-specific language
> like XSLT and use it to make conclusions about all of
> functional programming.

XSLT is not at all "crappy". It's just complicated. Only KISS features survive in the mainstream (which is a Good Thing, IMO).

haluk guner

Posts: 4
Nickname: hag
Registered: Nov, 2005

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 3:18 AM
Reply to this message Reply
most definitely.

Are you also aware of the fact that most of the design patterns will not be required with functional programming. Instead of a design pattern you have the solid implementations of the higher level functions ( (map, fold, reduce etc.) ready to be used.

Even more important factor is that with functional programming writing re-usable code stops being an issue. With their cleanly defined inputs & outputs all your functions are fully reusable full stop. You don't have to make any special effort in order to make your functions re-usable, they are usable by default. In which case your problem becomes producing something useful. As long as you produce something useful, it can be (re)used by anyone without any special effort.

On the contrary, producing a re-usable OO system needs a lot of effort. You need a lot of training (Design patterns & principles), studying and decent level of understanding of these concepts, together with fare amount of practice and experience in order to create an above average good structured system.

The difference is the huge amount of effort that is required solely in order to be able to use the OO tools/languages effectively which is one of the most fundamental problems of our industry:

"Developers spent/waste most of their time (%60-70) struggling with their languages, tools or technologies, instead of the domain problem that should be their main objective"

No (proper) engineering discipline will allow this.

In short, functional languages, tools or technologies will eventually become mainstream especially when businesses or project sponsors realize that the selection of the tool or the technology is too important a decision to be left to programmers alone, whose judgments are clearly clouded by their personal likes, dislikes and the CV++ factor.

Terje Slettebø

Posts: 205
Nickname: tslettebo
Registered: Jun, 2004

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 4:07 AM
Reply to this message Reply
> > <p>To what extent do you think functional programming
> will
> > become more mainstream in commercial development?
> > </p>
>
> The last functional programming language that was expected
> to hit the mainstream was XSLT. We were supposed to write
> XML tagged text to be converted by XSLT into different
> output formats (HTML, PDF, ...). But people preferred and
> prefer PHP for that kind of work.

Actually, at our company, we're in the process of separating the HTML from PHP, and use XSLT as our HTML template engine, and this has resulted in a much cleaner system (mostly from the separation of application logic and presentation, though).

An XML-based system like XSLT is typically more suited for XML manipulation than PHP, as it's all XML/XHTML (and thus also easier to modify with HTML-editors), rather than jumping in and out of PHP mode in a template file. However, there are differing opinions on this, too, some prefering to use PHP as a template engine in its own right.

Jules Jacobs

Posts: 119
Nickname: jules2
Registered: Mar, 2006

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 4:42 AM
Reply to this message Reply
> All those "easy" little anonymous function blocks are a
> maintenance and scalability nightmare. In OO terms, they
> can't be readily extended or subclassed.

OO-only programmer?

You can extend anonymous functions by wrapping them. This is like decorators in python.

irb(main):008:0> a = lambda {|i| i * 2}
=> #<Proc:0x02ace390@(irb):8>
irb(main):009:0> b = lambda {|i| a.call(i + 2)}
=> #<Proc:0x02aca010@(irb):9>
irb(main):010:0> a.call 3
=> 6
irb(main):011:0> b.call 3
=> 10


Is a class more extensible than this?

It doesn't make sense to subclass an anonymous function because it isn't a class. The integer 4 isn't a class either, so you can't subclass it. (with a prototype based object model you can subclass an instance. So 4 and an anonymous function can be subclassed). You *can* subclass the Proc class in Ruby.

class Prok < Proc
  def call(a)
    super(a + 2)
  end
end
 
Proc.new {|a| a * 2}.call(4) => 8
Prok.new {|a| a * 2}.call(4) => 12


But this doesn't make sense because it can be done better & easier by wrapping a lambda.

Functional programming already is going mainstream with Ruby. Ocaml (or a new language) will follow because Ruby is too slow, and then maybe Lisp (Java programmer: hey it's like executable XML like Ant, but better!).

There probably will be a hybrid OO/imperative & functional language like Ruby, Ocaml and Lisp: not purely functional.

> If parallelizing all of Google is worthwhile, declaring a
> simple Java interface for the functions is really a
> tiny, tiny price to pay to do it in an extensible
> and maintainable fashion.

Haskell:
(*2)

- or -

Java:
class TimesTwo implements SideEffectFree {
   int call(int a) {
      return a * 2;
   }
}
 
// ...
 
new TimesTwo();

Kay Schluehr

Posts: 302
Nickname: schluehk
Registered: Jan, 2005

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 5:43 AM
Reply to this message Reply
> All those "easy" little anonymous function blocks are a
> maintenance and scalability nightmare. In OO terms, they
> can't be readily extended or subclassed.

I partially agree with this. Passing e.g. \i -> i+1 to another function is actually passing an implementation around instead of a name that abstracts from the implementation. But this becomes a larger maintenance problem only if you have to synchronize behaviour across different method calls: when you want to pass \i -> i+1 to different methods and have to adapt all of them at the same time when you are going to change one of them. But what is the alternative? Maintaining a stateless utility class ( which is essentially a function library ) that defines plusOne, minusN, squarePlusOne... ? This looks just stupid, because you might hide the implementation but you only replace it by a name that is just the desciption of the implementation. In the end you have to change both the names and the implementation to stay consistent => more maintenance effort. If your argument isn't just driven by ideology I would like to know what you propose to do in this case?

Merriodoc Brandybuck

Posts: 225
Nickname: brandybuck
Registered: Mar, 2003

Re: Will Functional Programming Go Mainstream? Posted: Aug 4, 2006 8:53 AM
Reply to this message Reply
> All those "easy" little anonymous function blocks are a
> maintenance and scalability nightmare. In OO terms, they
> can't be readily extended or subclassed.
>
> If parallelizing all of Google is worthwhile, declaring a
> simple Java interface for the functions is really a
> tiny, tiny price to pay to do it in an extensible
> and maintainable fashion.

In functional programming you aren't often concerned with readily extending or subclassing anything. You are usually more concerned with creating simple building blocks so you can easily compose more complex functions out of smaller, simpler blocks. It's a totally different way to think about building programs and comparing the two will just lead you to all sorts of bad conclusions about one of the two programming methodologies if you are only comfortable in one of them.

I don't see how function blocks are anymore of a maintenance and scalability nightmare than dealing with bloated over-architected OO code. Scalability and maintenance nightmares can arise using any programming paradigm or language. Besides, most large systems are going to be constructed out of something more formal than anonymous function blocks.

As for functional programming becoming mainstream, I don't think it will happen. It's hard to really wrap your head around functional programming compared to the procedural/OO model. The past decade or so has seen a lot of people spend a lot of effort to try and dumb down programming models. I can't imagine that we are suddenly all going to shift gears and make it harder. As several people already mentioned, some of the simpler and easy to apply concepts will become more mainstream as .NET adopts them, but I don't know how often they will get used.

More than likely people will end up using the concepts without really realizing what they are doing because libraries and language constructs like Google's MapReduce will become more widespread where that sort of solution makes sense. To the end user who isn't familiar with what is going on under the covers they will simply be using a macro or subclassing their class from the 'Parallelize' (or something similarly named) base class and will be required to implement methods where inputs and outputs are cleanly defined and all the functional 'black magic' will go on without them even knowing they are using functional programming.

Flat View: This topic has 61 replies on 5 pages [ 1  2  3  4  5 | » ]
Topic: Geir Magnusson on Open Source Java Previous Topic   Next Topic Topic: Cameron Purdy on Dealing with Failure

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use