little challenge for sven and us

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
47 messages Options
123
Reply | Threaded
Open this post in threaded view
|

little challenge for sven and us

Stéphane Ducasse
Hi guys

apparently people get excited by nodeJS and I would like to know the equivalence of

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:

% node example.js
Server running at http://127.0.0.1:1337/


Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:

var net = require('net');
var server = net.createServer(function (socket) {
  socket.write("Echo server\r\n");
  socket.pipe(socket);
});

server.listen(1337, "127.0.0.1");


we should communicate better :)

Stef
Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

NorbertHartl

Am 30.06.2011 um 17:07 schrieb Stéphane Ducasse:

> Hi guys
>
> apparently people get excited by nodeJS and I would like to know the equivalence of
>
What does it mean?

Norbert

> 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:
>
> % node example.js
> Server running at http://127.0.0.1:1337/
>
>
> Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
>
> var net = require('net');
> var server = net.createServer(function (socket) {
>  socket.write("Echo server\r\n");
>  socket.pipe(socket);
> });
>
> server.listen(1337, "127.0.0.1");
>
>
> we should communicate better :)
>
> Stef


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Stéphane Ducasse
>> Hi guys
>>
>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>
> What does it mean?

in Pharo.. how do you have the same:

>> 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:
>>
>> % node example.js
>> Server running at http://127.0.0.1:1337/
>>
>>
>> Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
>>
>> var net = require('net');
>> var server = net.createServer(function (socket) {
>> socket.write("Echo server\r\n");
>> socket.pipe(socket);
>> });
>>
>> server.listen(1337, "127.0.0.1");
>>
>>
>> we should communicate better :)
>>
>> Stef
>
>


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Sven Van Caekenberghe
In reply to this post by Stéphane Ducasse
Stéphane,

That's not really a challenge ;-)

The second example is too simple to be useful, but this would be the Zn equivalent:


(ZnServer defaultOn: 1337)
        logToTranscript;
        delegate: (ZnValueDelegate with: [ :request |
                ZnResponse ok: (ZnEntity text: 'Hello World!') ]);
        start.
       
ZnClient get: '<a href="http://localhost:1337'">http://localhost:1337'.

(ZnServer defaultOn: 1337)
        logToTranscript;
        delegate: (ZnValueDelegate with: [ :request |
                ZnResponse ok: (ZnEntity with: request contents) ]);
        start.

ZnClient post: '<a href="http://localhost:1337'">http://localhost:1337' data: (ZnEntity text: 'Echo').

ZnServer stopDefault.


Smalltalk is a beautiful language, isn't it ?

Sven

PS: the delegate object has to respond to #handleRequest:. In earlier versions, it was a block, now ZnValueDelegate translates #handleRequest: to #value:. I thought that was clearer. For publicity reasons, maybe I could add a #delegateBlock: convencience accessor.


On 30 Jun 2011, at 17:07, Stéphane Ducasse wrote:

> Hi guys
>
> apparently people get excited by nodeJS and I would like to know the equivalence of
>
> 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:
>
> % node example.js
> Server running at http://127.0.0.1:1337/
>
>
> Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
>
> var net = require('net');
> var server = net.createServer(function (socket) {
>  socket.write("Echo server\r\n");
>  socket.pipe(socket);
> });
>
> server.listen(1337, "127.0.0.1");
>
>
> we should communicate better :)
>
> Stef


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

NorbertHartl
In reply to this post by Stéphane Ducasse

Am 30.06.2011 um 17:23 schrieb Stéphane Ducasse:

>>> Hi guys
>>>
>>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>>
>> What does it mean?
>
> in Pharo.. how do you have the same:

It depends what is in your head when you wrote this. The code snippet doesn't tell that much. Registering a Block for execution on request is probably not what makes you excited about. What is exciting about it is that javascript is written in a strictly asynchronous manner (event driven) and that matches perfectly the implementation with asynchronous I/O. Suddenly you can write programs they way you ever wanted it. And lucky for us smalltalk itself is event driven so it can go there easily, too. Well, easily would mean to have support for asynchronous I/O in the vm (file operations) and in the socket plugin at least.

