Re:Plug and Play All Your Observable Streams With Cycle.js
by noelwelsh on Friday November 06, 2015 @08:28AM
(#10519313)
Holy hyperbole, Batman! That article took a long time to get to the point, and I'm a touch hesitant to use the same breathless tone as the author. As I understand it, the model is the same as Elm. Separating specifying the computation (in this case, defining the event processing graph) from running the computation is an old trick in FP circles[1]. It's great to see JS libraries moving forward, but it would sure be an easier read if the author dropped the embellishment.
Re:Plug and Play All Your Observable Streams With Cycle.js
by bryanrasmussen on Friday November 06, 2015 @06:31AM
(#10518936)
Cycle.js http://cycle.js.org/ says that it allows "thisless JavaScript: The use of functions and RxJS Observables allow for a JavaScript programming style without the this keyword. Cycle.js encourages you to create apps with functional practices. Without this, you can write more reusable code and define logic without tightly coupling it to data. See it for yourself, this cannot be found in Cycle.js TodoMVC."
this, uh, doesn't seem to match my normal understanding of JS. Normally the method to reuse code is to change what 'this' refers to, but the statement above implies the existence of 'this' is a failure of JavaScript's design. I would like some elaboration.
If you use an OOP style (with classes and inheritance), then you end up needing to use the 'this' keyword. If you use a functional style, you don't.
Is the functional style better? Does it let you write more reusable code, and avoid tightly coupling it to date? Eh...maybe. If you like that style, you'll probably be more productive that way (and be intrigued by Cycle.js). If you don't like that style, you won't be.
Also:
> the statement above implies the existence of 'this' is a failure of JavaScript's design
It's certainly been a pain point, and there's a lot of confusion and debate over classes, prototypes, constructors, the this keyword, figuring out what 'this` even refers to at any given point, the 'new' keyword, etc. I'm not sure I'd agree that the existence of the 'this' keyword is a mistake (and I doubt the people behind Cycle.js would either), but I don't think it's controversial to note that you can avoid a lot of confusion and sidestep the whole thing, if you are of a mind, by just using plain functions returning objects as needed.
Re:Plug and Play All Your Observable Streams With Cycle.js
by tobr on Friday November 06, 2015 @06:57AM
(#10519009)
If you want to adopt a functional style, then there is little benefit to using `this` instead of regular arguments or closures, which are more versatile and follow more straightforward rules. I think most JS developers have been confused over the value of `this` more than once.
Re:Plug and Play All Your Observable Streams With Cycle.js
by RobertKerans on Friday November 06, 2015 @07:46AM
(#10519154)
YMMV, but I thought I would use them more regularly the more I wrote my JS in a functional style, but the use cases started to steadily dry up; it's gets much easier to write code that simply doesn't need to hold the reference in that way. Arrow functions help a great deal (there is no concept of `this` within them). Still very useful, but in very specific cases, or abstracted off into helpers. I've found `bind()` is much more useful (and will become moreso if the bind operator is okayed and optimised).
Re:Plug and Play All Your Observable Streams With Cycle.js
by cmdv on Thursday November 05, 2015 @08:32AM
(#10513166)
I've been playing with Cycle.js and was struggling a little even though I have previous experience in RxJS but after going through this article it really cleared up some fundamental aspects to Cycle.js :)
Re:Plug and Play All Your Observable Streams With Cycle.js
by RobertKerans on Friday November 06, 2015 @07:57AM
(#10519183)
The PragProg book they just released uses RXJS && Cycle.JS: I'm about halfway though at the minute, it's been really good so far, and I'd recommend it if you're wanting a bit more detail.
[1] Blog post about this: http://underscore.io/blog/posts/2015/04/28/monadic-io-lazine...
this, uh, doesn't seem to match my normal understanding of JS. Normally the method to reuse code is to change what 'this' refers to, but the statement above implies the existence of 'this' is a failure of JavaScript's design. I would like some elaboration.
If you use an OOP style (with classes and inheritance), then you end up needing to use the 'this' keyword. If you use a functional style, you don't.
Is the functional style better? Does it let you write more reusable code, and avoid tightly coupling it to date? Eh...maybe. If you like that style, you'll probably be more productive that way (and be intrigued by Cycle.js). If you don't like that style, you won't be.
Also:
> the statement above implies the existence of 'this' is a failure of JavaScript's design
It's certainly been a pain point, and there's a lot of confusion and debate over classes, prototypes, constructors, the this keyword, figuring out what 'this` even refers to at any given point, the 'new' keyword, etc. I'm not sure I'd agree that the existence of the 'this' keyword is a mistake (and I doubt the people behind Cycle.js would either), but I don't think it's controversial to note that you can avoid a lot of confusion and sidestep the whole thing, if you are of a mind, by just using plain functions returning objects as needed.
Never seen that before; +1 for medium.com