[erlang-questions] The gen server simplified (how it works)
Kevin A. Smith
kevin@REDACTED
Wed Apr 20 21:24:00 CEST 2011
Strong agreement with everything stated. When I teach an "Intro To Erlang" class I spend a lot of time (lecture and labs) working on the basics before we tackle gen_server. In fact, one of the last labs before getting to gen_server requires the class to write their own server very similar to Joe's code.
Abstractions aren't very helpful if you don't understand what they're abstracting.
--Kevin
On Apr 20, 2011, at 6:16 AM, Joe Armstrong wrote:
>
>
> On Wed, Apr 20, 2011 at 10:59 AM, Samuel Rivas <samuel.rivas@REDACTED> wrote:
> > Things become problematic when you do not entirely understand the
> > abstraction.
> > Maybe the abstraction is inappropriate for your needs. I have seen many
> > examples
> > of code where the gen_server *is* inappropriate. The acid test is "does the
> > gen_sever code look like spaghetti" if the answer is yes then all you have
> > done
> > is shoe horn the applications into an inappropriate form. In this case
> > you should ditch the gen_server and roll-your own.
>
> Another problem I often see is that newbies tend to regard gen_server
> as something that does magic, and fail to understand how the code runs
> in the server and the clients (since that code lives in the same
> module, usually).
>
> They end up in solutions with parts of the gen server sending messages
> back and forth, putting receives that spoil the abstraction
> intercepting messages that gen_server code should be handling,
> throwing exits in server code and attempting to catch them in the
> client code, blocking servers with heavyweight operations, ...
>
> I really consider advising against using gen_server (or any other
> abstraction) until one is able to write a client-server and a
> supervisor tree without them so that you can understand what's
> happening under the hood of gen_server (which, as you say, it's not
> rocket science).
>
>
> Absolutely.
>
> I think the problem stems from the use of IDEs - in eclipse/Xcode etc you click on
> a "new project" button and the system automatically generates a load of crap files
> full of incomprehensible undocumented nonsense. This leads to a mentality
> of "using stuff without understanding it" - All I ever use is emacs, make and a shell.
> Usually I put all the files in one directory. I want to understand *everything*
>
> As IDEs get more and more complex and help you more and more
> it gets harder and harder to understand what's really going on.
>
> Graphics programming used to be easy - anybody remember Borlands turbo graphics?
> - but now it's far more difficult since you have to fight with all the tools and
> frameworks that get in the way and make life difficult.
>
> /joe
>
>
>
> Cheers
> --
> Samuel
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list