Tag Info

Hot answers tagged

73

There's certainly a noticeable trend towards functional programming, or at least certain aspects of it. Some of the popular languages that at some point adopted anonymous functions are C++ (C++11), PHP (PHP 5.3.0), C# (C# v2.0), Delphi (since 2009), Objective C (blocks) while Java 8 will bring support for lambdas to the language . And there are popular ...


59

Look up "bootstrapping". Basically you start with a very minimal process/set of functions that can be used to compile the code that defines a slightly more functional compiler. This creates your next compiler which then can then be used to build code that can do even more. You repeat this process until you have a full blown compiler that can compile all the ...


54

I can't find the right post anymore, but Eric Lippert (and possibly several other softies) have opined on several occasions about how Linq is declarative, which, for several classes of problems, is far more intuitive than imperative syntax. Linq enables you to write code that expresses the intent, not the mechanism. You tell me which is easier to read. ...


46

Co-Worker: Lets be honest here. Linq syntax sucks. It's confusing and non-intuitive. You can't argue with that criticism. For your coworker, it sucks. We failed to design a syntax that, for them, was clear and intuitive. That's our failing, and you can pass on my apologies to your coworker. I am happy to take suggestions on how to make it better; what ...


46

Yes, use them. I am a junior developer, and I know/understand lambdas (and the other concepts you mentioned). There is nothing I could forsee preventing a junior developer from learning all of those concepts in a very short amount of time. Juniors may not have the same amount of experience/expertise when it comes to many gotchas of software development, ...


29