Is that what you asked?

Norbert

>
>>> 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:
>>>
>>> % node example.js
>>> Server running at http://127.0.0.1:1337/
>>>
>>>
>>> Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
>>>
>>> var net = require('net');
>>> var server = net.createServer(function (socket) {
>>> socket.write("Echo server\r\n");
>>> socket.pipe(socket);
>>> });
>>>
>>> server.listen(1337, "127.0.0.1");
>>>
>>>
>>> we should communicate better :)
>>>
>>> Stef
>>
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Janko Mivšek
S, Norbert Hartl piše:

> Am 30.06.2011 um 17:23 schrieb Stéphane Ducasse:

>>>> apparently people get excited by nodeJS and I would like to know the equivalence of

>>> What does it mean?

>> in Pharo.. how do you have the same:

> It depends what is in your head when you wrote this. The code snippet doesn't tell that much. Registering a Block for execution on request is probably not what makes you excited about. What is exciting about it is that javascript is written in a strictly asynchronous manner (event driven) and that matches perfectly the implementation with asynchronous I/O. Suddenly you can write programs they way you ever wanted it. And lucky for us smalltalk itself is event driven so it can go there easily, too. Well, easily would mean to have support for asynchronous I/O in the vm (file operations) and in the socket plugin at least.

Because I'm just working on asynchronous no-blocking node.js like
control flow in Aida, I can say that this is really natural to Smalltalk
with its closures, much more than so called callbacks in JavaScript. In
Smalltalk it is more readable and you hardly notice the difference to
the normal Smalltalk code, while in JavaScript those callbacks are a bit
hard to grasp and understand. From non seasoned programmer perspective,
that is.

Best regards
Janko

--
Janko Mivšek
Aida/Web
Smalltalk Web Application Server
http://www.aidaweb.si

Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Olivier Auverlot
In reply to this post by Stéphane Ducasse
Hi Stef,

I don't think that the buzz around NodeJS comes from these samples of code. Yes, it's very easy to starting a project with NodeJS but the interest from NodeJS is that this server extends the usages of Javascript wich becomes an language useable on many platform, many OS for many usages. With Javascript, programmers can write client code in browsers, widgets for desktop computers, shell scripts with Rhino, mobile applications for Android or IOS, ... and now, programmers can write server code for web applications and web services.

My two cents

Olivier ;-)
www.auverlot.fr
Hi guys

apparently people get excited by nodeJS and I would like to know the equivalence of

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:

% node example.js
Server running at http://127.0.0.1:1337/


Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:

var net = require('net');
var server = net.createServer(function (socket) {
  socket.write("Echo server\r\n");
  socket.pipe(socket);
});

server.listen(1337, "127.0.0.1");


we should communicate better :)

Stef

Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

NorbertHartl
In reply to this post by Janko Mivšek

Am 30.06.2011 um 17:53 schrieb Janko Mivšek:

> S, Norbert Hartl piše:
>
>> Am 30.06.2011 um 17:23 schrieb Stéphane Ducasse:
>
>>>>> apparently people get excited by nodeJS and I would like to know the equivalence of
>
>>>> What does it mean?
>
>>> in Pharo.. how do you have the same:
>
>> It depends what is in your head when you wrote this. The code snippet doesn't tell that much. Registering a Block for execution on request is probably not what makes you excited about. What is exciting about it is that javascript is written in a strictly asynchronous manner (event driven) and that matches perfectly the implementation with asynchronous I/O. Suddenly you can write programs they way you ever wanted it. And lucky for us smalltalk itself is event driven so it can go there easily, too. Well, easily would mean to have support for asynchronous I/O in the vm (file operations) and in the socket plugin at least.
>
> Because I'm just working on asynchronous no-blocking node.js like
> control flow in Aida, I can say that this is really natural to Smalltalk
> with its closures, much more than so called callbacks in JavaScript. In
> Smalltalk it is more readable and you hardly notice the difference to
> the normal Smalltalk code, while in JavaScript those callbacks are a bit
> hard to grasp and understand. From non seasoned programmer perspective,
> that is.
>
Can you elaborate on this? I agree that one of the biggest flaws in javascript is that you have to write function() {} to use a closure which prevents its usage in a lot of cases, e.g. in filter functions etc. It is just ugly and nobody likes it. The second point is that you need to preserve this in javascript manually if you wish to use it in closures.
Apart from that I can see a single difference between the two. Callbacks are natural to javascript because most usage pattern use it. Closures are natural to smalltalk because it just needs [ ] and it is well used throughout the class library.

