> ReScript, as with other statically typed functional languages, aims at changing the way code is approached at a fundamental level.
We currently have a project written in ReScript and it's an absolute nightmare. Most of our stack is JavaScript/TypeScript/Flow, so no one can just jump in and work on it very easily - they first have to learn ReScript and all of it's different concepts, approaches, and nuances (or refresh themselves if they've done that but haven't worked on the project in a while). It's a HUGE context switch. At least TypeScript is a superset of JavaScript so it's very easy to get up to speed on for a JavaScript developer, and switch between.
For a side project this is fun. But I would never consider this for a "real-world" project (i.e. something you get paid for). At least not anytime soon. Maybe in a few years if there's wider adoption, but that's a long way off.
It's a common challenge with any kind of software; as a company, you want to avoid adding more to your stack, even if it means using a suboptimal or boring technology. Every new technology adds complexity and difficulty. Actually I'll just link it, it explains the concept much better (and with pictures!) than I can: http://boringtechnology.club/
As somebody who really, really likes boring, I think it's time to put Typescript in the Boring category -- at least on the client side.
Practically all major libraries provide a Typescript definition. Especially React, which has become the boring choice for a lot of client side programming. And you were going to end up using some sort of cross-compiler and packager for significant browser code anyway, just to wrap up all that risk about multiple browsers.
That's a bit less clear on the server side, where you have more control. But two things are going for you: if you're going to use Node you might as well use the same language on both sides, and you can cleanly escape to plain Javascript if you feel compelled.
(Personally I'd prefer a less sucky language, but honestly, TS makes JS pretty good. Not great, especially with all the legacy warts, but decent, and at least you get to share code with the browser.)
TS has survived long enough and become endemic enough that it doesn't look like much risk any more, and it's a vastly better language than plain Javascript -- especially for reducing the risks that come with long-term boring projects. If you're writing JS and like boring, Typescript is looking increasingly like the good, boring choice.
I help maintain ReScript. That it _seems_ to change the way code is approached is an artifact of an early community excited to try FP concepts in it. Nothing wrong with that; however, the ReScript team (me included) don't really approach things this way. Our goal, outlined at (https://rescript-lang.org/docs/manual/latest/introduction), is to provide:
- a more solid type system
- and a much faster compilation speed (a growing pain in TS projects)
- to write mainstream code
- for products (as opposed to a focus on intermediate FP libraries)
The fact that it leverages some FP concepts here and there is just a mean, not the end.
The marketing of this is really hard, because FP usually attracts the crowd you'd expect, at the expense of several of the above emphasis. But we're still working toward it.
Having seen some ReScript codebases in the wild, I definitely know where your team comes from. We do try to approach it with the "different TypeScript" angle, but understandably userland doesn't always write code the way we'd like to recommend.
> ReScript is not just a rebranding: it’s a ReasonML which freed itself of the yoke of the OCaml ecosystem. By doing so, it forfeited compilation to native code and OCaml library interop, but gained a freer syntax which further resembles JavaScript
See also BuckleScript & Reason are now called ReScript:
At least from a branding perspective, it seems the whole thing has been quite bungled. But obviously what's more relevant is how well the technical goals actually get met.
A couple of years ago I was a big advocate of ReasonML and went so far as to run a meet up. I honestly believed in the technical value of it and saw it as a better alternative to Typescript.
At the time, the waters were muddy enough with Reason, Bucklescript and OCaml but you could explain it away. The rebrand and change of syntax that came with Rescript was the end of the line for me. Issues like async await have gone unaddressed for years and instead the community is caught up on syntaxes and compilation targets.
I turned to Clojurescript since. It solved most of it's problems years ago and its functional enough that I don't miss the static types. The large standard library also avoids the questions around whether you should use Belt or Tablecloth or any of the other "standard" libraries.
It's certainly confusing, it's a small niche. It may just cater to people who already know functional programming. The majority will stuck in JS anyway to get the job done.
Generally speaking, I am pretty happy with the (small) syntax changes from Reason to Rescript [1]. No necessary semi-colon, arrays, object declaration & access. We can finally pattern match on arrays [2] which I think was not possible with Reason (only lists were).
However, there are no custom infix operator with Rescript [1], which is quite sad as it makes monadic code cleaner, whereas they were supported by ReasonML.
I find the dropping of native compilation to be unfortunate.
There are 3 categories of code I’m interested in writing:
- Client code, must compile to JS.
- Server code, ideally would compile to native.
- Tooling code (e.g. Webpack / Babel replacements), ideally would compile to native.
I would like to write these things in one language.
I was using TypeScript all through 2019. Went back to plain old JavaScript at the beginning of 2020. Still using plain old JavaScript by default, and break out React when I _really_ have to. No regrets, many benefits.
I write pure TS code, and I never use sourcemaps to debug (Chrome Dev Tools has a setting that allows you to disable using sourcemaps).
And our code is setup to compile to ES2015, I believe.
The reason is simple. Typescript's compilation to JS is really straightforward. You can predict the code that will be generated trivially, because the vast majority of the time it does nothing more than stripping away types.
Since we compile down to ES2015, there are a few additional trivial transformations to handle unsupported features like "let" correctly, but they are also trivial to understand.
I’ve been a huge supporter of VanillaJS for years. In my opinion, standard modern JavaScript is powerful enough to stand on its own for all of the reasons you state. The biggest problem with transpiled languages is that there is yet another level of abstraction to reason about, so debugging can become quite tricky. Many platforms already make layout and markup too abstract (JSF, Slim, to name a few).
Now, if you’re working with something like Angular, TypeScript makes sense and is portable within that ecosystem, but that’s it.
I once wrote a widget/plugin in pure JavaScript and it worked perfectly well. However, because the project’s “standard” was to use Coffeescript, I was forced to rewrite it in that. Luckily I found a Javascript to Coffeescript converter, which in the end I found extremely amusing because that of course gets compiled to Javascript, which had been written in Javascript in the first place. The resultant code looked like a bad translation of English to Italian and back to English again.
I've been using vanilla JS when not using Reason and it is pretty nice. I hate that safari does not support arrow function methods though (as they allow you to not have to bind `this` in the constructor).
concerning you post scriptum in brackets, what I like with types is:
Which version of Safari are you using? According to caniuse[0], arrow functions are supported in Safari starting with version 10, which is over four years old at this point.
They said "arrow function methods", so I assume they're looking for public class fields support [1], not only arrow functions support per se. Public class fields (apart from static fields) are also supported in Safari though since September.
Yes, that's exactly what I meant! Nice! Indeed, I had in mind a script I wrote just around that time and I guess the iPhone I was testing on was not fully updated. Just checked on my Safari on Big Sur and they do work now, sweet ! Should have tried / checked before commenting, thanks for the heads up ;)
I'm willing to accept the basic hypothesis that's static typing makes for less runtime errors. The type system in well thought out languages like elm or rust makes coding in them pretty simple. I don't think that typescript's type system is good enough to actually deliver on this promise.
It's very easy, in my experience, to spend 5 minutes writing a function that I am 100% sure will work fine in JavaScript, and then spend 15 minutes trying to figure out how to type it. I'm sure that this is partly due to my own lack of understanding. Typing is basically a huge add-on to the cognitive load when using this superset.
Of course, it could just be that I'm not very good at typescript. But it's a new technology, and it's very possible to find yourself on a project with people who aren't that experienced with it.
Additionally, I think the type system really pushes you towards object oriented programming. This is fundamentally at odds with the way most people write ReactJS.
Lastly, while deno is becoming a more viable option, most JavaScript development is taking place in node, meaning you have to transpile it. TypeScript adds the overhead of needing a build tool. Using `.mjs` files makes it so easy to spin up a project without any dependencies, something the HN crowd is always kvetching about.
> I'm willing to accept the basic hypothesis that's static typing makes for less runtime errors. The type system in well thought out languages like elm or rust makes coding in them pretty simple. I don't think that typescript's type system is good enough to actually deliver on this promise.
I can only share my experience in multiple companies and products that it does deliver and it can result in a dramatic decrease of defects.
> I'm sure that this is partly due to my own lack of understanding. Typing is basically a huge add-on to the cognitive load when using this superset. [...] Of course, it could just be that I'm not very good at typescript. But it's a new technology, and it's very possible to find yourself on a project with people who aren't that experienced with it.
Tools don't come for free. You need to understand TypeScript in order to use it effectively. In my experience having at least a couple senior or principal developers with TypeScript proficiency makes a huge difference, not just because they can assist and guide you, but because with TypeScript they can create a well typed ecosystem that results in it being easier for developers to code safely and following a well thought-out architecture (or rather, make it harder to not do it right), and set up linters & autofixers and other tooling to make things even easier.
> Additionally, I think the type system really pushes you towards object oriented programming. This is fundamentally at odds with the way most people write ReactJS.
I'm curious what gives you this impression. The codebases I've worked with are heavily functional, with very little OO code —sometimes it makes sense— and if anything TS helps us do FP better.
People here are forgetting that Typescript is first and foremost a static code analysis tool for Javascript. You can run Typescript's compiler WITHOUT writing a single type declaration as part of your CI, and you should. You don't have to write a single .ts file to use Typescript.
It works in TypeScript - just rename something from JS to TS and the you have the benefits of TS's types, warnings, and features but your code will continue to work. Untyped things default to 'any', which is useful if you want to migrate a project from JS to TS. It's a very useful feature if you have a mature project in JS that you want to improve.
I think it was supposed to be a comparison to Typescript. Since TS is a strict superset of JS you can simply rename a file and refactor into TS as you go.
Why not simply use Javascript? Today it's a fine language. You may complain about fatigue etc which I can buy, but Rescript is simply not solving that.
Because of static types. If you're building software that needs to be maintained over time, types are always preferable to a lack of types. This is because types codify the shape of application data structures that exist whether you explicitly define them or not. A lack of types is a form of technical debt that every future developer has to repay as they discover application data structures through trial and error.
the only reason I'm using typescript over javascript is types, once I converted a huge code base, there were instances where I fed javascript wrong number of args, or just wrong type of args and it did work (failing subtly on runtime), otherwise is perfectly fine.
I also like it for not having to constantly check properties before using them. I parse the data once at the application boundary (like after an API call) and then I can use it with confidence.
Ok well that is true and may happen sometimes. Personally, I have just dabbled with type definitions, configs etc much more than I ever had those kinds of problems in javascript.
I just feel typescript usually gets in the way, sometimes in a good way, but all too often in a bad way.
Plus my main gripe with typescript is that microsoft owns and controls it so I won't use it just because of that.
I made this discovery just yesterday. I tried converting a tiny side project from vanilla JS to Typescript because I wanted to see what all the hype was about. I had this idea in my head(perhaps naively) that I would catch an edge case/silent error or two in my application that I did not know existed prior to implementing static typing.
Instead, I spent a whole bunch of time wrestling with the tooling and configs in order to get my (previously working) code to compile.
I'm not trying to make the conclusion that typescript is bad, as I've hardly even used it at this point. But from my experience, it's not exactly the 1:1 from JS that some people argue. My takeaway is that there can be real value to be had from static typing in JS, but it might not always make sense to introduce the tooling overhead for tiny codebases that are developed by a single maintainer.
It's probably useful, like most stuff that comes out from big companies, if you are a big company with big teams. I do not work for a big company and I will probably never do it again so Typescript is definitely not for me.
People go in this trap again and again, including myself.
"Oh this FAANG uses this, it must be great and suitible for us" - no, it's suitible for them because they have completely different problems than you and have to do stuff in a much more complicated way than you need to.
Recently I think Microsoft is a very good open source supporter. So it isn't a problem for me.
I also feel Typescript is good, but sometimes it is hard to use because of so many typing. It needs VScode always for auto complete helper.
I remember javascript as an old good days...
Well I don't care so much about Microsoft per say, but I try to avoid any tech from any big tech company. I don't like their dominance so I'll rather use alternatives.
Refactoring a large code base is way easier with TypeScript than it is with JavaScript for example. Getting familiar with such a large codebase is also easier with TypeScript thanks to good auto-completion in editors like VSCode.
My interest in ReScript is that it doesn't aim to add more features to JavaScript, it's a completely different language which has a JavaScript-like interface and compiles to JavaScript.
It's a statically-typed functional language from the ML family, which is a huge deal. It implements a completely different approach to code, even if it looks similar.
It's currently academical, "ivory tower," but in my opinion it will trickle into industry. Someone described ReScript as ECMAScript 2030.
> ReScript, as with other statically typed functional languages, aims at changing the way code is approached at a fundamental level.
We currently have a project written in ReScript and it's an absolute nightmare. Most of our stack is JavaScript/TypeScript/Flow, so no one can just jump in and work on it very easily - they first have to learn ReScript and all of it's different concepts, approaches, and nuances (or refresh themselves if they've done that but haven't worked on the project in a while). It's a HUGE context switch. At least TypeScript is a superset of JavaScript so it's very easy to get up to speed on for a JavaScript developer, and switch between.
For a side project this is fun. But I would never consider this for a "real-world" project (i.e. something you get paid for). At least not anytime soon. Maybe in a few years if there's wider adoption, but that's a long way off.