Lambda calculus The lambda calculus is a computation model invented by Alonzo Church in the 30s. The syntax and semantics of most functional programming languages are directly or indirectly inspired by the lambda calculus. The lambda calculus in its most basic form has two operations: Abstraction (creating an (anonymous) function) and application (apply ...


29

Yes, it's simply a recurring phrase in the title of several papers, starting from a couple in the 70s, in which Sussman and Steele demonstrate the use of lambda calculus for programming, by means of a minimalist Lisp dialect named "Scheme" they devised for the purpose. You can find the papers themselves here; they're interesting and surprisingly relevant. ...


26

The word "lambda" or "lambda expressions" most often refers to anonymous functions. So in that sense a lambda is a kind of function, but not every function is a lambda (i.e. named functions aren't usually referred to as lambdas). Depending on the language, anonymous functions are often implemented differently than named functions (particularly in languages ...


26

I think its interesting how much the popularity of functional programming has paralleled the growth and proliferation of Javascript. Javascript has a lot of radical features along the functional programming spectrum that at the time of its creation (1995) were not very popular among mainstream programming languages (C++/Java). It was injected suddenly into ...


26

There's a fair bit of incorrect information in ratchet freak's answer and in its comment thread. I'll respond here in an answer, since a comment is too small. Also, since this an answer after all, I'll attempt to answer the original question too. (Note however that I am not an expert on type systems.) First, the short answers to the original question are ...


23

JavaScript and DOM event handlers meant that millions of programmers had to learn at least a little bit about first class functions in order to do any interactivity on the web. From there, it's a relatively short step to anonymous functions. Because JavaScript doesn't close over this, it also strongly encourages you to learn about closures too. And then ...


20

If they're a sensible solution to your problem then you should use them. Don't artificially restrict yourself - you're more likely to end up with poor quality code that's hard to maintain. If the code is well written with appropriate comments then those following on should be able to learn from you.


20

tl;dr: while it's mostly syntactic sugar, that nicer syntax makes lots of things practical that used to end in endless, unreadable lines of braces and parentheses. Well, it's actually the other way around as lambdas are much older than Java. Anonymous inner classes with a single method are (were) the closest Java came to lambdas. It's an approximation that ...


19

Guido van van Rossum answered it himself: But such solutions often lack "Pythonicity" -- that elusive trait of a good Python feature. It's impossible to express Pythonicity as a hard constraint. Even the Zen of Python doesn't translate into a simple test of Pythonicity... In the example above, it's easy to find the Achilles heel of the proposed ...


16

Like anything else in the programming world, you gotta get used to the syntax, and then it is (potentially) easier to read. Like anything else in the programming world, there is the potential for spaghetti code or other abuses. Like anything else in the programming world, you can either do it this way or another way. Like anything else in the programming ...


16

The problem seems to be that junior developers and others don't necessarily understand what the function pointer\delegate\lambda function concept is Quite frankly, that's their problem. That's what you ensure they have training for. You can't not use a good technique just because some people might not understand it. If they need help with it, they ...


15

Basically, lambda functions are functions you create "on the fly". In C++1x they could be used them to improve on its support for functional programming: std::for_each( begin, end, [](int i){std::cout << i;} ); This will roughly result in code similar to this one: struct some_functor { void operator()(int i) {std::cout << i;} }; ...


15

I think the discussion regarding objects vs. functions is a red herring. If the question is, "Is a lambda a function or an object?" the answer should be yes. That's the point of first-class functions: they aren't treated differently than any other type. Java already manages to mostly ignore the differences between Object and primitive types (and Scala ...


15

Bootstrapping is definitely the standard way to build a compiler today. But remember that you don't need a compiler or interpreter to write a program in a language. For instance, Christopher Strachey wrote a famous AI program that was able to play Checkers in CPL before there was a compiler for CPL. He had to translate the program to machine code "manually", ...


14

The use case for lambdas are those situations where you need to create a simple small function object that is not meant to be reused. Lambdas represent a simple way of doing so. Some of the basic use cases will involve using the standard library algorithms: std::vector<double> data = get_data(); std::transform( data.begin(), data.end(), data.begin(), ...


14

Lambda The Ultimate refers to the idea that the lambdas of lambda-calculus can effectively implement every builtin concept in every programming language, past, present, and future. Classes, Modules, Packages, Objects, Methods, Control-Flow, Data Structures, Macros, Continuations, Coroutines, Generators, List Comprehensions, Streams, and so on. As it ...


13

Put a link to the msdn documentation in comments at the top of a block that uses it then go ahead. You shouldn't be scared to use new/complex technology, its part of a developers job to learn things they don't know.


13

As Yannis pointed out, there are a number of factors that have influenced the adoption of high-order functions in languages that were previously without. One of the important items he only touched lightly on is the proliferation of multi-core processors and, with that, the desire for more parallel and concurrent processing. The map/filter/reduce style of ...


13

It certainly isn't the only factor, but I'll point out the popularity of Ruby. Not saying this is more important than any of the six answers already on the board, but I think that many things happened at once and that it's useful to enumerate them all. Ruby is not a functional language and its lambdas, prods, and blocks seem clunky when you've used ...


12

Looking at the compiled code through ILSpy, there actually is a difference in the two references. For a simplistic program like this: namespace ScratchLambda { using System; using System.Collections.Generic; using System.Linq; using System.Text; internal class Program { private static void Main(string[] args) { ...


11

ChrisF's answer is excellent, but I wanted to add this example that always stuck by me after my computer science course on bootstrapping. Suppose you have a basic C compiler that does not support escape codes for strings yet, and you wanted to add that. You could add a snippet of code similar to this: if( str[i] == 0x5c ) { // ASCII code for ...


11

Java has changed focus with time. At first it was designed as a simple powerful language, as a reaction to "powerful complex" C++. Some features that were in C++ were intentionally left out, like operator overloading, templates, enums, that were deemed too complicated or relics of the C era, and OOP being at the peak of its popularity, everything was made an ...


10

The problem seems to be that junior developers and others don't necessarily understand what the function pointer\delegate\lambda function concept is Then they need to learn them. Period. This is not an esoteric corner of C#. You must understand them to make use of many .Net libraries. This is not an esoteric language topic, in general. Virtually ...


10

Clojure doesn't have call/cc, but you don't want undelimited continuations anyway. We argue against call/cc as a core language feature, as the distinguished control operation to implement natively relegating all others to libraries. The primitive call/cc is a bad abstraction -- in various meanings of 'bad' shown below, -- and its capture of the ...


10

When Java was first designed it was considered appropriate to leave out anonymous functions. I can think of two reasons (but they might be different from the official ones): Java was designed as an object-oriented language without functions, so it was not very natural to have anonymous functions in a language without functions. Or at least, this would have ...



Only top voted, non community-wiki answers of a minimum length are eligible