Norbert



Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Sven Van Caekenberghe
In reply to this post by Janko Mivšek

On 30 Jun 2011, at 17:53, Janko Mivšek wrote:

> Because I'm just working on asynchronous no-blocking node.js like
> control flow in Aida, I can say that this is really natural to Smalltalk
> with its closures, much more than so called callbacks in JavaScript. In
> Smalltalk it is more readable and you hardly notice the difference to
> the normal Smalltalk code, while in JavaScript those callbacks are a bit
> hard to grasp and understand. From non seasoned programmer perspective,
> that is.

Janko, that sounds promising, I would really love to learn more about your efforts.

How do you do async IO without the select() system call ? As far as I know, that is not available as a VM primitive.

Sven


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Sven Van Caekenberghe
In reply to this post by Olivier Auverlot

On 30 Jun 2011, at 18:01, Olivier Auverlot wrote:

> I don't think that the buzz around NodeJS comes from these samples of code. Yes, it's very easy to starting a project with NodeJS but the interest from NodeJS is that this server extends the usages of Javascript wich becomes an language useable on many platform, many OS for many usages. With Javascript, programmers can write client code in browsers, widgets for desktop computers, shell scripts with Rhino, mobile applications for Android or IOS, ... and now, programmers can write server code for web applications and web services.

Both what Olivier writes above and what Norbert writes (asynch support) are correct.

Still, all this buzz around JS, Ruby, Python, Java, C#, whatever, is just that, buzz.

Smalltalk has been an extremely dynamic binary cross platform language for decades, absorbing all kinds of new stuff.

Yes, we can and should learn from other developments, but we should not be blinded by the hype.

All these other platforms have their strengths, but many serious faults as well.

So far, I haven't seen much that can't be done in Smalltalk in some way. And it is so much more easy, productive, nicer, pleasant, fun to do it in Smalltalk.

Sven


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Janko Mivšek
In reply to this post by NorbertHartl


S, Norbert Hartl piše:

>
> Am 30.06.2011 um 17:53 schrieb Janko Mivšek:
>
>> S, Norbert Hartl piše:
>>
>>> Am 30.06.2011 um 17:23 schrieb Stéphane Ducasse:
>>
>>>>>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>
>>>>> What does it mean?
>>
>>>> in Pharo.. how do you have the same:
>>
>>> It depends what is in your head when you wrote this. The code snippet doesn't tell that much. Registering a Block for execution on request is probably not what makes you excited about. What is exciting about it is that javascript is written in a strictly asynchronous manner (event driven) and that matches perfectly the implementation with asynchronous I/O. Suddenly you can write programs they way you ever wanted it. And lucky for us smalltalk itself is event driven so it can go there easily, too. Well, easily would mean to have support for asynchronous I/O in the vm (file operations) and in the socket plugin at least.
>>
>> Because I'm just working on asynchronous no-blocking node.js like
>> control flow in Aida, I can say that this is really natural to Smalltalk
>> with its closures, much more than so called callbacks in JavaScript. In
>> Smalltalk it is more readable and you hardly notice the difference to
>> the normal Smalltalk code, while in JavaScript those callbacks are a bit
>> hard to grasp and understand. From non seasoned programmer perspective,
>> that is.
>>
> Can you elaborate on this? I agree that one of the biggest flaws in javascript is that you have to write function() {} to use a closure which prevents its usage in a lot of cases, e.g. in filter functions etc. It is just ugly and nobody likes it. The second point is that you need to preserve this in javascript manually if you wish to use it in closures.
> Apart from that I can see a single difference between the two. Callbacks are natural to javascript because most usage pattern use it. Closures are natural to smalltalk because it just needs [ ] and it is well used throughout the class library.

