3 ms·
I hate that await has made it easy to turn JS in to a synchronous language. I see so much front end code that would be better for users without await, but lots
by onion2k 6y ago
I hate that await has made it easy to turn JS in to a synchronous language. I see so much front end code that would be better for users without await, but lots of developers prefer to write code that's easier to think about rather than fast. It's hugely annoying.
- rectang 6y agoBut very little code has to be fast, right? Best to prioritize making code "easier to think about" and thus more likely correct, then to profile and optimize the bottlenecks.
- nine_k 6y agoAll the code in the UI should better be fast, else the UI drowns in annoying molasses real quick. So no, performance does matter a lot here.
- rectang 6y agoI don't dispute that UI code needs to be fast overall, but it's still the case that only a small proportion of the code needs to be fast in order for the whole thing to be fast. FWIW I worked in the search/database space for a decade and it's the same thing there. There was one time I wrote a lock-free hash table implementation for a registry that needed to be optimized for concurrent access; that code was much harder to write and to understand than the rest of the codebase, but it was justified. Most of the codebase, though, was not performance-critical. EDIT: I will grant that you still need to think about how to architect the project so that it is optimizable later, which can mean thinking about what needs to be async early on.
- onion2k 6y agoNot really. Front end devs should be aiming for a solid 60fps, so you only have about 16ms to do everything you need to do in a frame (less actually because the browser itself needs time as well). If you have interactions, network requests, animation, and calculations all blocking the main thread it'll be a horrible experience for the user. Giving up async and not letting the browser do what it can as soon as possible is just silly.
- rectang 6y agoI feel like there's a disconnect here. I did not suggest "giving up async"; I expect that async will be used when justified — as I described having done myself in a nearby comment. I'm just making a bog-standard argument against premature optimization, and I'm shocked that we can't find common ground.
- spanhandler 6y agoI think sync should always have been the default. Most of the syntax ugliness and screwing-about over the years in JS and especially Node codebases that I’ve seen has been everyone wrestling against that default because they do need their code to be locally synchronous. That it’s technically async at the event loop is mostly something programmers shouldn’t usually need to worry about unless they need to leverage that.