Nobody doubts the functional approach that Elm et al are promoting works, and may very well be the way of the future. Kudos for being an early adopter–the Meteor community definitely needs to become more adventurous like yourself.
That said, you’re missing the point of my article: to honor what functional programming gets right and start a conversation about how to bring the best parts of it to imperative object oriented programming.
…Just stating that “explicitness” is the way to go–not to be rude, but that’s basically like what everyone in 2015 with access to a blog and a little React experience has been doing–is not adding anything to the conversation. Though, in your favor, I do agree us Meteor developers have been blind way too long (me included), especially in comparison to the greater NPM community. 2015 was especially fast, so let it serve as a wakeup call to us.
But let’s move to the next step and start thinking how we can improve Meteor. What you–as in you specifically, Chet–want is a functional stack top to bottom based on observables (imagine cycle.js on the client all the way down to the database). Very similar to what the Datomic database is bringing to the Clojurescript world (which I know you’re aware of, as its integration is a to do item in your “elmish” package):
I.e. similar to what’s described in “Turning the Database inside out”, popularized by Redux creator, Dan Abramov:
…That’s a different framework altogether–and if Meteor was ever to become that there wouldn’t be a single line of code from their current platform. I’m speaking hyperbolically but you get the idea. My point is either way: I agree with you–this would be awesome! Let’s go start a company and build that. Until then, while we’re still using Meteor, let’s figure out what we can fix in a fraction of the time and get it done. Multiple approaches work–so rather than trash one, let’s realize the precise strengths and weaknesses and get to work where we can add value. The main strength being that Meteor is built already and the main weakness of the impending functional stack is that it’s currently just hypothetical. Parts of it are done, particularly the client side, but everything below that HAS NOT ARRIVED YET. I’m considering going being part of that future myself, i.e. its arrival, i.e. helping it to arrive sooner, i.e. building it! That said, I think an incremental approach improving our current tools needs to happen regardless. If you watched @staltz’s video at Reactive Conference:
you will see that we are making improvements to our imperative “horse” while the new functional stack is, what seems to be, a “BMW” lol. …But one hidden takeaway I got from that video is that people will have a hard time migrating from the OOP imperative approach to functional for years to come. The more we can make the OOP imperative approach like the functional approach (like React has done with hybrid functional class-based components), the more we can bridge that gap, the easier we can make it for people to transition to our brighter functional future. I’m not even saying I’m going to be the one to do it and carry the imperative flag for much longer–I’m this close to jumping ship completely like @staltz did with Cycle.js. Either way I have compassion for the struggles with predictability that imperative OOP programmers have and will continue to have, and understand–that for business reasons, the time it takes to learn or other, even plain old stubbornness–it’s not an option for everyone to just jump ship to functional programming. I would also argue it’s not the right time either. The industry is in the midst of so much upheavel. I wouldn’t even build an app right now, if I had the choice. I’d just be part of creating the foundation of the future, and that’s basically what I’m doing with these Medium articles and things like TrackerReact.
The problem explicit fanboys have with implicit abstractions is that so many implicit abstractions are leaky and not complete. If they were rock solid, we wouldn’t be having this conversation. Would you write 100 lines instead of 20 lines if 20 lines was 100% guaranteed to achieve what you want without problems?? No, you wouldn’t. What I’m saying today is Tracker has been far from “rock solid,” but if it was rock solid you wouldn’t even have the trace errors you’re talking about.
In short, we aren’t talking about “magically changing the meaning of [our] code”–we are talking about getting right what Tracker got wrong all along. Tracker never should re-run your code if you don’t even use the fields in your find call! That’s not the expected behavior. It’s nonsense we have put up with because the ease of Meteor application development has lulled so many of us into thinking we could never build the internals of what Meteor is doing ourselves–meanwhile the greater NPM community and sharp individuals like yourself are discovering every day that’s not true and there is a life outside of Meteor [patented @SkinnyGeek1010 concept :)].
You are correct about potentially missing state, but for the wrong reasons. Minimongo is a subset of what’s in Mongo–by caching/snapshotting all of Mongo on your local machine, you guarantee not only that you capture minimongo, but also subscriptions and everything behaves as normally; you guarantee that stale server side data doesn’t come back, which is most important. …and I’m actually incorrect as well–there are local collections too–so we have to snapshot both minimongo and all of mongo, but it’s still not that big of a deal since you only need one extra snapshot, and then a log of all mutations to bring it up to speed when necessary.
But I’m not done disproving your hypothesis that we “[cannot] guarantee [we’ll] reproduce” state well enough to be useable :
…Now, if in Redux you used any immutable data, any global state, within your reducers, you would f#*! it up. right. So similarly in Meteor, any state outside of Minimongo–because of the fact that it’s not tracked–would break things. It doesn’t have to do with the state being held outside the [client] application in Mongo on the server as you’re pin-pointing the problem to be. It has to do with making sure ReactiveDict
, Session
(which is ReactiveDict), and all the most common reactive datasources are snapshotted/cached in the same way. AND THEN on top of that, like reducers in Redux, relies on you not using global variables or properties on global variables to store some extra state. Again, Redux has the same problem; you’re just instructed not to do do that–we can provide similar instructions.
The fact of the matter is most Meteor apps do a good job of relying on reactive datasources rather than plain old global state anyway–so we are most of the way there. They need them to do the reactive stuff Meteor is all about. So it’s not that big of an “ask” to ask developers to just use reactive data sources if they count on time traveling working. If they want to add a new reactive data source, e.g. @luisherranz 's ReactiveState
, well then there’s a simple API he can use to partake in the snapshotting goodness.
But I agree, there are holes. But I would say easy holes to keep plugged if you want to partake in Time Traveling and [accurate] hot module reload. I think a “more than good enough” solution for facilitating time traveling and HMR is completely possible, and in fact easy to build. The more challenging part in fact is traversing the dependency graph and providing dispose
, accept
etc handlers like Webpack so that HMR occurs properly–so for the purpose of this conversation, let’s limit it to Time Traveling.
Time traveling [yes, in a mutable environment] is easily achievable by snapshotting et al as discussed.
I’ll check out Elmish. That’s dope that you used Ramda to make it.