[erlang-questions] Re: What about making sense?

Joe Armstrong erlang@REDACTED
Mon Feb 22 22:46:49 CET 2010


On Mon, Feb 22, 2010 at 4:05 PM, David Mercer <dmercer@REDACTED> wrote:
> On Saturday, February 20, 2010, Joe Armstrong wrote:
>
>> When I write *any* process I always start with something like:
>>
>> loop(...) ->
>>     receive
>>          Any -> io:format("got:~p~n",[Any]),
>>          loop(...)
>>    end.
>
> Out of curiosity, why do you start with that and not:
>
>        -behaviour(gen_server).
>
>        init(_) -> {ok, []}.
>
>        handle_info(Info, State) ->
>                io:format("got:~p~n",[Info]),
>                {noreply, State}.
>
> Obviously, the semantics are different and all, but I'd have thought if I
> were creating a process, I may as well make it a gen-server process so I
> don't have to retrofit it into that framework later.

For most programs there is no later.

Most of what I write is never used. In solving problems
I try to identify "the most difficult part of the problem" and then solve it.

I usually start by writing pure erlang code, with only calls to pure
libraries (lists, sets etc)
with no complex callback structure - then I see what patterns emerge,
and then abstract
*if necessary* introducing abstractions as I go along. Starting with
gen_server pre-supposes
that I want all the goodies offered by gen_server (code_change etc.
calls and casts). Usually
I only need global name registration and a simple RPC.

I'm also trying to find new and useful abstractions, the process for
doing this seems to be
write raw erlang code - abstract and then generalise. So I usually
start with raw Erlang
mess around a bit and see what patterns emerge. When I start a new
problem I have no idea
what structures will emerge, so I absorb myself in the problem, and
then let my subconscious get to work. Then I just wait and see what
comes out when I start typing.

Often really beautiful structures emerge from just typing in some
solution to a problem (any solution) and then re-arranging the code
until it looks pretty.

If the code were every to make it into production code I'd then
re-write it and fit it
into more standard forms or invent custom abstractions if the standard
forms were inappropriate.

/Joe



>
> Cheers,
>
> David
>
>


More information about the erlang-questions mailing list