TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Function Colour Myth, Or: async/await is not what you think it is

15 pointsby goranmoominover 3 years ago

5 comments

quotemstrover 3 years ago
The author doesn't deconstruct the idea of function color at all: he just claims it's a good thing because threads are hard. The whole reason people talk about function color in the first place is that it turns out there's no such thing as a free lunch and there's a good reason threads work the way they do.
评论 #28907091 未加载
karmakazeover 3 years ago
The problem isn&#x27;t &#x27;function&#x27; color, it&#x27;s thread vs coroutines.<p>Go doesn&#x27;t have a problem with function color because they are all coroutines and can suspend on any library call.<p>Java doesn&#x27;t have a problem calling or waiting on any function, but it does suffer from thread usage if done too much. This is due to a lack of coroutines.<p>JavaScript&#x2F;Node somehow decided that the main thread isn&#x27;t like all the other coroutines. This is the problem. Make them all coroutines as is done in Go, with the same caveat that if the main one exits the &#x27;program&#x27; ends, so it should await anything it needs to.
dcowover 3 years ago
Isn&#x27;t every function in the world (in non duck-type runtime languages) colored by its return type? Functions have signatures. You can&#x27;t call a function that returns an int and store the value into a variable of type string. Similarly, you can&#x27;t store a future&lt;int&gt; to a variable of type int without yielding execution and (a)waiting for the result to show up in some memory location and then copying that.<p>async&#x2F;await is just syntax that removes boilerplate from some common patterns like returning a future and yielding execution while waiting on its result. You could implement this yourself in every function, but people don&#x27;t want to and find async&#x2F;await convenient. So here we are.<p>Maybe it&#x27;s just me, but the whole function color thing really comes off as &quot;why can&#x27;t I store a string in an int variable? The compiler could call itoa for me why doesn&#x27;t it?&quot;. I mean if that&#x27;s what you want go use a language where the compiler does that for you. We&#x27;re here using types because we care about code correctness and are willing to endure some compile time restrictions to achieve it.
celeritasceleryover 3 years ago
If I understand this argument, colored functions are not a requirement for concurrency, but they are convenient. But I didn’t follow why they are convenient. Is it because they are explicit? What convenience would you loose without colored functions?
JohnHaugelandover 3 years ago
Node isn&#x27;t even async first, this doesn&#x27;t come from c#, etc<p>If you&#x27;re going to argue with someone you really need to know the material