[erlang-questions] Beginners tutorials
Joe Armstrong
erlang@REDACTED
Thu Jun 12 19:56:10 CEST 2014
On Thu, Jun 12, 2014 at 5:10 PM, Loïc Hoguin <essen@REDACTED> wrote:
> The simple nodejs example works because it's a nodejs example and not a
> Javascript example. Someone who doesn't know Javascript (pretty much
> equivalent to someone who doesn't know programming at all) won't understand
> it. In particular it has a number of objects in it, and these are not what
> you start learning a language with.
>
>
No but the example is the *first* thing you see on the nodejs.org website
and node.js
is far more popular than Erlang. The first example just says "type this
stuff in" and
"give this command" - it's not *teaching* JS nor Node.js for that matter -
that comes later.
> Most people who look at Erlang necessarily have to learn a number of
> things that people who look at nodejs don't. You can't dumb it down as much
> as nodejs can.
>
I have no intention of dumbing down anything - what I want is a simple
example
that folks can type in and run. They don't need to understand it yet.
I tried the node example and it worked and I still don't understand how it
works.
I'd have to read and understand all the code to do this - but this can come
later
...
>
> The other issue would be that teaching someone to do that in Erlang would
> be counter-productive. Do you really want to teach people to do that and
> then tell them they're doing it wrong?
Yes - I do want this. This is how education works. You start with the
simple story
and then tell people why it is wrong.
Take physics, for example. Start with Newtonian mechanics, then
relativistic, then quantum relativistic, ...
Start by telling people functions in Erlang are pure, then tell them about
ets and get/put
I would also not start with examples that are wrong - it's easy to find
examples that are correct.
> I think the bigger difference here is that nodejs uses a scripting
> language vs Erlang's compiled/run in a VM language.
The examples could easily start with escript. Compiling should not change
semantics
only performance (which again is not the whole truth, but good enough to
get started)
> There's simply more to do and learn before you can start something.
I can start things with a one liner
> You have to compile the file.
Not if it's an escript
> You have to start the VM with the proper paths set.
Like Java and Node
> And so on. Since you have to do all that, why not explain it properly from
> the beginning?
>
Simple examples should work out-of-the-box. And simple examples should be
explained properly.
>
> That's why the Cowboy guide starts with building a release.
I've run cowboy thousands of times (I use it a lot) and have *never* built
a release.
The only time I build a release is in products and this is the last thing I
do, not the first.
> It takes about five minutes to go from nothing to your first release
> running a hello world application.
A release might take five minutes - but you don't need a release to
run hello world.
Example:
Type this in a file called hello.es
#!/usr/bin/env escript
main(_) ->
io:format("Hello world~n").
Then give this commands
$ escript ./hello.es
I timed this it and it took me 17 seconds. If you have correctly installed
Erlang this
should work first time.
How about a cowboy example in an escript that you can type in and run in
less than one minute? - This might get you a large number of new users.
> Of course that's not as fast as nodejs, but we simply can't go that fast
> anyway.
No we should go 10 times faster :-)
> We're not a scripting language.
escript is.
Add:
-mode(compile).
To an escript and it *is* compiled
> Still I think that's a pretty quick way to start.
>
> The chapter is here if you want to take a look and provide feedback:
> http://ninenines.eu/docs/en/cowboy/HEAD/guide/getting_started/
>
>
I think this would be excellent as an "Advanced usage" section.
Your first paragraph says:
<quote>
Setting up a working Erlang application is a little more complex than for
most other languages. The reason is that Erlang is designed to build
systems and not just simple applications.
</quote>
I disagree - Erlang was designed for building systems AND simple
applications.
Also "most other languages" are complex to set up.
(Actually the fast majority of things I write ARE simple, without releases
and all that stuff. Releases are only for production quality run-forever
stuff)
(aside - setting up a working C application - ie one that runs forever
and restarts after errors is *incredibly* difficult - so I'm not sure what
your point of reference is here)
In Garrett's talk at EUC and in Katie Miller's keynote, both speakers
emphasised the
importance of Erlang being not perceived as being complex and difficult to
get started with. This is why I don't like first sentence in the "Getting
started" guide.
If I'd said that in the first line of my Erlang book my editor would have
asked me if
I actually wanted anybody to read the book.
I'd have said
"Getting started with cowboy is really really easy, just put this in a file
... and type this.
..."
Once you've got started you can gradually introduce more complex ideas.
And yes - I do use cowboy - but I don't build it in a release, and it can be
booted from an escript and we can make examples that show this.
Cheers
/Joe
>
> On 06/12/2014 04:54 PM, Joe Armstrong 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
>>
>>
> --
> Loïc Hoguin
> http://ninenines.eu
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140612/91c66c84/attachment.htm>
More information about the erlang-questions
mailing list