Defensive programming
Pupeno
pupeno@REDACTED
Wed Mar 29 00:36:39 CEST 2006
Hello,
I am used to defensive programming and it's hard for me to program otherwise.
Today I've found this piece of code I wrote some months ago:
acceptor(tcp, Module, LSocket) ->
case gen_tcp:accept(LSocket) of
{ok, Socket} ->
case Module:start() of
{ok, Pid} ->
ok = gen_tcp:controlling_process(Socket, Pid),
gen_server:cast(Pid, {connected, Socket}),
acceptor(tcp, Module, LSocket);
{error, Error} ->
{stop, {Module, LSocket, Error}}
end;
{error, Reason} ->
{stop, {Module, LSocket, Reason}}
end;
is that too defensive ? should I write it this way
acceptor(tcp, Module, LSocket) ->
{ok, Socket} = case gen_tcp:accept(LSocket),
{ok, Pid} = Module:start()
ok = gen_tcp:controlling_process(Socket, Pid),
gen_server:cast(Pid, {connected, Socket}),
acceptor(tcp, Module, LSocket);
?
Thanks.
--
Pupeno <pupeno@REDACTED> (http://pupeno.com)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060329/5d1c97df/attachment.bin>
More information about the erlang-questions
mailing list