[erlang-questions] Beginners tutorials
Joe Armstrong
erlang@REDACTED
Thu Jun 12 23:08:33 CEST 2014
On Thu, Jun 12, 2014 at 10:29 PM, rambocoder <erlang@REDACTED> wrote:
> Joe,
>
> When I first heard about node, this book provided a gentle introduction by
> developing a web based calculator:
>
> http://www.packtpub.com/toc/node-web-development-table-contents
>
> The book is based on Node 0.4, so none of the examples will work out of
> the box with current node.
>
> The book started with canonical "Hello World" example, then it progressed
> by introducing a package manager and a section on how to make the "Hello
> World" app run as a daemon and have it autostart on a Linux server (similar
> to your http://www.sics.se/~joe/tutorials/web_server/web_server.html). I
> really liked the book's guide on "daemonizing" the basic node server
> (init.d script + forever) because it was such an easy win and within
> minutes I had the example running on my Linode.
> http://www.railstutorial.org/book/beginning a Ruby on Rails tutorial that
> does something similar by not just introducing ROR in the first chapter,
> but also getting me started with rvm, gem, git workflow and the free Heroku
> tier, so by the end of the chapter you have a basic hello world ROR
> application running on Heroku.
>
> After the "Hello World" example, the Node Web Development book shows how
> to render a basic table of contents web page with several calculator URLs.
> Each calculator URL is another example of generating HTML this time with a
> form and some injected values using string replace, no template language
> yet.
>
> Then the book proceeds to show how to do routing of URLs and parsing query
> strings, how to handle POST parameters and return results of calculations
> using just node, no 3rd party libraries.
>
> Once the basic calculator is developed, the author asks: "What complete
> web server features are missing?" and introduces Connect middleware. Logic
> code of the calculator remains intact, but web server startup and routing
> code get's rewritten to use Connect in addition to adding Connect's static
> content handling and Connect's logger. Once Connect based calculator is
> running, he introduces Express web framework and EJS templating engine,
> changing string based HTML generation into an EJS templates, rewriting
> routing into parametrized Express based routing and he adds Error pages.
>
> Before Cowboy, Misultin was all the rage, it provided short and sweet
> examples of simple applications in one Erlang file
> https://code.google.com/p/misultin/wiki/ExamplesPage and before Misultin,
> Mochiweb was the go to web server for one pager examples, such as
> http://www.metabrew.com/article/a-million-user-comet-application-with-mochiweb-part-1
> and in Kevin Smith's screencasts
> http://pragprog.com/screencasts/v-kserl/source_code Episode 6, Adding
> REST using Mochiweb
>
> Cowboy "Hello World" can also be presented as 1 file, check out Elixir's
> Plug Hello World example,
> https://github.com/elixir-lang/plug/blob/master/README.md#hello-world
>
*very* interesting - uses cowboy :-)
Now why can't we do that? - this code is also superficially similar to the
node version
not a bad thing I think.
>
> I think it would be awesome to have an erlang tutorial that would teach
> how to build a web app while doing a compare and contrast to nodejs code.
>
Absolutely - I'd like to learn node *properly* - run to completion in a
callback
is the very "interesting" idea (pre 1957 if the wikipedia is correct).
(Time sharing was invented while people were waiting for jobs to complete
:-)
/Joe
>
> Cheers,
>
> rambocoder
>
>
>
> On Thu, Jun 12, 2014 at 10:54 AM, Joe Armstrong <erlang@REDACTED> wrote:
>
>> Re: Garrett's great talk at EUC2014
>>
>> The point has been made many times before that
>> "There are no easy Erlang getting started guides"
>>
>> So I thought I'd take a look at Node.js.
>>
>> The node js home page (node.js) starts with a simple example
>>
>>
>> <quote>
>> var http = require('http');
>> http.createServer(function (req, res) {
>> res.writeHead(200, {'Content-Type': 'text/plain'});
>> res.end('Hello World\n');
>> }).listen(1337, '127.0.0.1');
>> console.log('Server running at http://127.0.0.1:1337/');
>>
>> To run the server, put the code into a file example.js and execute it
>> with the node program from the command line:
>>
>> % node example.js
>> Server running at http://127.0.0.1:1337/
>> </endquote>
>>
>> It's pretty easy to knock up an almost identical example in Erlang -
>> using any of the well-known web
>> servers in the background, unfortunately this has not been done, or if it
>> has been done
>> it's not easy to find the examples (or if there are examples I can't find
>> them)
>>
>> I was vaguely thinking of making some examples that are more-or-less
>> isomorphic to the
>> node.js examples and then applying small transformation steps to turn
>> then from idiomatic node.js code to idiomatic Erlang code.
>>
>> Although I could find a simple hello world example in node.js I could not
>> find a tutorial that
>> started with a simple example and then built on it in very small steps
>> adding routing, authentication,
>> database access and so on.
>>
>> Does anybody know of some examples of node.js that could be used for this.
>>
>> Cheers
>>
>> /Joe
>>
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140612/caaa1464/attachment.htm>
More information about the erlang-questions
mailing list