by skywal_l · 4y ago · 0 comments
* the use of decorators in even the most basic example
* no async/await. You fall back to Promise.{then,resolve}. The example given is not that clear to me.
* You can't have two files with the same name in different folders??
And in general, for me, the ability to be a little less strict at times makes Typescript way more easier to deal with. It's a 80/20 thing. Most of the time I want type enforced but in some situation, I know it's OK and I just want to move on with my day.
Using fp-ts there is never a need for async/await and the code is still linear, (Promise is transformed to TaskEither<Error, Result>, similar to the example in the article, although you can ignore the error and just map over the result, handling the error somewhere near the end of the chain).
Problem with async/await is that the syntax is so easy that eventually the whole codebase gets polluted by it, even parts that could have been completely separated.
From the coding perspective, the problem with promises arise when there is a need to bind the intermediate results. You can either store them in an object and return that object for the next .then(fn) call, or you can nest inside a promise. I guess nesting is what annoys people the most (pyramid).
Curious, why is this bad?
When code is sloppily written you realize that at some point you can't use much of the existing code outside of async.
One nice example of polluting the codebase is having async local storage. Now everything that reads from the storage needs to be annotated async and now your initialization pipeline might be insanely async. Good way to avoid it is to read the whole local storage at the beginning (having a sync interface) and then everyone just reads without await.
From recent experience, I did exactly that with storage and ended up removing thousands of async annotations that were no longer necessary.
Similar "mistakes" happen for other things and then at some point you are putting loading guards everywhere because your async operations are always awaiting and letting the UI update when it should not.
You say async were all over the place. Either it makes sense because fundamentally, what you are doing IS asynchronous. Or it make no sense because the asynchronous nature of you calls are not important in your design (I don't see why but ok), in that case you can always break the chains by using a promise:
async bar() {
return await baz();
}
foo() {
const promise = bar();
promise.then(() => {}); // don't care...
}Can we agree that JSX is not a valid JS? So decorators are required indeed to simulate "JSX magic"
> no async/await.
As I mentioned, it's not an really an issue (although I though it will be). At least from my experience.
> You can't have two files with the same name in different folders??
This sucks indeed :)
The problem that those 20% corrupt the value of another 80% :/
Neither is rescript - so why not make jsx a first class citizen?
Doesn't this mean we're basically back to callback hell? This was one of the primary criticisms of Node before async/await was introduced.
Await/Async kind of streamlined all this.
async/await aren't keywords in F# and kotlin
Ah yes. The magic word "just". You "just" do something that does something.
And yet even the example in the article uses Promise.then and eventual callback hell.
https://github.com/ocsigen/lwt
The `let* in` is a generic syntax for monads, it doesn't need a special one just for promise. This was in fact a debate back when async/await was in consideration for ECMAScript, but special syntax is hip so now we have `async/await` for Promise, `.?` for optionals and `flatMap` for arrays, basically the same thing.
hello.then(a => return op1(a)).then(b => return op2(b)).then(c => console.log(c);
const a = await hello();
const b = await op1(a);
const c = await op2(b);
console.log(c)
In Haskell (>>= is pronounced "bind", \a -> is like a => in JS): hello >>= (\a -> op1 a >>= (\b -> op2 b >>= (\c -> show c)))
do {
a <- hello;
b <- op1 a;
c <- op2 b;
show c
}
There is a slight difference, in that JS promises aren't monads. But the idea is still here.Ia desugared to m >>= (\a -> return r)
Think of it m.then(function (a) return r)
ReScript requires a lot of commitment, as you have to completely rewrite each module to 100% comply with the type algorithm.
Typescript even transpiles when it encounters type errors.
We started using Rescript by adopting individual files until most of our codebase is ReScript. We still have Typescript lingering around but folks _choose_ to refactor it to Rescript because they've found it easier to work with.
Rescript doesn't make you do strange things. The async/await stuff is annoying for sure, but after 3 years of using it, we've kinda forgotten about it.