7

If you had to explain Lambda expressions to a 5th grader (10/11 years old), how would you do it? And what examples might you give, or resources might you point them to? I may be finding myself in the position of having to teach this to 5th grade level developers and could use some assistance.

[EDIT]: The "5th Grader" reference was meant to relate to an American TV show which pits adults vs. 5th graders in a quiz type setting (I think). I meant to imply that the people who need to be taught this know nothing about Lambda's and I need to find a way to make things VERY simple. I'm sorry that I forgot this forum has a worldwide audience.

Thanks very much.

Randy Minder
  • 47,200
  • 49
  • 204
  • 358
  • 6
    Just so us non US residents don't have to go off and research it, what age range are "5th graders" – Ben Robinson Jun 03 '10 at 11:32
  • 1
    Generic advice: build on something they already know. Do they already now something about delegates, function pointers, functional programming, lambda calculus, ...? What's their background? If they're just starting to learn programming, are you sure lambda expressions or even C# are the right things to teach to them? – dtb Jun 03 '10 at 11:35
  • 1
    In US schools, 5th grade is primary school level at about age 10-11. http://en.wikipedia.org/wiki/Fifth_grade – spoulson Jun 03 '10 at 11:37
  • Some answers here might help: http://stackoverflow.com/questions/2167360/lambda-for-dummies-anyone-anyone-i-think-not – IAbstract Jun 03 '10 at 11:39
  • @Ben - Very sorry. The "5th' grader reference relates to an American TV show about adults vs. 5th grade students in a quiz show of sorts (I think). I meant to imply the people who need to be taught this no nothing about the subject. – Randy Minder Jun 03 '10 at 11:42
  • 1
    @Randy, yeah we have that in the UK too, it's just called "are you smarter than a 10 year old" ;-) – Ben Robinson Jun 03 '10 at 11:52
  • 2
    Pervert! a 10 years kid shouldn't know what a lambda is! I call it lost innocence (jk) – mati Jun 03 '10 at 13:11

7 Answers7

6

Just call it a function without a name. If she has not been exposed to much programming her mind not already have been calcified in thinking that all functions should have names.

Most of the complexity related to lambda expressions is caused by complicated naming and putting it on a marble pedestal.

Lot's of kids create great websites with lot's of Javascript stuff. Chances are they are using lambda expressions all the time without knowing it. They just call it a 'cool trick'.

Peter Tillemans
  • 34,983
  • 11
  • 83
  • 114
2

I don't think you need to explain lambda expressions to kids aged 10-11. Just show them how lambda expressions look like, what you can do with them, and where you can use them. Kids in that age still have the capability to learn something new without relying on analogies to understand it.

dtb
  • 213,145
  • 36
  • 401
  • 431
1

Lambda expressions are what I consider higher order programming. Rigorous explanation will require extensive prerequisite learning. Certainly, this is not practical at the 5th grade level.

However, it might help to just cover some concepts by example in a way that mirrors real life physical situations.

For instance, a scale is a sort of a lambda expression. It tallies the mass of the objects placed on it. It is not a variable because it does not store the number anywhere. Instead, it generates the number at the time of use. When used again, it recalculates based on its inputs. You can take it places and use it somewhere else, but the underlying mechanics (expression) is the same.

spoulson
  • 21,335
  • 15
  • 77
  • 102
1

if he already understands what "function" is that you can say that it is the function that you need only once and therefore it doesn't need a name.

Anyway, if you need to explain functional programming I would recommend to try to steal some ideas from http://learnyouahaskell.com/ - it's one of the best explanations of ideas behind functional programming I've ever read.

Andrey Taptunov
  • 9,367
  • 5
  • 31
  • 44
0

Lambda expressions in c# are basically just anonymous delegates so when explaining what they are to ANYONE they need to understand in this order:

What a delegate is and what they are used for.

What an anonymous delegate is and how it is just short hand way of creating a delegate.

Lambda expression syntax and how it is just really a even more short hand way of creating an anonymous delegate.

Ben Robinson
  • 21,601
  • 5
  • 62
  • 79
  • 1
    I'd say a delegate is a verbose way to write a lambda expression... why do students have to be taught language features in the order they were introduced in the language? – dtb Jun 03 '10 at 11:39
  • They don't have to be, i just think if you see the whole picture of what something is, where it came from and why it exists it helps you understand what to use it for. – Ben Robinson Jun 03 '10 at 11:51
0

Probably not the best thing to start explaining to a fifth grader if a cutting edge OO language (C#) didn't get it for 10 years.

Pretty hard to come up with an analogy for a function with no name... Perhaps it's significant because it's a less verbose way specify a callback?

Igor Zevaka
  • 74,528
  • 26
  • 112
  • 128
0

I'm assuming you're actually looking for a basic intro for programmers, not actual 5th graders. (For 5th graders, Python or JavaScript tend to be best). Anyways, two good introductions to C# lambda expressions:

The first (disclaimer - my blog) will give you a quick explanation of the fundamental concepts. The book provides complete coverage of all relevant topics.

David Thielen
  • 28,723
  • 34
  • 119
  • 193