[erlang-questions] Erlang for youngsters

Fred Hebert mononcqc@REDACTED
Mon Jun 16 14:59:52 CEST 2014


Answers inline (and better seen through fixed-width font)

On 06/16, Torben Hoffmann wrote:
> I think that fault-tolerant, distributed programming is hard because there is a big
> context you need to address. The sheer about of things that can go wrong will make it
> difficult to get into.
> 
> I think that concurrent programming is easy to learn:
> 

I'm injecting myself in here to put emphasis on that part. The objective
here is to teach concurrent programming and fault tolerance, right?

> Here's a simple process that just acknowledges that it has received a message and
> continues to do so over and over again:
> 
> echo() ->
>   receive
>     Msg ->
>      io:format("I'm happy, 'cause I recevied: ~p~n", [Msg]
>   end,
>   echo().
> 
> The file example1.erl contains the echo function.
> Open up the Erlang shell:
> $ erl
> 
> c(example1).
> 
> (this compiles the code and now you can start an echo process)
> 
> Pid = spawn ( fun() -> echo() end ).
> 
> (you just stored the process identifier (Pid) for the process you spawn, so now you
> can send it a message:)
> 
> Pid ! "Erlang is cool".
> 
> "I'm happy, 'cause I received: Erlang is cool"


Here's what could be even nicer: have an IDE (or something like
scratch). Every process is its own block on the screen, visual:


 *-------------[echo]--------------------------* *----[ProcX]-----*
 | echo() ->                                   | |  ...           |
 |   receive                                   | *----------------*
 |       Msg ->                                |
 |         io:format("I'm happy, ...", [Msg])  | *---[Output]-----*
 |   end,                                      | |                |
 |   echo(),                                   | |                |
 *---------------------------------------------* *----------------*

Click 'run'. Click the process, and have a prompt that lets you write in
a message: "Erlang is cool". See the box hilighted when code runs there:

 *=============[echo]==========================*  *----[ProcX]-----*
 || echo() ->                                  || |  ...           |
 ||   receive                                  || *----------------*
 ||       Msg ->                               ||
 ||         io:format("I'm happy, ...", [Msg]) || *---[Output]-----*
 ||   end,                                     || |                |
 ||   echo(),                                  || |                |
 *=============================================*  *----------------*

see the output in another box:

 *-------------[echo]--------------------------* *----[ProcX]-----*
 | echo() ->                                   | |  ...           |
 |   receive                                   | *----------------*
 |       Msg ->                                |
 |         io:format("I'm happy, ...", [Msg])  | *===[Output]=====*
 |   end,                                      | || I'm happy,   ||
 |   echo(),                                   | || 'cause I ... ||
 *---------------------------------------------* *================*

Hell, at this point it no longer needs to be Erlang, if you really want
to teach the principles, and not the language. The question here really
is: what's the objective?

I mean, let people put colors on the boxes, even be able to change
their shapes and brightness and events and they'll probably be able to
create fancypants blinkenlight stuff, or want to use it as a monitoring
dashboard for whatever.

If the objective is to teach Erlang for them to learn the principles it
stands for, teaching these principles should come before 'teaching
Erlang' in how the educative environment is set up.

If the objective is 'teach Erlang', then you'll have to make different
assumptions entirely.

Regards,
Fred.



More information about the erlang-questions mailing list