views:

169

answers:

4

Are there any disadvantages to having first class functions in a language?

Joel in this entry says

"Object-oriented programming languages aren't completely convinced that you should be allowed to do anything with functions."

I might be naïve here, but why don’t all languages support first class functions if there aren’t much issues

+1  A: 

Adding this feature might be a disadvantage if introducing the change requires a costly re-write of language compilers, interpreters, and other tools. It might also be a disadvantage if the language's culture is not familiar enough with the advantages provided by this feature in which case adding the feature is a waste of effort.

jkndrkn
+3  A: 

In an ideal world where there was never a cost associated with developing new features, the only downside I can see to including functional programming techniques would be confusion to developers who are not familiar with functional techniques (and I don't really see that as much of a downside).

In reality, treating functions as first-class typically requires significant rewrites to the compiler itself. The cost of doing this has to be weighed against the long-term gain.

Anton
A: 

Why do you want that all languages support first class functions? Many programming fields simply don't need it.

mouviciel
+2  A: 

Additionally, first class functions require runtime interpretation of code and some form of garbage collection. Both of these add overhead that might not be suitable for certain problems and languages.

Kai
Not necessarily. There are languages with first class functions which aren't interpreted and don't have GC (f.e. C++). Closures are more difficult to implement without GC though.
liori