News for hackers. Stuff that matters.
Re:ReasonML – React as first intended by amenod on Thursday May 24, 2018 @11:00AM (#17144636)
Honest question: why would someone use this instead of React?

From my point of view, React solved a real problem. JS before React (at least old-skool, with jQuery & co.) was simply unmaintainable. It was often easier to thow old projects away and start anew than to maintain what inevitably became a tangled mess of callbacks and global variables. Not because of incompetency of developers (at least I hope so ;) but because there were no standard of encapsulation, separation of concerns and similar.

Why would someone who knows React want to switch to ReasonML?

Re:ReasonML – React as first intended by Rotareti on Thursday May 24, 2018 @12:37PM (#17145726)
The last ReactJS project I was working on ended up with libraries such as Ramda, ImmubtableJS, recompose, etc, in order to make the codebase more functional... We also switched to TypeScript for the type-system. While these libs improved the overall experience, it never came close to what you get from a proper functional language. I'm currently working on a frontend that uses ReasonReact and it feels much smoother.

> Honest question: why would someone use this instead of React?

The libraries I mentioned have __a_lot__ of stars on github, I'm sure many people using them, those might be better off with ReasonML.

I hope ReasonML will succeed and the ecosystem catches up. ReasonML is the fucntional general purpose language I always wanted. If they get the concurrency story right it might become a nice functional alternative to Golang as well.

Re:ReasonML – React as first intended by dmead on Thursday May 24, 2018 @01:48PM (#17146443)
fucntional
Re:ReasonML – React as first intended by simplify on Thursday May 24, 2018 @11:23AM (#17144883)
ReasonML has more potential. Aside from its excellent type system (one of the best), it can also compile to native code. This has several benefits:

- Frontend: Your tools are fast. The ReasonML-to-JS compiler is already an order of magnitude faster that TypeScript, etc. Fastpack is a native bundler in the works that aims to bundle your project in under a second (and faster for incremental builds).

- Mobile & Desktop: Some are experimenting right now with writing a version of React in pure Reason that compiles to native code, bypassing the JavaScript runtime entirely.

- Backend: You'll be able to use the Node.js ecosystem but compile certain modules to native code when you need critical performance.

Edit: I should add, the Node.js backend story is currently the least developed part of the ecosystem (I'm personally working on getting that up to speed).

Re:ReasonML – React as first intended by christophilus on Thursday May 24, 2018 @02:29PM (#17146872)
Yeah. The OCaml compiler is just crazy fast. It's like Go, but with a super nice functional language. The compiler seems to be doing a heck of a lot of heavy-lifting in such a small amount of time. I'd be interested in a talk about how it manages that, if anyone knows of one.
Re:ReasonML – React as first intended by Aeolus98 on Monday May 28, 2018 @03:20PM (#17174250)
A lot of the tooling speed comes from a couple places:

1. The compiler optimizations being applied to code - Things like GADT's are able to be allocated very efficiently - Can generate code that doesn't box at runtime (smash it into a pointer is done as well) - Pointers are word-aligned

2. The OCaml runtime - No JIT - No warmup - Can emit native code

3. The HM type system - Typecheckers for HM are really simple [1]

[1] https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_sy...

This simplicity + the features of the compiler combine to make the OCaml compiler very fast, and very easy to write one (some undergrad CS classes do), and developer-time tenable to make both happen.

Re:ReasonML – React as first intended by komuW on Thursday May 24, 2018 @12:03PM (#17145302)
This reminds me that all those points would apply to dartlang
Re:ReasonML – React as first intended by cookiecavekeep on Thursday May 24, 2018 @01:40PM (#17146379)
Except for the speed argument. For AngularDart projects: the current compiler (ddc) takes minutes to warm up and since it keeps all assets in memory, is quite memory hungry as well. The new incremental build tools are much nicer to use (store assets on disk), and a lot faster after the first build, but still nowhere near sub-second.
Re:ReasonML – React as first intended by BLanen on Thursday May 24, 2018 @04:15PM (#17147926)
I mean, why even use node for the backend?
Re:ReasonML – React as first intended by amenod on Thursday May 24, 2018 @11:44AM (#17145105)
Thanks (to the others too), that does sound good.
Re:ReasonML – React as first intended by bratsche on Thursday May 24, 2018 @11:21AM (#17144858)
You wouldn't necessarily use ReasonML instead of React, you can use them together. You would use ReasonML instead of whatever Babel/es6/es7/typescript/whatever.

Here is the official React binding (or whatever you call it) for ReasonML: https://reasonml.github.io/reason-react/

Using this you would still be using React, just in a different language. But my understanding is that you would not be using redux (if you are now) because it doesn't make sense in a language like ReasonML.

Re:ReasonML – React as first intended by RussianCow on Thursday May 24, 2018 @11:42AM (#17145087)
> But my understanding is that you would not be using redux (if you are now) because it doesn't make sense in a language like ReasonML.

Why would using Redux not make sense? It's not like the problem of sharing state between components goes away with a functional language?

Re:ReasonML – React as first intended by Kiro on Thursday May 24, 2018 @11:57AM (#17145239)
It's covered in the article:

"When using ReasonML, we don't need Redux anymore. ReactReason stateless components already come with the concept of a build in reducer, which is meant to take care of the problems Redux used to address."

Re:ReasonML – React as first intended by RussianCow on Thursday May 24, 2018 @12:21PM (#17145539)
Reducers are only one (and IMO the least important) part of using Redux with React; the other part is `connect`, which lets you pass global state directly into a deeply nested component without passing it all the way down the tree via props. Unless I'm mistaken, ReactReason doesn't offer an alternative to that.
Re:ReasonML – React as first intended by cdaringe on Thursday May 24, 2018 @01:13PM (#17146130)
Historically a single connected root has been frowned upon. I'm not so sure it should still be feared now that you can use PureComponents and FSCs the whole way down. ShouldComponentUpdate calls are cheap in pure-town.
Re:ReasonML – React as first intended by RussianCow on Thursday May 24, 2018 @01:36PM (#17146326)
For me, it's not a matter of performance, but rather of convenience. If I have a deeply nested component that needs to dispatch an action or access a part of the global state, I don't want to have to pass that all the way down through every other component in the hierarchy. The grandparent of a "Like" button shouldn't need to know the details of how it's implemented with regards to the global state, but it's forced to if you pass everything via props.
Re:ReasonML – React as first intended by DougBTX on Thursday May 24, 2018 @01:54PM (#17146503)
The newly official Context API might change things here, since it will be much easier to pass state down to grandchildren. I’ve not been keeping up to date with the plans for what react-redux will do with the new API yet, could be interesting.
Re:ReasonML – React as first intended by cdaringe on Thursday May 24, 2018 @02:52PM (#17147097)
Action creators always felt like and unnecessary abstraction to me. To avoid the aforementioned problem, I passed down a message library, or action object that has all of the actions on it, and dispatch. It's all I need!
Re:ReasonML – React as first intended by acemarke on Thursday May 24, 2018 @10:13PM (#17150128)
Sure, action creators are "unnecessary" - you can always declare action objects and action types directly inline:

    this.props.dispatch({type : "INCREMENT"});
Nothing's ever _forced_ you to use action creators, or declare your type constants separately.

However, we encourage use of action creators as a good practice. See my blog post "Idiomatic Redux: Why Use Action Creators?" [0] for some reasons, as well as the related Redux FAQ entry [1].

[0] http://blog.isquaredsoftware.com/2016/10/idiomatic-redux-why...

[1] https://redux.js.org/faq/code-structure#why-should-i-use-act...

Re:ReasonML – React as first intended by cdaringe on Thursday May 24, 2018 @11:21PM (#17150377)
I respect your opinion but found each of the arguments contained within weak or easily countered.

> 1 ... put the logic for creating that action in one place

This isn't so simple. You end up duping the action in at minimum 1 AC (often many ACs), and onboard the complexity of an unnecessary function, plus importing and connecting that function all over your app. A UNIQUE_ACTION_CONSTANT is an easy refactor, unlike action creators, which can cause a cascade of changes when reworking component structures.

> 3 ... larger logic that goes into preparing the action object,

This justies a function, not necessarily an AC.

> 4 ... lets the action creator worry about how to handle things

Smart components are already aware of the state system by means of connect. Further, in AC aware apps, you have a whole swath of extra imports to manage, more connect calls to manage, and a binding API to consider, which sometimes requires patterns and team agreement on their own. dispatch + messages does away with all of that, and is shown to be simple/effective as popularized in Elm and Reason.

> 5 ... testing

Kinda. I'll meet ya half way here. But stubbing disptach and/or component methods is also very cheap, and super simple to reason about.

I say this all in the spirit of collaboration and productive debate :)

Re:ReasonML – React as first intended by crooked-v on Thursday May 24, 2018 @03:18PM (#17147308)
The new context API can probably help with that. Pass an object through context that contains the reducer state of a root level component (or a getState() or whatever), plus a dispatch function. Blam, Redux-equivalent without a separate library.
Re:ReasonML – React as first intended by RobertKerans on Thursday May 24, 2018 @04:40PM (#17148212)
ReasonReact doesn't have Context, the API is unstable so they aren't binding to it.
Re:ReasonML – React as first intended by RussianCow on Thursday May 24, 2018 @05:11PM (#17148450)
The new API as of 16.3 is stable, so I suspect ReactReason will support it soon (if it doesn't already, by default).

https://reactjs.org/docs/context.html

Re:ReasonML – React as first intended by RobertKerans on Friday May 25, 2018 @04:08AM (#17151558)
Ah, that's great that it's finally settled. RR is on v15 in terms of what it has to support though, so no dice; main focus at the minute seems to be on dropping v15 support and migrating to v16, which cleans up some of the code (particularly w/r/t the async side), but that has to happen before they bind to the new API, so going to be a while.
Re:ReasonML – React as first intended by bratsche on Thursday May 24, 2018 @12:00PM (#17145266)
I commented before reading the article, just going by memory of reading about this before. Perhaps I was wrong about it not making sense in the language, but more that it isn't necessary when using ReactReason because the concept is built into that binding.
Re:ReasonML – React as first intended by crimsonalucard on Thursday May 24, 2018 @12:49PM (#17145859)
Nobody mentioned the biggest reason. True functional programming coupled with type checking leads to more modular programs with significantly less bugs. I don't know about ReasonML, but a similar framework called ELM delivers Zero run time errors. Zero. Languages that eliminate entire classes of errors from type errors to run time errors should be the future evolution of programming languages. React+redux was only a small step in the right direction.
Re:ReasonML – React as first intended by disease on Thursday May 24, 2018 @02:36PM (#17146943)
Well said. When we went from JavaScript to TypeScript we completely eliminated any errors we had associated with types. Then we turned on the noImplicitAny and strickNullChecks options and completely got rid of our 'x is not a function of y' and 'z is not defined' errors.
Re:ReasonML – React as first intended by ardfard on Thursday May 24, 2018 @11:14AM (#17144781)
ReasonML is a language that transpiles to JS, not a view library so it's not gonna replace React. The more appropriate question is why someone use this for developing React app rather than using plain JS? The answer is IMO because React paradigm lent itself better with functional way of handling state like immutability and persistent data structures that's why ReasonML is more like a perfect match.
Re:ReasonML – React as first intended by hellofunk on Thursday May 24, 2018 @11:05AM (#17144687)
Because React is a very natural fit for a functional language of which JS really isn’t. Which is also why it is so lovely to use React from Clojurescript.
Re:ReasonML – React as first intended by Scarbutt on Thursday May 24, 2018 @11:22AM (#17144866)
How's Clojurescript interop story? what always holds me from using these compile to JS langs is the fear that the gains you get from using a better/nicer language are completely destroyed by all the interop churn.
Re:ReasonML – React as first intended by lilactown on Thursday May 24, 2018 @11:44AM (#17145107)
As someone who's done a bunch of interop in ReasonML & ClojureScript, ClojureScript interop blows ReasonML away (in terms of ease) at the language level.

The current problem with ClojureScript interop is the Google Closure compiler's support for stuff on npm. I switched our team to using shadow-cljs[0] and it solved all of those problems. Would highly recommend.

[0] http://shadow-cljs.org/

Re:ReasonML – React as first intended by Scarbutt on Friday May 25, 2018 @07:41PM (#17159093)
Ok thanks, I know this can be highly subjective but which do you prefer between the two (reason and cljs) and why?
Re:ReasonML – React as first intended by lilactown on Saturday May 26, 2018 @07:26PM (#17164724)
I really like both languages. Like, a lot. They both tick all the boxes of:

1. Immutable by default (with sane escape hatches) 2. Fully qualified namespaces 3. Functional (with sane escape hatches) 4. Good interop with host platform

At the beginning of this year, my team started a green field project to replace our old system. I had the chance to steer us toward ReasonML or Clojure(Script), and we decided on Clojure.

The main reasons were:

1. The number and maturity of libraries for Clojure(Script) was much higher 2. Clojure's server-side story was much better, and we needed to write a ton of services as well as client-side code 3. The ecosystem, language & tooling was much more stable for Clojure back then

I think that ReasonML has a ton of great ideas, it just lacks maturity. I love the language itself, but I would not yet want to inflict it upon my team mates who have spent the last 10 years writing Java back-end services. Clojure(Script) ended up being a much better fit and I feel like I am just as productive, if not moreso, than when I was writing code in ReasonML.

Re:ReasonML – React as first intended by hajile on Thursday May 24, 2018 @06:15PM (#17148974)
What level of inter-opt? If you want to gradually convert from JS to clojurescript, it seemed like a huge amount of work.
Re:ReasonML – React as first intended by lilactown on Thursday May 24, 2018 @08:45PM (#17149772)
Ah, hmm.

Using JS from CLJS is incredibly easy. Like I said, shadow-cljs solved all of our problems there.

Going the other way - using code written in CLJS in JS - is another matter. This is not well supported by the ecosystem. shadow-cljs has much, much better support for this than the standard ClojureScript/closure compiler, but it doesn't hold a candle to what BuckleScript does.

IME, doing a top-down transition - where you convert the top of your app to ClojureScript, that calls everything - works best. From the top, you work your way down into each feature.

ReasonML, on the other hand, works better from the bottom up. Typing your whole app is hard, so you start with some small feature that then you export to JS land (since that's so much easier with BuckleScript). From the bottom, you work your way into writing more and more features in ReasonML.

Re:ReasonML – React as first intended by hellofunk on Thursday May 24, 2018 @12:10PM (#17145371)
Clojure, on any platform (JVM, JS, .Net) has a fundamental language-level philosophy of easy interop with the host.
Re:ReasonML – React as first intended by specialp on Thursday May 24, 2018 @12:29PM (#17145631)
Clojurescript has very easy JS interopt (clj->js), (js->clj) plus easy ways to export external js library functions. There's been nothing I can't do in CLJS.
Re:ReasonML – React as first intended by yashafromrussia on Thursday May 24, 2018 @11:06AM (#17144690)
Someone who knows React can easily be using ReasonML. So to me, the question is, why not? You can get most of the features of ReasonML with 3rd party libs - TypeScript for type safety, Redux for state management, and Immutable. However, when I look at the build time comparison, I doubt you'd get something as fast with JavaScript, at least not today.
Re:ReasonML – React as first intended by actsasbuffoon on Thursday May 24, 2018 @11:35AM (#17145027)
Typescript, Redux, and Immutable.js work together as a pretty compelling stack, but they involve a fair bit of boilerplate compared to Elm or ReasonML.

Elm provides type safety, immutable data structures, and state management in a very compact but readable way. In fact, Redux was strongly inspired by Elm's state management.

All of these stacks are perfectly acceptable choices, so it comes down to a matter of personal preference. I'd encourage everyone to spend some time with Elm and ReasonML. I find them to be productive and very enjoyable tools.

Re:ReasonML – React as first intended by cies on Thursday May 24, 2018 @11:50AM (#17145171)
> compared to Elm or ReasonML

PureScript deserves a mention in this list as well. More full-featured and general purpose than Elm, cleaner design than ReasonML. Prolly the smallest community of the 3.

Re:ReasonML – React as first intended by fpoling on Thursday May 24, 2018 @03:20PM (#17147325)
I played with PureScript a little. It has advanced type system that captures a lot of semantics of JS allowing easy interobility with JS ecosystem. But that comes with a huge price. With all those monads and monad transformers interacting with JS it is easy to end up with stateful mess. Surely, it will be typed and functional mess, but still it is hard to maintain with all state pieces spread through code hiding in lambdas.

With Elm the situation is very different. All your code is pure. The runtime hides the state management and the only way to interact with JS is via message passing. The end result is code that is extremely easy to follow, maintain and debug. Moreover, as Elm style and tooling discourages using lambda-style callbacks with opaque state, all state is very explicit and often just by looking at the state data structures, one often can grasp what the code is doing. It is almost like code follows from the data structures.

Re:ReasonML – React as first intended by cies on Thursday May 24, 2018 @08:55PM (#17149818)
Elm is a lang and a FW in one. Very opinionated. Very batteries included.

PS is a lang. It compiles well to JS, but there is no friction against making it compile to native, apart from the time it takes to maintain that compiler backend.

On top of PS you may pick a FW. Some have React.js under the hood, some follow more closely The Elm Architecture.

Only with a FW, PS can be compared to Elm.

Re:ReasonML – React as first intended by fpoling on Friday May 25, 2018 @01:48AM (#17150927)
Elm is also a language. Surely it's libraries and runtime assume JS and DOM, but nothing prevents creating other ports of the language or creating alternative libraries.

And yes, Elm is opinionated. But that is a consequence of being very simple and pure functional language. As its typesystem does not support using monads or effects to model state with code similar in style to that in non-functional languages, one inevitably ends up with a runtime similar to Elm browser bindings in any Elm embedding.

Essentially Elm is opinionated because its pure functional style is the only style supported by the language with no escape hatches like the do blocks in Haskell or PureScript.

Re:ReasonML – React as first intended by actsasbuffoon on Thursday May 24, 2018 @01:40PM (#17146367)
I love Purescript, but I'd be hesitant to recommend it to anyone without a Haskell background. There's a lot more to learn in Purescript, and I'd worry that it could discourage people who are new to the Haskell family of languages.

I'd advise starting with Elm to fall in love with the development experience and wonderful error messages, and graduating to Purescript when you need more power.

Re:ReasonML – React as first intended by christophilus on Thursday May 24, 2018 @02:42PM (#17147006)
I like PureScript a whole lot. Something that ClojureScript and Reason seem to have on PureScript is really efficient persistent structures being the default, at least if I remember correctly. It's been a while, but I seem to recall PureScript giving me nice, functional syntax that under the hood did lots of native JS object / array copies.
Re:ReasonML – React as first intended by tfranco on Thursday May 24, 2018 @12:31PM (#17145663)
Interesting. We covered ELM a few weeks ago: https://www.imaginarycloud.com/blog/elm-javascript-reinvente...
Re:ReasonML – React as first intended by baddox on Thursday May 24, 2018 @12:37PM (#17145724)
The jump from Typescript/Flow to ReasonML is as significant (or more so) than the jump from plain JavaScript to Typescript/Flow.
Re:ReasonML – React as first intended by scns on Thursday May 24, 2018 @12:06PM (#17145332)
Facebook rewrote Messenger in Reason. Before they had hundreds of bugreports in a year. Afterwards? Less then ten.
Re:ReasonML – React as first intended by cjbprime on Thursday May 24, 2018 @03:16PM (#17147298)
Did they rewrite it using the old language too, as a control? :)
Re:ReasonML – React as first intended by Scarbutt on Thursday May 24, 2018 @12:09PM (#17145365)
Is there some official analysis of this?
Re:ReasonML – React as first intended by adamkl on Thursday May 24, 2018 @12:31PM (#17145652)
Note, the ReasonML rewrite refers to the Web version of Messenger only (at the time of this blog post):

https://reasonml.github.io/blog/2017/09/08/messenger-50-reas...

Re:ReasonML – React as first intended by tigershark on Thursday May 24, 2018 @03:15PM (#17147290)
Everyone that works with F# and OCAML can confirm the trend I guess..
Re:ReasonML – React as first intended by ch4s3 on Thursday May 24, 2018 @11:02AM (#17144658)
For the same/similar reasons, more or less. You get a great type system, merlin(a great analysis tool), faster compilation, all kinds of great compile time checks, and you can still use react.
Re:ReasonML – React as first intended by mLuby on Thursday May 24, 2018 @11:09AM (#17144733)
Those are all good things, but they aren't really the same reason. Parent describes JQuery to React as spaghetti code -> reasonable code, whereas React to ReasonML sounds like reasonable code -> reasonable code (with better tooling).
Re:ReasonML – React as first intended by ch4s3 on Thursday May 24, 2018 @11:20AM (#17144847)
Yeah, I agree but would say reasonable code -> slightly more maintainable, reasonable code. Sure, the low hanging fruit is gone, but it's a similar reason. What I'm getting at is that you can write spaghetti React pretty easily, and people do. One of the core promises of using an ML to do react is that its harder to mess with state all over the app and wind up with a big bowl of spaghetti.
Re:ReasonML – React as first intended by cies on Thursday May 24, 2018 @11:53AM (#17145199)
JS code can be a pain to maintain (in the membrane... joke, sorry, I'll stop). And FB knows this. That's why they developed ReasonML: great JS interop, but much better maintenance story (than both JS and TS) because of the stronger typing discipline.

On a large code base, increased maintainability can be a huge commercial advantage.

Re:ReasonML – React as first intended by Scarbutt on Thursday May 24, 2018 @11:09AM (#17144737)
Some developers believe (and prefer) in that good type systems help for large software projects.
Re:ReasonML – React as first intended by cies on Thursday May 24, 2018 @11:54AM (#17145207)
A company like FB believes so too, judging from how much resources they throw at it.
Re:ReasonML – React as first intended by gildas on Thursday May 24, 2018 @02:18PM (#17146782)
> From my point of view, React solved a real problem. JS before React (at least old-skool, with jQuery & co.) was simply unmaintainable

Why would someone who knows Dojo or GWT want to switch to React?