Let me show an example by Ryan Dahl, author of node.js. First in
JavaScript then how it will look in Smalltalk.

Synchronous blocking database call:

        var result = db.query("select..");
        // wait
        // use result

Asynchronous non-blocking database call:

        db.query("select..", function (result) {// use result });
        // continue

In first case program execution is blocked until database returns
result. In second case we register a callback function to deal with the
result. This function will be called later when result arrives, while we
don't wait but continue with execution.

If you'll do in Smalltalk a blocking call:

        result := db query: 'select..'.
        result useIt
       
A non-blocking call can look something like:

        db query: 'select..' thenDo: [:result | result useIt ]

As you see with our closures we can much more naturally and
understandably write such calls.

Best regards
Janko



--
Janko Mivšek
Svetovalec za informatiko
Eranova d.o.o.
Ljubljana, Slovenija
www.eranova.si
tel:  01 514 22 55
faks: 01 514 22 56
gsm: 031 674 565

Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Igor Stasenko
2011/6/30 Janko Mivšek <[hidden email]>:

>
>
> S, Norbert Hartl piše:
>>
>> Am 30.06.2011 um 17:53 schrieb Janko Mivšek:
>>
>>> S, Norbert Hartl piše:
>>>
>>>> Am 30.06.2011 um 17:23 schrieb Stéphane Ducasse:
>>>
>>>>>>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>>
>>>>>> What does it mean?
>>>
>>>>> in Pharo.. how do you have the same:
>>>
>>>> It depends what is in your head when you wrote this. The code snippet doesn't tell that much. Registering a Block for execution on request is probably not what makes you excited about. What is exciting about it is that javascript is written in a strictly asynchronous manner (event driven) and that matches perfectly the implementation with asynchronous I/O. Suddenly you can write programs they way you ever wanted it. And lucky for us smalltalk itself is event driven so it can go there easily, too. Well, easily would mean to have support for asynchronous I/O in the vm (file operations) and in the socket plugin at least.
>>>
>>> Because I'm just working on asynchronous no-blocking node.js like
>>> control flow in Aida, I can say that this is really natural to Smalltalk
>>> with its closures, much more than so called callbacks in JavaScript. In
>>> Smalltalk it is more readable and you hardly notice the difference to
>>> the normal Smalltalk code, while in JavaScript those callbacks are a bit
>>> hard to grasp and understand. From non seasoned programmer perspective,
>>> that is.
>>>
>> Can you elaborate on this? I agree that one of the biggest flaws in javascript is that you have to write function() {} to use a closure which prevents its usage in a lot of cases, e.g. in filter functions etc. It is just ugly and nobody likes it. The second point is that you need to preserve this in javascript manually if you wish to use it in closures.
>> Apart from that I can see a single difference between the two. Callbacks are natural to javascript because most usage pattern use it. Closures are natural to smalltalk because it just needs [ ] and it is well used throughout the class library.
>
> Let me show an example by Ryan Dahl, author of node.js. First in
> JavaScript then how it will look in Smalltalk.
>
> Synchronous blocking database call:
>
>        var result = db.query("select..");
>        // wait
>        // use result
>
> Asynchronous non-blocking database call:
>
>        db.query("select..", function (result) {// use result });
>        // continue
>
> In first case program execution is blocked until database returns
> result. In second case we register a callback function to deal with the
> result. This function will be called later when result arrives, while we
> don't wait but continue with execution.
>
> If you'll do in Smalltalk a blocking call:
>
>        result := db query: 'select..'.
>        result useIt
>
> A non-blocking call can look something like:
>
>        db query: 'select..' thenDo: [:result | result useIt ]
>
> As you see with our closures we can much more naturally and
> understandably write such calls.
>

Indeed. Actually the recent JS popular libraries coding style reminds
me more and more smalltalk.
Looks like they are inventing new wheel, going long road from creepy C
syntax and C programming style
to smalltalk.

> Best regards
> Janko
>

--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Janko Mivšek
In reply to this post by Sven Van Caekenberghe


S, Sven Van Caekenberghe piše:

>
> On 30 Jun 2011, at 17:53, Janko Mivšek wrote:
>
>> Because I'm just working on asynchronous no-blocking node.js like
>> control flow in Aida, I can say that this is really natural to Smalltalk
>> with its closures, much more than so called callbacks in JavaScript. In
>> Smalltalk it is more readable and you hardly notice the difference to
>> the normal Smalltalk code, while in JavaScript those callbacks are a bit
>> hard to grasp and understand. From non seasoned programmer perspective,
>> that is.
>
> Janko, that sounds promising, I would really love to learn more about your efforts.
>
> How do you do async IO without the select() system call ? As far as I know, that is not available as a VM primitive.
Currently I'm introducing those techniques in Aida not for I/O but for
tree-like control flow. One snippet from the forthcoming ToDo list
example to confirm the delete of ToDo task (see attached screenshot):

  link := e addNilLinkText: 'Delete this task'.
  link onClickPopup:
    (WebDialog newConfirm
        text: 'Do you really want to delete that task?';
        ifTrue:
           [self observee deleteTask: aToDoTask.
            aListElement update]).

This is typical tree-like control flow scenario. When clicking on the
link, a popup with Yes/No confirmation appear. If Yes is clicked, true
is returned and ifTrue: block executed.

Whole point is that this is a non-blocking code, in contrast to
continuation based approach like in Seaside, where similar code would
block and wait until dialog component returns answer.

Here need to be mentioned that Iliad also use non-blocking tree-like
control flow.

Best regards
Janko


--
Janko Mivšek
Aida/Web
Smalltalk Web Application Server
http://www.aidaweb.si

todo-delete.png (23K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Stéphane Ducasse
In reply to this post by Sven Van Caekenberghe
> That's not really a challenge ;-)

Excellent I like to hear that :)

Now we should add it on the web somewhere because this is the second lesson.
We are not really good at communication.

Stef

>
> The second example is too simple to be useful, but this would be the Zn equivalent:
>
>
> (ZnServer defaultOn: 1337)
> logToTranscript;
> delegate: (ZnValueDelegate with: [ :request |
> ZnResponse ok: (ZnEntity text: 'Hello World!') ]);
> start.
>
> ZnClient get: '<a href="http://localhost:1337'">http://localhost:1337'.
>
> (ZnServer defaultOn: 1337)
> logToTranscript;
> delegate: (ZnValueDelegate with: [ :request |
> ZnResponse ok: (ZnEntity with: request contents) ]);
> start.
>
> ZnClient post: '<a href="http://localhost:1337'">http://localhost:1337' data: (ZnEntity text: 'Echo').
>
> ZnServer stopDefault.
>
>
> Smalltalk is a beautiful language, isn't it ?
>
> Sven
>
> PS: the delegate object has to respond to #handleRequest:. In earlier versions, it was a block, now ZnValueDelegate translates #handleRequest: to #value:. I thought that was clearer. For publicity reasons, maybe I could add a #delegateBlock: convencience accessor.
>
>
> On 30 Jun 2011, at 17:07, Stéphane Ducasse wrote:
>
>> Hi guys
>>
>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>
>> 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:
>>
>> % node example.js
>> Server running at http://127.0.0.1:1337/
>>
>>
>> Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
>>
>> var net = require('net');
>> var server = net.createServer(function (socket) {
>> socket.write("Echo server\r\n");
>> socket.pipe(socket);
>> });
>>
>> server.listen(1337, "127.0.0.1");
>>
>>
>> we should communicate better :)
>>
>> Stef
>
>


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

NorbertHartl
In reply to this post by Janko Mivšek

Am 30.06.2011 um 21:03 schrieb Janko Mivšek:

>
>
> S, Norbert Hartl piše:
>>
>> Am 30.06.2011 um 17:53 schrieb Janko Mivšek:
>>
>>> S, Norbert Hartl piše:
>>>
>>>> Am 30.06.2011 um 17:23 schrieb Stéphane Ducasse:
>>>
>>>>>>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>>
>>>>>> What does it mean?
>>>
>>>>> in Pharo.. how do you have the same:
>>>
>>>> It depends what is in your head when you wrote this. The code snippet doesn't tell that much. Registering a Block for execution on request is probably not what makes you excited about. What is exciting about it is that javascript is written in a strictly asynchronous manner (event driven) and that matches perfectly the implementation with asynchronous I/O. Suddenly you can write programs they way you ever wanted it. And lucky for us smalltalk itself is event driven so it can go there easily, too. Well, easily would mean to have support for asynchronous I/O in the vm (file operations) and in the socket plugin at least.
>>>
>>> Because I'm just working on asynchronous no-blocking node.js like
>>> control flow in Aida, I can say that this is really natural to Smalltalk
>>> with its closures, much more than so called callbacks in JavaScript. In
>>> Smalltalk it is more readable and you hardly notice the difference to
>>> the normal Smalltalk code, while in JavaScript those callbacks are a bit
>>> hard to grasp and understand. From non seasoned programmer perspective,
>>> that is.
>>>
>> Can you elaborate on this? I agree that one of the biggest flaws in javascript is that you have to write function() {} to use a closure which prevents its usage in a lot of cases, e.g. in filter functions etc. It is just ugly and nobody likes it. The second point is that you need to preserve this in javascript manually if you wish to use it in closures.
>> Apart from that I can see a single difference between the two. Callbacks are natural to javascript because most usage pattern use it. Closures are natural to smalltalk because it just needs [ ] and it is well used throughout the class library.
>
> Let me show an example by Ryan Dahl, author of node.js. First in
> JavaScript then how it will look in Smalltalk.
>
> Synchronous blocking database call:
>
> var result = db.query("select..");
> // wait
> // use result
>
> Asynchronous non-blocking database call:
>
> db.query("select..", function (result) {// use result });
> // continue
>
> In first case program execution is blocked until database returns
> result. In second case we register a callback function to deal with the
> result. This function will be called later when result arrives, while we
> don't wait but continue with execution.
>
> If you'll do in Smalltalk a blocking call:
>
> result := db query: 'select..'.
> result useIt
>
> A non-blocking call can look something like:
>
> db query: 'select..' thenDo: [:result | result useIt ]
>
> As you see with our closures we can much more naturally and
> understandably write such calls.
>
Ok, I don't think we need to argue that smalltalks syntax has great potential. But to be honest

> db query: 'select..' thenDo: [:result | result useIt ]

doesn't feel natural to me from a smalltalk point of view. More natural appears

database select: [:each| each....]

So not having to use javascript syntax might be an advantage. It would be great if you would omit the SQL as well ;)

If we talk about asynchronous programming I'm more concerned about composability and control of asynchronous operations then to have a nice syntax for a really simple case.

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Stéphane Ducasse
In reply to this post by Olivier Auverlot
Yes I know.
Now still we are bad at communication and at marketing what we have.
Our community as a whole lacked a vision for so long ....
We are trying but it is slow

Stef

On Jun 30, 2011, at 6:01 PM, Olivier Auverlot wrote:

> Hi Stef,
>
> I don't think that the buzz around NodeJS comes from these samples of code. Yes, it's very easy to starting a project with NodeJS but the interest from NodeJS is that this server extends the usages of Javascript wich becomes an language useable on many platform, many OS for many usages. With Javascript, programmers can write client code in browsers, widgets for desktop computers, shell scripts with Rhino, mobile applications for Android or IOS, ... and now, programmers can write server code for web applications and web services.
>
> My two cents
>
> Olivier ;-)
> www.auverlot.fr
>> Hi guys
>>
>> apparently people get excited by nodeJS and I would like to know the equivalence of
>>
>> 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:
>>
>> % node example.js
>> Server running at
>> http://127.0.0.1:1337/
>>
>>
>>
>> Here is an example of a simple TCP server which listens on port 1337 and echoes whatever you send it:
>>
>> var net = require('net');
>> var server = net.createServer(function (socket) {
>>   socket.write("Echo server\r\n");
>>   socket.pipe(socket);
>> });
>>
>> server.listen(1337, "127.0.0.1");
>>
>>
>> we should communicate better :)
>>
>> Stef
>>
>
>


Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Stéphane Ducasse
In reply to this post by Igor Stasenko
> Indeed. Actually the recent JS popular libraries coding style reminds
> me more and more smalltalk.
> Looks like they are inventing new wheel, going long road from creepy C
> syntax and C programming style
> to smalltalk.


The problem igor is that they will get there and fast because the world is faster.
Microsoft is creating a new lab at Zurich for example. And our nice little community
did not move since at least one decade.
Sometimes I'm immensely sad to see for example that while julian is working for cincom
he does not lead an effort to bring Seaside to the next level. Company vision are puzzling me.

Stef
Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Igor Stasenko
On 1 July 2011 07:32, Stéphane Ducasse <[hidden email]> wrote:

>> Indeed. Actually the recent JS popular libraries coding style reminds
>> me more and more smalltalk.
>> Looks like they are inventing new wheel, going long road from creepy C
>> syntax and C programming style
>> to smalltalk.
>
>
> The problem igor is that they will get there and fast because the world is faster.
> Microsoft is creating a new lab at Zurich for example. And our nice little community
> did not move since at least one decade.
> Sometimes I'm immensely sad to see for example that while julian is working for cincom
> he does not lead an effort to bring Seaside to the next level. Company vision are puzzling me.
>

To get to the next level, first you have to define what is next level.
For me , i don't see what is the next level for web application
framework like seaside. Do you?

> Stef
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Julian Fitzell-2
In reply to this post by Janko Mivšek
2011/6/30 Janko Mivšek <[hidden email]>
Whole point is that this is a non-blocking code, in contrast to
continuation based approach like in Seaside, where similar code would
block and wait until dialog component returns answer.

Janko, what are you talking about? If it's not blocking, it's just a callback. Of course Seaside can do the same thing: you just use #show:onAnswer:.

Julian

Reply | Threaded
Open this post in threaded view
|

Re: little challenge for sven and us

Stéphane Ducasse
In reply to this post by Igor Stasenko

On Jul 1, 2011, at 10:56 AM, Igor Stasenko wrote:

> On 1 July 2011 07:32, Stéphane Ducasse <[hidden email]> wrote:
>>> Indeed. Actually the recent JS popular libraries coding style reminds
>>> me more and more smalltalk.
>>> Looks like they are inventing new wheel, going long road from creepy C
>>> syntax and C programming style
>>> to smalltalk.
>>
>>
>> The problem igor is that they will get there and fast because the world is faster.
>> Microsoft is creating a new lab at Zurich for example. And our nice little community
>> did not move since at least one decade.
>> Sometimes I'm immensely sad to see for example that while julian is working for cincom
>> he does not lead an effort to bring Seaside to the next level. Company vision are puzzling me.
>>
>
> To get to the next level, first you have to define what is next level.
> For me , i don't see what is the next level for web application
> framework like seaside. Do you?


No but I'm not in the field.

Stef
123