Hacker News new | ask | show | jobs
by y4mi 2358 days ago
And unanimous functions are basically non-existent. Yes, lambda works but only allows a single line, which forces you to name the function anyway.
1 comments

I find that a good thing rather than as a shortcoming. JS/TS looks horrendous with the amount of function nesting. Luckily, it looks like futures and await are resolving some of that mess.

In my mind, the following is better than the JS equivalent using closures:

    response = await AsyncHTTPClient().fetch("http://www.google.com")
    self.result = json.loads(response.payload)
You see exactly what is going on, no additional nesting, and no need for semi-inner state that potentially complicates state reasoning. I.e. people get tempted to put code afterwards thinking it'll run after the previous line.

I may get some flack for this or my language, but I have absolutely no idea why anyone bothers so much with the closure garbage outside of select places where they make sense. It's non-intuitive and looks bad. Heck, I have a bad enough time explaining to seasoned devs the difference between threads and async concepts. Then you throw that sort of stuff at a junior JS dev and chaos will most certainly ensure with a buggy FE where no one can reason about state and there are null checks all over the place, just because. I've seen it in static FE languages like C#, too. State becomes too difficult to reason about, so null-checks are required everywhere.

Edit. Formatting.