Question: I'm giving a small presentation to a group of C/C++ programmers who have very little experience with functional languages. Part of the presentation mentions Erlang, and I would like to give a specific small code example. 

There is a ton of awesome information on StackOverflow about how/where Erlang is used and its advantages. One of the most common advantages I see is how it can do a lot with just a little terse code, especially compared to C/C++. 

I am looking for a good code snippet of Erlang that simply illustrates these types of benefits. Especially something thats easily done in Erlang with few lines, that would be much more complicated in C/C++.

Anyone have any interesting suggestions?

Answer: 
Check out [example 4](http://www.erlang.org/doc/programming_examples/bit_syntax.html) for an excellent example of Erlang's bit syntax. I'm sure there are a number of c/c++ developers that will appreciate the brevity of the syntax!
the factorial code snippet is the best i have always used to show how short erlang programs can be

```

-module(factorial).
-export([calculate/1]).

calculate(0) -> 1;
calculate(N) -> N * calculate(N -1).

```

As simple as that. That short program illustrates not only how short Erlang programs can be, But also: `**[Pattern Matching](http://en.wikipedia.org/wiki/Pattern_matching)**`, `Function Clauses` and **`[Last Call Optimization](http://en.wikipedia.org/wiki/Tail_call)`**.   

 I always had a C++ version of the same, below:

```

#include<iostream.h>
#include<conio.h>

long factorial(unsigned int a);

void main() {
    unsigned int a;
    long fac;
    .....
    .....
    return factorial(a); 
}

long factorial(unsigned int x) {
        long fac=1;
        if(x == 0) {return 1;}
        else {
                while(x > 0) {
                    fac *= x;
                    x -= 1 ;
                }
        return fac; } 
}

```

Well, this may not be the shortest C++ version, but i know you get the idea.