Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disadvantages of First-class functions [closed]

Tags:

function

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

like image 548
Quintin Par Avatar asked Nov 25 '09 15:11

Quintin Par


People also ask

Why do we need first-class functions?

First-Class Function: A programming language is said to have First-class functions if functions in that language are treated like other variables. So the functions can be assigned to any other variable or passed as an argument or can be returned by another function.

Can you explain your level of understanding of first-class functions?

A programming language is said to have First-class functions when functions in that language are treated like any other variable. For example, in such a language, a function can be passed as an argument to other functions, can be returned by another function and can be assigned as a value to a variable.

What languages have first-class functions?

Functional programming languages, such as Erlang, Scheme, ML, Haskell, F#, and Scala, all have first-class functions. When Lisp, one of the earliest functional languages, was designed, not all aspects of first-class functions were then properly understood, resulting in functions being dynamically scoped.

Can first-class functions return functions?

First-class functions are functions that can be treated like any other value. You can pass them to functions as arguments, return them from functions, and save them in variables.


1 Answers

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.

like image 140
Anton Avatar answered Oct 13 '22 19:10

Anton