Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've programmed a bit of Haskell and Prolog as part of a couple of uni courses, but that's about it. And I've never seen it been used in industry (not that I've had much of working experience to begin with but I've never seen an ad where you are required to know them).

So should we be using functional and/or logic programming languages more often? Are there any advantages or disadvantages for using or not using them?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

I believe in using the right tool for the job. Both imperative and functional languages have their place and there's no need to push for using one kind more than the other.

For the advantages/disadvantages, I don't think I could beat Eric Lippert's answer to the "Why hasn't functional programming taken over yet?" SO question.

share|improve this answer
    
Hmm? Why the downvote? –  Anna Lear Sep 16 '10 at 15:42
1  
I haven't downvote but I disagree with his answer (such as 'mistaking' concurrency and parallelizm - in functional world those terms means 2 different things). However it does not mean I think it is bad answer. –  Maciej Piechotka Sep 16 '10 at 18:28
    
Indeed, Eric Lippert's was a very informative answer. Thanks for the direction. –  gablin Sep 16 '10 at 22:12

First of all - because the compiler have to do much more. If you want to create imperative compiler you can nearly do 1-1 transformation to assembler and the code produced will have acceptable speed (sure - there could be much to do but it is 'basicly' 1-1 compilation + optimalisation). Functional compilers HAVE TO handle well heavy inlineing, tail-call optimalisation etc. Therefore implementation of functional languages were much slower then C/C++/... in past (however they gain much speed each iteration as compilers are getting better).

Secondly - programmers are so used to state that they cannot 'accept' "there is no spoo... state" approach. Sure - the lack of state is not useful in each condition but the lack of (global) state does not mean lack of local state.

Thirdly - functional programming have no nice story behind it. The OOP have nice story as the objects maps to nouns and how intuitive it is. Afterwards you know that it is not so simple because you cannot create a class Manager as subclass of Employee as Employee may get promote to Manager and you have to play around decorators. The functional programs have story in mathematics which is IMHO more useful but less marketable.

As internally from the computer perspective - there is no difference between parallel and concurrent computing many programmers do not see a difference and many languages have the same primitives to handle both. Thank to lack of local state and lightweight threads in functional programming languages the parallelisation of algorithm is much easier. However concurrent programming is not made automatically easier as concurrency is about global state.

Finally - there is a lot of older programs written in inperative style. Even porting from imperative language to imperative language is much simpler then to functional one.

As far as I know investment banks start embracing the functional programs internally so they DO come into XXI c. (in very important although hidden area) - so they do gain momentum.

PS. While I believe that functional programs are "better" in meaning they hide the complexity better then other approaches it does not mean that there are no areas such as scripts that are inherently imperative.

share|improve this answer

A programming language is a form of representation of information. In this case instructions for the computer to follow. However, the representation also is important for the target audience (i.e. the programmers).

Functional/logical concept are not as commonly used in daily life as procedural concepts. If you read instructions (i.e. how to use your television, dvd player, or build some furniture from IKEA), they are mostly written in a procedural way (albeit in natural language).

Therefore, a lot of people that are not very deeply involved in math or sciences often are far more familiar with such procedural concepts than the logical or functional ones.

I think this has a lot of impact in the choice of which class of programming language is used. In the end, the set of problems that can be solved with any of such programming languages is pretty much the same (as long as they are all turing complete).

However, a lot of procedural languages obtaining more and more facets of other concepts. Python can do lambda-calculus and closures, ruby as well. Javascript which is haevily used in industry is actually really a functional language (even most people "misuse" is by using it more in a procedural way). Therefore, it is really the task of the programmer to use those features appropriately where they fit.

share|improve this answer
1  
Since when is JavaScript a functional language? –  Jonas Sep 16 '10 at 15:26
1  
@Jonas - It is indeed a functional language and it always has been. Of course a language can follow many paradigms at once as JavaScript does. –  ChaosPandion Sep 16 '10 at 16:17
1  
@ChaosPandion: Just because it has closures and high order functions? :) –  Jonas Sep 16 '10 at 16:38
    
@Jonas - Indeed, obviously we are not talking Haskell here but you can still call it functional. –  ChaosPandion Sep 16 '10 at 17:06
2  
I guess that you should consider general approach to problem in idiomatic way. Hence if programming langauge suggest to split problem into pure functions it is functional. If it suggest to split problem into objects it is object-oriented. If it suggest to "do this and then do that" it is imperative. Hence lambdas, continuations etc. are not necessary features only for functional languages and JS is not a functional language as it does not 'suggest' to think in terms of functions and immutable data. –  Maciej Piechotka Sep 16 '10 at 18:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.