Live data from Hacker News

How I want to write Node: Stream all the things

caolanmcmahon.com

101–110 of 118 posts

Re: How I want to write Node: Stream all the things

#101
post #97

Earlier quoted context omitted.

Can you qualify "Haskell doesn't have anything close to the plug-and-playability of npm modules" because I don't quite get what you mean? Maybe it is because I can't think of anything plug-and-play in node that isn't plug-and-play in Haskell.

Sure. I want a git server with push notifications. Two lines with the pushover module in node. I would be pleasantly surprised if this existed at all in the Haskell community. Even more so with two lines of my own code.

I think that has much more to do with the size of Node than the methods of streaming being used. Such things are easily accomplish able atop libraries in Haskell, but pushover hasn't been written as a library because the ecosystem isn't at the point where it specializes so far yet.

But the API provided is trivially replicated, and, yes, easily built atop pipes.

Re: How I want to write Node: Stream all the things

#102
post #45
post #37

Earlier quoted context omitted.

async: async.waterfall([ fn1, fn2, fn3 ], function(err, result) { }); Q: resultP = [ fn1, fn2, fn3 ].reduce(Q.when, void 0); resultP .then(function(result) {}); .catch(function(err) {}); If you chain thens in Q, you are not doing it right (imho).

Q docs show both. Either way: .waterfall() is still simpler.

Waterfall is an easier top-level API that hides a clean low-level API. When it's all you need and it works well then you won't want to switch. When it breaks or you want it to behave better then a nice low-level API is beneficial.

Re: How I want to write Node: Stream all the things

#103
post #84

Earlier quoted context omitted.

When did sane and static typing become synonymous?

sane has nothing to do with static typing. Python is a language which is dynamic and has a sane semantics. e.g. in JS {} + {} is NaN and many other examples.

Right, sane semantics: http://cs.brown.edu/research/plt/dl/lambda-py/lambda-py.pdf

Saner perhaps, but still ungodly complex with weird edge cases.

Re: How I want to write Node: Stream all the things

#104
post #98
post #88

Earlier quoted context omitted.

There's a language where `{} + {}` does something useful? Or is the complaint that it should `TypeError`?

If it does anything at all, it certainly shouldn't generate NaN

Why not? If (+) is numeric addition and coercion is free then {} is NaN and so is {} and so is NaN + (anything) and so is (anything) + NaN.

Which is not to say that it's a good choice, but instead to say that the badness stems from overloading (+) too much and having free coercion.

Re: How I want to write Node: Stream all the things

#105
post #31

If you're doing Node.js, Caolan's async library is pretty much part of the standard toolkit. I know Caolan's been thinking about this and reworking it for a while, so I'll be interested to see whether it manages to see significant takeup.

From Great British Node Conf, maybe two months ago: a speaker talking about promises asked what people use for flow control: - promises: about 20% of the room. - async: about 80% of the room For me async.waterfall([list of functions]) is little nicer than 10 chained .thens(). And people advocating promises still keep saying it keeps things flat. No it doesn't, we're already flat because we're all using async. Stop pr…

  Boxon.cast( fs.readfile, 'myfile' )
  .then( function( content ){ console.log( content ) })
  .catch( function( err ){ console.log( "Error", err ) });
Boxon is promise implementation agnostic, works with Q, bluebird, etc... See https://github.com/JeanHuguesRobert/l8/wiki/AboutBoxons

Re: How I want to write Node: Stream all the things

#106
post #78

I really like Node, but I want a language with sane semantics. What's the best option apart from JS and CoffeScript. TypeScript is awesome, but I'm afraid that there will no good community, because of MS stigma.

Google Dart and TypeScript are pretty good alternatives to JS in some cases and Dart has the notion of streams.

https://www.dartlang.org/docs/tutorials/streams/

Re: How I want to write Node: Stream all the things

#107
post #43

Earlier quoted context omitted.

- Why BlueBird? What's wrong with Q? - Isn't data a scope down? - https://github.com/petkaantonov/bluebird/blob/master/API.md is API based, not task based. async is API based too, but the API has names like 'waterfall' and 'parallel'. I can click them because I know what they mean. Promises just makes me feel like I'm reading about and endless series of abstractions.

Native Promises already landed Chrome 32 and Q still does not support native promises. Bluebird delegate to native if supported. Promises can be used as flow control, but more importantly, it's an object that encapsulates asynchronous mechanics. I like to see how async can launch an asynchronous operation, then allow listeners to be attached later to capture the result. Now, you may say that if you want to attach lis…

Using async, if you want something to allow listeners to be attached later:

  var outcome = Boxon();
  fs.readFile( "test.txt", outcome );
  // Attach listener later:
  outcome( function( err, content ){ ... } );
See https://github.com/JeanHuguesRobert/l8/wiki/AboutBoxons

Boxon objects are light compared to promises, but they interop well. Best of both worlds!

Re: How I want to write Node: Stream all the things

#108

It looks like this whole notion of 'stream' is just a syntactic sugar for javascript guys who lost themselves in a bunch of nested stupid callbacks, which is worse than lisp parens. Instead of nesting whole callbacks, create a stream in the middle; execute first half of callback chain and dump the result into the stream so that next half of callback chain can be executed later. Why is this so an enlightenment for nod…

yup! node does streams horribly wrong

I am considering the idea of spending some time studying node streams. Your remark worries me. Is there some sources I can consult about node stream potential weaknesses? Thanks.

Re: How I want to write Node: Stream all the things

#109
post #84

Earlier quoted context omitted.

When did sane and static typing become synonymous?

sane has nothing to do with static typing. Python is a language which is dynamic and has a sane semantics. e.g. in JS {} + {} is NaN and many other examples.

How would using TypeScript fix that?
Post reply on HN