Why don't programming languages automatically manage the synchronous/asynchronous problem? The Next CEO of Stack OverflowWhy is there still case sensitivity in some programming languages?Why don't programming languages separate out style from content?Combining asynchronous and synchronous programmingUse cases and usage patterns of futures vs callbacksLanguage compiled to JS – most elegant way to do synchronous-style waitsSynchronous facade hiding asynchronous web serviceUsing and designing asynchronous APIs with naturally synchronous partsWhy are Promises not “awaited” by default?Design of asynchronous componentWhy do many languages semantically distinguish “async” functions from “non-async” ones?
Anatomically Correct Strange Women In Ponds Distributing Swords
Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis
How to safely derail a train during transit?
Why do airplanes bank sharply to the right after air-to-air refueling?
Would a galaxy be visible from outside, but nearby?
Can we say or write : "No, it'sn't"?
Why do we use the plural of movies in this phrase "We went to the movies last night."?
How to log in to Centos 7 using RDP from Win10
How do scammers retract money, while you can’t?
Beyond letters and diaries—exercises to explore characters' personalities and motivation
Hindi speaking tourist to UK from India
Between two walls
Can I equip Skullclamp on a creature I am sacrificing?
FBX seems to be empty when imported into Blender
Opposite of a diet
Really confused on what inner tube would fit my BF’s new bike?
How did people program for Consoles with multiple CPUs?
Why does standard notation not preserve intervals (visually)
How long to clear the 'suck zone' of a turbofan after start is initiated?
Is there a way to save my career from absolute disaster?
What does "Its cash flow is deeply negative" mean?
How to count occurrences of text in a file?
Is HostGator storing my password in plaintext?
A "random" question: usage of "random" as adjective in Spanish
Why don't programming languages automatically manage the synchronous/asynchronous problem?
The Next CEO of Stack OverflowWhy is there still case sensitivity in some programming languages?Why don't programming languages separate out style from content?Combining asynchronous and synchronous programmingUse cases and usage patterns of futures vs callbacksLanguage compiled to JS – most elegant way to do synchronous-style waitsSynchronous facade hiding asynchronous web serviceUsing and designing asynchronous APIs with naturally synchronous partsWhy are Promises not “awaited” by default?Design of asynchronous componentWhy do many languages semantically distinguish “async” functions from “non-async” ones?
I did not find many resources about this, I was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way.
For example here is a javascript code which retrieves the number of users stored in a database (asynchronous operation):
getNbOfUsers(function (nbOfUsers) console.log(nbOfUsers) );
It would be nice to be able to write something like that:
const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);
And so the compilator would automatically take care of waiting for the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.
Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.
Is it possible? It may be a terrible idea/a utopia... I don't know
programming-languages syntax asynchronous-programming
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
|
show 2 more comments
I did not find many resources about this, I was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way.
For example here is a javascript code which retrieves the number of users stored in a database (asynchronous operation):
getNbOfUsers(function (nbOfUsers) console.log(nbOfUsers) );
It would be nice to be able to write something like that:
const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);
And so the compilator would automatically take care of waiting for the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.
Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.
Is it possible? It may be a terrible idea/a utopia... I don't know
programming-languages syntax asynchronous-programming
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
11
I don't really understand your question. If you "always wait for the asynchronous operation", then it is not an asynchronous operation, it is a synchronous operation. Can you clarify? Maybe give a specification of the type of behavior you are looking for? Also, "what do you think about it" is off-topic on Software Engineering. You need to formulate your question in the context of a concrete problem, that has a single, unambiguous, canonical, objectively correct answer.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I imagine a hypothetical C# that implicitlyawaits aTask<T>to convert it toT
– Caleth
2 hours ago
Are you asking about language support for Transparent Futures? If yes, why do you need language support, why are the currently existing libraries not good enough?
– Jörg W Mittag
2 hours ago
@Caleth I don't know much of C#, in js or swift we have to adopt a particular syntax to manage operations which resolves in the future (i am avoiding the asynchronous term as it seems to create confusions). And this particular syntax is really heavy, so that's why we got promises and later async/await to make it a bit lighter, but still... My question is if it is possible for a programming language to handle the same way the both, as it would make things much more easier for the programmer, code more readable etc.
– Cinn
2 hours ago
Check out coroutines in Kotlin. What you are describing seems similar.
– JimmyJames
2 hours ago
|
show 2 more comments
I did not find many resources about this, I was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way.
For example here is a javascript code which retrieves the number of users stored in a database (asynchronous operation):
getNbOfUsers(function (nbOfUsers) console.log(nbOfUsers) );
It would be nice to be able to write something like that:
const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);
And so the compilator would automatically take care of waiting for the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.
Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.
Is it possible? It may be a terrible idea/a utopia... I don't know
programming-languages syntax asynchronous-programming
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I did not find many resources about this, I was wondering if it's possible/a good idea to be able to write asynchronous code in a synchronous way.
For example here is a javascript code which retrieves the number of users stored in a database (asynchronous operation):
getNbOfUsers(function (nbOfUsers) console.log(nbOfUsers) );
It would be nice to be able to write something like that:
const nbOfUsers = getNbOfUsers();
console.log(getNbOfUsers);
And so the compilator would automatically take care of waiting for the response to then execute console.log. It will always wait for the asynchronous operations to answer before the results have to be used anywhere else. We would use so much less often callbacks, promises, async/await or whatever, and never have to worry if the result of an operation is available immediately or not.
Errors would still be manageable (does nbOfUsers got an integer or an error?) using try/catch, or something like optionals like in Swift language.
Is it possible? It may be a terrible idea/a utopia... I don't know
programming-languages syntax asynchronous-programming
programming-languages syntax asynchronous-programming
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 19 mins ago
les
1033
1033
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 hours ago
CinnCinn
1415
1415
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Cinn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
11
I don't really understand your question. If you "always wait for the asynchronous operation", then it is not an asynchronous operation, it is a synchronous operation. Can you clarify? Maybe give a specification of the type of behavior you are looking for? Also, "what do you think about it" is off-topic on Software Engineering. You need to formulate your question in the context of a concrete problem, that has a single, unambiguous, canonical, objectively correct answer.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I imagine a hypothetical C# that implicitlyawaits aTask<T>to convert it toT
– Caleth
2 hours ago
Are you asking about language support for Transparent Futures? If yes, why do you need language support, why are the currently existing libraries not good enough?
– Jörg W Mittag
2 hours ago
@Caleth I don't know much of C#, in js or swift we have to adopt a particular syntax to manage operations which resolves in the future (i am avoiding the asynchronous term as it seems to create confusions). And this particular syntax is really heavy, so that's why we got promises and later async/await to make it a bit lighter, but still... My question is if it is possible for a programming language to handle the same way the both, as it would make things much more easier for the programmer, code more readable etc.
– Cinn
2 hours ago
Check out coroutines in Kotlin. What you are describing seems similar.
– JimmyJames
2 hours ago
|
show 2 more comments
11
I don't really understand your question. If you "always wait for the asynchronous operation", then it is not an asynchronous operation, it is a synchronous operation. Can you clarify? Maybe give a specification of the type of behavior you are looking for? Also, "what do you think about it" is off-topic on Software Engineering. You need to formulate your question in the context of a concrete problem, that has a single, unambiguous, canonical, objectively correct answer.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I imagine a hypothetical C# that implicitlyawaits aTask<T>to convert it toT
– Caleth
2 hours ago
Are you asking about language support for Transparent Futures? If yes, why do you need language support, why are the currently existing libraries not good enough?
– Jörg W Mittag
2 hours ago
@Caleth I don't know much of C#, in js or swift we have to adopt a particular syntax to manage operations which resolves in the future (i am avoiding the asynchronous term as it seems to create confusions). And this particular syntax is really heavy, so that's why we got promises and later async/await to make it a bit lighter, but still... My question is if it is possible for a programming language to handle the same way the both, as it would make things much more easier for the programmer, code more readable etc.
– Cinn
2 hours ago
Check out coroutines in Kotlin. What you are describing seems similar.
– JimmyJames
2 hours ago
11
11
I don't really understand your question. If you "always wait for the asynchronous operation", then it is not an asynchronous operation, it is a synchronous operation. Can you clarify? Maybe give a specification of the type of behavior you are looking for? Also, "what do you think about it" is off-topic on Software Engineering. You need to formulate your question in the context of a concrete problem, that has a single, unambiguous, canonical, objectively correct answer.
– Jörg W Mittag
2 hours ago
I don't really understand your question. If you "always wait for the asynchronous operation", then it is not an asynchronous operation, it is a synchronous operation. Can you clarify? Maybe give a specification of the type of behavior you are looking for? Also, "what do you think about it" is off-topic on Software Engineering. You need to formulate your question in the context of a concrete problem, that has a single, unambiguous, canonical, objectively correct answer.
– Jörg W Mittag
2 hours ago
1
1
@JörgWMittag I imagine a hypothetical C# that implicitly
awaits a Task<T> to convert it to T– Caleth
2 hours ago
@JörgWMittag I imagine a hypothetical C# that implicitly
awaits a Task<T> to convert it to T– Caleth
2 hours ago
Are you asking about language support for Transparent Futures? If yes, why do you need language support, why are the currently existing libraries not good enough?
– Jörg W Mittag
2 hours ago
Are you asking about language support for Transparent Futures? If yes, why do you need language support, why are the currently existing libraries not good enough?
– Jörg W Mittag
2 hours ago
@Caleth I don't know much of C#, in js or swift we have to adopt a particular syntax to manage operations which resolves in the future (i am avoiding the asynchronous term as it seems to create confusions). And this particular syntax is really heavy, so that's why we got promises and later async/await to make it a bit lighter, but still... My question is if it is possible for a programming language to handle the same way the both, as it would make things much more easier for the programmer, code more readable etc.
– Cinn
2 hours ago
@Caleth I don't know much of C#, in js or swift we have to adopt a particular syntax to manage operations which resolves in the future (i am avoiding the asynchronous term as it seems to create confusions). And this particular syntax is really heavy, so that's why we got promises and later async/await to make it a bit lighter, but still... My question is if it is possible for a programming language to handle the same way the both, as it would make things much more easier for the programmer, code more readable etc.
– Cinn
2 hours ago
Check out coroutines in Kotlin. What you are describing seems similar.
– JimmyJames
2 hours ago
Check out coroutines in Kotlin. What you are describing seems similar.
– JimmyJames
2 hours ago
|
show 2 more comments
7 Answers
7
active
oldest
votes
Async/await is exactly that automated management that you propose, albeit with two extra keywords. Why are they important? Aside from backwards compatibility?
Without explicit points where a coroutine may be suspended and resumed, we would need a type system to detect where an awaitable value must be awaited. Many programming languages do not have such a type system.
By making awaiting a value explicit, we can also pass awaitable values around as first class objects: promises. This can be super useful when writing higher-order code.
Async code has very deep effects for the execution model of a language, similar to the absence or presence of exceptions in the language. In particular, an async function can only be awaited by async functions. This affects all calling functions! But what if we change a function from non-async to async at the end of this dependency chain? This would be a backwards-incompatible change … unless all functions are async and every function call is awaited by default.
And that is highly undesirable because it has very bad performance implications. You wouldn't be able to simply return cheap values. Every function call would become a lot more expensive.
Async is great, but some kind of implicit async won't work in reality.
Pure functional languages like Haskell have a bit of an escape hatch because execution order is largely unspecified and unobservable. Or phrased differently: any specific order of operations must be explicitly encoded. That can be rather cumbersome for real-world programs, especially those I/O-heavy programs for which async code is a very good fit.
1
You don't necessarily need a type system. Transparent Futures in e.g. ECMAScript, Smalltalk, Self, Newspeak, Io, Ioke, Seph, can be easily implemented without tyoe system or language support. In Smalltalk and its descendants, an object can transparently change its identity, in ECMAScript, it can transparently change its shape. That is all you need to make Futures transparent, no need for language support for asynchrony.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I understand what you're saying and how that could work, but transparent futures without a type system make it rather difficult to simultaneously have first class futures, no? I would need some way to select whether I want to send messages to the future or the future's value, preferably something better thansomeValue ifItIsAFuture [self| self messageIWantToSend]because that's tricky to integrate with generic code.
– amon
1 hour ago
Haskell is a pretty good imperative language. In my opinion, explicit state and IO is not cumbersome but elegant.
– les
21 mins ago
add a comment |
Some do.
They're not mainstream (yet) because async is a relatively new feature that we've only just now gotten a good feel for if it's even a good feature, or how to present it to programmers in a way that is friendly/usable/expressive/etc. Existing async features are largely bolted onto existing languages, which require a little different design approach.
That said, it's not clearly a good idea to do everywhere. A common failing is doing async calls in a loop, effectively serializing their execution. Having asynchronous calls be implicit may obscure that sort of error. Also, if you support implicit coercion from a Task<T> (or your language's equivalent) to T, that can add a bit of complexity/cost to your typechecker and error reporting when it's unclear which of the two the programmer really wanted.
But those are not insurmountable problems. If you wanted to support that behavior you almost certainly could, though there would be trade-offs.
I think an idea could be to wrap everything in async functions, the synchronous tasks would just resolve immediatly and we get all a one kind to handle (Edit: @amon explained why it's a bad idea...)
– Cinn
2 hours ago
add a comment |
There are languages that do this. But, there is actually not much of a need, since it can be easily accomplished with existing language features.
As long as you have some way of expressing asynchrony, you can implement Futures or Promises purely as a library feature, you don't need any special language features. And as long as you have some of expressing Transparent Proxies, you can put the two features together and you have Transparent Futures.
For example, in Smalltalk and its descendants, an object can change its identity, it can literally "become" a different object (and in fact the method that does this is called Object>>become:).
Imagine a long-running computation that returns a Future<Int>. This Future<Int> has all the same methods as Int, except with different implementations. Future<Int>'s + method does not add another number and return the result, it returns a new Future<Int> which wraps the computation. And so on, and so forth. Methods that cannot sensibly be implemented by returning a Future<Int>, will instead automatically await the result, and then call self become: result., which will make the currently executing object (self, i.e. the Future<Int>) literally become the result object, i.e. from now on the object reference that used to be a Future<Int> is now an Int everywhere, completely transparent to the client.
No special asynchrony-related language features needed.
Ok, but that has problems if bothFuture<T>andTshare some common interface and I use functionality from that interface. Should itbecomethe result and then use the functionality, or not? I'm thinking of things like an equality operator or a to-string debugging representation.
– amon
1 hour ago
I understand that it does not add any features, the thing is we have different syntaxes to write immediately resolving computations and long-running computations, and after that we would use the results the same way for other purposes. I was wondering if we could have a syntax that transparently handle the both, making it more readable and so the programmer does not have to handle it. Like doinga + b, both integers, no matters if a and b are available immediately or later, we just writea + b(making possible to doInt + Future<Int>)
– Cinn
1 hour ago
@Cinn: Yes, you can do that with Transparent Futures, and you don't need any special language features to do that. You can implement it using the already existing features in e.g. Smalltalk, Self, Newspeak, Us, Korz, Io, Ioke, Seph, ECMAScript, and apparently, as I just read, Python.
– Jörg W Mittag
1 hour ago
3
@amon: The idea of Transparent Futures is that you don't know it's a future. From your point of view, there is no common interface betweenFuture<T>andTbecause from your point of view, there is noFuture<T>, only aT. Now, there is of course lots of engineering challenges around how to make this efficient, which operations should be blocking vs. non-blocking, etc., but that is really independent of whether you do it as a language or as a library feature. Transparency was a requirement stipulated by the OP in the question, I won't argue that it is hard and might not make sense.
– Jörg W Mittag
1 hour ago
add a comment |
If i'm reading you right you are asking for a synchronous programming model but a high performance implementation. If that is correct than that is already available to us in the form of green threads or processes of e.g. Erlang or Haskell. So yes, it's an excellent idea, but the retrofitting to existing languages can't always be as smooth as you would like.
add a comment |
What you are missing, is the purpose of async operations: They allow you to make use of your waiting time!
If you turn an async operation, like requesting some resource from a server, into a synchronous operation by implicitly and immediately waiting for the reply, your thread cannot do anything else with the waiting time. If the server takes 10 milliseconds to respond, there go about 30 million CPU cycles to the waste. The latency of the response becomes the execution time for the request.
The only reason why programmers invented async operations, is to hide the latency of inherently long-running tasks behind other useful computations. If you can fill the waiting time with useful work, that's CPU time saved. If you can't, well, nothing's lost by the operation being async.
So, I recommend to embrace the async operations that your languages provide to you. They are there to save you time.
i was thinking of a functional language where operations are not blocking, so even if it has a synchronous syntax, a long-running computation will not block the thread
– Cinn
7 mins ago
add a comment |
The problem you're describing is two-fold.
- The program you're writing should behave asynchronously as a whole when viewed from the outside.
- It should not be visible at the call site whether a function call potentially gives up control or not.
There are a couple of ways to achieve this, but they basically boil down to
- having multiple threads (at some level of abstraction)
- having multiple kinds of function at the language level, all of which are called like this
foo(4, 7, bar, quux).
For (1), I'm lumping together forking and running multiple processes, spawning multiple kernel threads, and green thread implementations that schedule language-runtime level threads onto kernel threads. From the perspective of the problem, they are the same. In this world, no function ever gives up or loses control from the perspective of its thread. The thread itself sometimes doesn't have control and sometimes isn't running but you don't give up control of your own thread in this world. A system fitting this model may or may not have the ability to spawn new threads or join on existing threads. A system fitting this model may or may not have the ability to duplicate a thread like Unix's fork.
(2) is interesting. In order to do it justice we need to talk about introduction and elimination forms.
I'm going to show why implicit await cannot be added to a language like Javascript in a backwards-compatible way. The basic idea is that by exposing promises to the user and having a distinction between synchronous and asynchronous contexts, Javascript has leaked an implementation detail that prevents handling synchronous and asynchronous functions uniformly. There's also the fact that you can't await a promise outside of an async function body. These design choices are incompatible with "making asynchronousness invisible to the caller".
You can introduce a synchronous function using a lambda and eliminate it with a function call.
Synchronous function introduction:
((x) => return x + x;)
Synchronous function elimination:
f(4)
((x) => return x + x;)(4)
You can contrast this with asynchronous function introduction and elimination.
Asynchronous function introduction
(async (x) => return x + x;)
Asynchonrous function elimination (note: only valid inside an async function)
await (async (x) => return x + x;)(4)
The fundamental problem here is that an asynchronous function is also a synchronous function producing a promise object.
Here's an example of calling an asynchronous function synchronously in the node.js repl.
> (async (x) => return x + x;)(4)
Promise 8
You can hypothetically have a language, even a dynamically typed one, where the difference between asynchronous and synchronous function calls is not visible at the call site and possibly is not visible at the definition site.
Taking a language like that and lowering it to Javascript is possible, you'd just have to effectively make all functions asynchronous.
add a comment |
This is available in C++ as std::async since C++11.
The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call.
And with C++20 coroutines can be used:
https://www.modernescpp.com/index.php/coroutines- https://lewissbaker.github.io/2017/11/17/understanding-operator-co-await
This doesn't seem to answer the question. According to your link: "What does the Coroutines TS give us? Three new language keywords: co_await, co_yield and co_return"... But the question is why do we need anawait(orco_awaitin this case) keyword in the first place?
– Arturo Torres Sánchez
11 mins ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "131"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: false,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Cinn is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f389445%2fwhy-dont-programming-languages-automatically-manage-the-synchronous-asynchronou%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
StackExchange.ready(function ()
$("#show-editor-button input, #show-editor-button button").click(function ()
var showEditor = function()
$("#show-editor-button").hide();
$("#post-form").removeClass("dno");
StackExchange.editor.finallyInit();
;
var useFancy = $(this).data('confirm-use-fancy');
if(useFancy == 'True')
var popupTitle = $(this).data('confirm-fancy-title');
var popupBody = $(this).data('confirm-fancy-body');
var popupAccept = $(this).data('confirm-fancy-accept-button');
$(this).loadPopup(
url: '/post/self-answer-popup',
loaded: function(popup)
var pTitle = $(popup).find('h2');
var pBody = $(popup).find('.popup-body');
var pSubmit = $(popup).find('.popup-submit');
pTitle.text(popupTitle);
pBody.html(popupBody);
pSubmit.val(popupAccept).click(showEditor);
)
else
var confirmText = $(this).data('confirm-text');
if (confirmText ? confirm(confirmText) : true)
showEditor();
);
);
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
Async/await is exactly that automated management that you propose, albeit with two extra keywords. Why are they important? Aside from backwards compatibility?
Without explicit points where a coroutine may be suspended and resumed, we would need a type system to detect where an awaitable value must be awaited. Many programming languages do not have such a type system.
By making awaiting a value explicit, we can also pass awaitable values around as first class objects: promises. This can be super useful when writing higher-order code.
Async code has very deep effects for the execution model of a language, similar to the absence or presence of exceptions in the language. In particular, an async function can only be awaited by async functions. This affects all calling functions! But what if we change a function from non-async to async at the end of this dependency chain? This would be a backwards-incompatible change … unless all functions are async and every function call is awaited by default.
And that is highly undesirable because it has very bad performance implications. You wouldn't be able to simply return cheap values. Every function call would become a lot more expensive.
Async is great, but some kind of implicit async won't work in reality.
Pure functional languages like Haskell have a bit of an escape hatch because execution order is largely unspecified and unobservable. Or phrased differently: any specific order of operations must be explicitly encoded. That can be rather cumbersome for real-world programs, especially those I/O-heavy programs for which async code is a very good fit.
1
You don't necessarily need a type system. Transparent Futures in e.g. ECMAScript, Smalltalk, Self, Newspeak, Io, Ioke, Seph, can be easily implemented without tyoe system or language support. In Smalltalk and its descendants, an object can transparently change its identity, in ECMAScript, it can transparently change its shape. That is all you need to make Futures transparent, no need for language support for asynchrony.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I understand what you're saying and how that could work, but transparent futures without a type system make it rather difficult to simultaneously have first class futures, no? I would need some way to select whether I want to send messages to the future or the future's value, preferably something better thansomeValue ifItIsAFuture [self| self messageIWantToSend]because that's tricky to integrate with generic code.
– amon
1 hour ago
Haskell is a pretty good imperative language. In my opinion, explicit state and IO is not cumbersome but elegant.
– les
21 mins ago
add a comment |
Async/await is exactly that automated management that you propose, albeit with two extra keywords. Why are they important? Aside from backwards compatibility?
Without explicit points where a coroutine may be suspended and resumed, we would need a type system to detect where an awaitable value must be awaited. Many programming languages do not have such a type system.
By making awaiting a value explicit, we can also pass awaitable values around as first class objects: promises. This can be super useful when writing higher-order code.
Async code has very deep effects for the execution model of a language, similar to the absence or presence of exceptions in the language. In particular, an async function can only be awaited by async functions. This affects all calling functions! But what if we change a function from non-async to async at the end of this dependency chain? This would be a backwards-incompatible change … unless all functions are async and every function call is awaited by default.
And that is highly undesirable because it has very bad performance implications. You wouldn't be able to simply return cheap values. Every function call would become a lot more expensive.
Async is great, but some kind of implicit async won't work in reality.
Pure functional languages like Haskell have a bit of an escape hatch because execution order is largely unspecified and unobservable. Or phrased differently: any specific order of operations must be explicitly encoded. That can be rather cumbersome for real-world programs, especially those I/O-heavy programs for which async code is a very good fit.
1
You don't necessarily need a type system. Transparent Futures in e.g. ECMAScript, Smalltalk, Self, Newspeak, Io, Ioke, Seph, can be easily implemented without tyoe system or language support. In Smalltalk and its descendants, an object can transparently change its identity, in ECMAScript, it can transparently change its shape. That is all you need to make Futures transparent, no need for language support for asynchrony.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I understand what you're saying and how that could work, but transparent futures without a type system make it rather difficult to simultaneously have first class futures, no? I would need some way to select whether I want to send messages to the future or the future's value, preferably something better thansomeValue ifItIsAFuture [self| self messageIWantToSend]because that's tricky to integrate with generic code.
– amon
1 hour ago
Haskell is a pretty good imperative language. In my opinion, explicit state and IO is not cumbersome but elegant.
– les
21 mins ago
add a comment |
Async/await is exactly that automated management that you propose, albeit with two extra keywords. Why are they important? Aside from backwards compatibility?
Without explicit points where a coroutine may be suspended and resumed, we would need a type system to detect where an awaitable value must be awaited. Many programming languages do not have such a type system.
By making awaiting a value explicit, we can also pass awaitable values around as first class objects: promises. This can be super useful when writing higher-order code.
Async code has very deep effects for the execution model of a language, similar to the absence or presence of exceptions in the language. In particular, an async function can only be awaited by async functions. This affects all calling functions! But what if we change a function from non-async to async at the end of this dependency chain? This would be a backwards-incompatible change … unless all functions are async and every function call is awaited by default.
And that is highly undesirable because it has very bad performance implications. You wouldn't be able to simply return cheap values. Every function call would become a lot more expensive.
Async is great, but some kind of implicit async won't work in reality.
Pure functional languages like Haskell have a bit of an escape hatch because execution order is largely unspecified and unobservable. Or phrased differently: any specific order of operations must be explicitly encoded. That can be rather cumbersome for real-world programs, especially those I/O-heavy programs for which async code is a very good fit.
Async/await is exactly that automated management that you propose, albeit with two extra keywords. Why are they important? Aside from backwards compatibility?
Without explicit points where a coroutine may be suspended and resumed, we would need a type system to detect where an awaitable value must be awaited. Many programming languages do not have such a type system.
By making awaiting a value explicit, we can also pass awaitable values around as first class objects: promises. This can be super useful when writing higher-order code.
Async code has very deep effects for the execution model of a language, similar to the absence or presence of exceptions in the language. In particular, an async function can only be awaited by async functions. This affects all calling functions! But what if we change a function from non-async to async at the end of this dependency chain? This would be a backwards-incompatible change … unless all functions are async and every function call is awaited by default.
And that is highly undesirable because it has very bad performance implications. You wouldn't be able to simply return cheap values. Every function call would become a lot more expensive.
Async is great, but some kind of implicit async won't work in reality.
Pure functional languages like Haskell have a bit of an escape hatch because execution order is largely unspecified and unobservable. Or phrased differently: any specific order of operations must be explicitly encoded. That can be rather cumbersome for real-world programs, especially those I/O-heavy programs for which async code is a very good fit.
answered 2 hours ago
amonamon
89.6k21170262
89.6k21170262
1
You don't necessarily need a type system. Transparent Futures in e.g. ECMAScript, Smalltalk, Self, Newspeak, Io, Ioke, Seph, can be easily implemented without tyoe system or language support. In Smalltalk and its descendants, an object can transparently change its identity, in ECMAScript, it can transparently change its shape. That is all you need to make Futures transparent, no need for language support for asynchrony.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I understand what you're saying and how that could work, but transparent futures without a type system make it rather difficult to simultaneously have first class futures, no? I would need some way to select whether I want to send messages to the future or the future's value, preferably something better thansomeValue ifItIsAFuture [self| self messageIWantToSend]because that's tricky to integrate with generic code.
– amon
1 hour ago
Haskell is a pretty good imperative language. In my opinion, explicit state and IO is not cumbersome but elegant.
– les
21 mins ago
add a comment |
1
You don't necessarily need a type system. Transparent Futures in e.g. ECMAScript, Smalltalk, Self, Newspeak, Io, Ioke, Seph, can be easily implemented without tyoe system or language support. In Smalltalk and its descendants, an object can transparently change its identity, in ECMAScript, it can transparently change its shape. That is all you need to make Futures transparent, no need for language support for asynchrony.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I understand what you're saying and how that could work, but transparent futures without a type system make it rather difficult to simultaneously have first class futures, no? I would need some way to select whether I want to send messages to the future or the future's value, preferably something better thansomeValue ifItIsAFuture [self| self messageIWantToSend]because that's tricky to integrate with generic code.
– amon
1 hour ago
Haskell is a pretty good imperative language. In my opinion, explicit state and IO is not cumbersome but elegant.
– les
21 mins ago
1
1
You don't necessarily need a type system. Transparent Futures in e.g. ECMAScript, Smalltalk, Self, Newspeak, Io, Ioke, Seph, can be easily implemented without tyoe system or language support. In Smalltalk and its descendants, an object can transparently change its identity, in ECMAScript, it can transparently change its shape. That is all you need to make Futures transparent, no need for language support for asynchrony.
– Jörg W Mittag
2 hours ago
You don't necessarily need a type system. Transparent Futures in e.g. ECMAScript, Smalltalk, Self, Newspeak, Io, Ioke, Seph, can be easily implemented without tyoe system or language support. In Smalltalk and its descendants, an object can transparently change its identity, in ECMAScript, it can transparently change its shape. That is all you need to make Futures transparent, no need for language support for asynchrony.
– Jörg W Mittag
2 hours ago
1
1
@JörgWMittag I understand what you're saying and how that could work, but transparent futures without a type system make it rather difficult to simultaneously have first class futures, no? I would need some way to select whether I want to send messages to the future or the future's value, preferably something better than
someValue ifItIsAFuture [self| self messageIWantToSend] because that's tricky to integrate with generic code.– amon
1 hour ago
@JörgWMittag I understand what you're saying and how that could work, but transparent futures without a type system make it rather difficult to simultaneously have first class futures, no? I would need some way to select whether I want to send messages to the future or the future's value, preferably something better than
someValue ifItIsAFuture [self| self messageIWantToSend] because that's tricky to integrate with generic code.– amon
1 hour ago
Haskell is a pretty good imperative language. In my opinion, explicit state and IO is not cumbersome but elegant.
– les
21 mins ago
Haskell is a pretty good imperative language. In my opinion, explicit state and IO is not cumbersome but elegant.
– les
21 mins ago
add a comment |
Some do.
They're not mainstream (yet) because async is a relatively new feature that we've only just now gotten a good feel for if it's even a good feature, or how to present it to programmers in a way that is friendly/usable/expressive/etc. Existing async features are largely bolted onto existing languages, which require a little different design approach.
That said, it's not clearly a good idea to do everywhere. A common failing is doing async calls in a loop, effectively serializing their execution. Having asynchronous calls be implicit may obscure that sort of error. Also, if you support implicit coercion from a Task<T> (or your language's equivalent) to T, that can add a bit of complexity/cost to your typechecker and error reporting when it's unclear which of the two the programmer really wanted.
But those are not insurmountable problems. If you wanted to support that behavior you almost certainly could, though there would be trade-offs.
I think an idea could be to wrap everything in async functions, the synchronous tasks would just resolve immediatly and we get all a one kind to handle (Edit: @amon explained why it's a bad idea...)
– Cinn
2 hours ago
add a comment |
Some do.
They're not mainstream (yet) because async is a relatively new feature that we've only just now gotten a good feel for if it's even a good feature, or how to present it to programmers in a way that is friendly/usable/expressive/etc. Existing async features are largely bolted onto existing languages, which require a little different design approach.
That said, it's not clearly a good idea to do everywhere. A common failing is doing async calls in a loop, effectively serializing their execution. Having asynchronous calls be implicit may obscure that sort of error. Also, if you support implicit coercion from a Task<T> (or your language's equivalent) to T, that can add a bit of complexity/cost to your typechecker and error reporting when it's unclear which of the two the programmer really wanted.
But those are not insurmountable problems. If you wanted to support that behavior you almost certainly could, though there would be trade-offs.
I think an idea could be to wrap everything in async functions, the synchronous tasks would just resolve immediatly and we get all a one kind to handle (Edit: @amon explained why it's a bad idea...)
– Cinn
2 hours ago
add a comment |
Some do.
They're not mainstream (yet) because async is a relatively new feature that we've only just now gotten a good feel for if it's even a good feature, or how to present it to programmers in a way that is friendly/usable/expressive/etc. Existing async features are largely bolted onto existing languages, which require a little different design approach.
That said, it's not clearly a good idea to do everywhere. A common failing is doing async calls in a loop, effectively serializing their execution. Having asynchronous calls be implicit may obscure that sort of error. Also, if you support implicit coercion from a Task<T> (or your language's equivalent) to T, that can add a bit of complexity/cost to your typechecker and error reporting when it's unclear which of the two the programmer really wanted.
But those are not insurmountable problems. If you wanted to support that behavior you almost certainly could, though there would be trade-offs.
Some do.
They're not mainstream (yet) because async is a relatively new feature that we've only just now gotten a good feel for if it's even a good feature, or how to present it to programmers in a way that is friendly/usable/expressive/etc. Existing async features are largely bolted onto existing languages, which require a little different design approach.
That said, it's not clearly a good idea to do everywhere. A common failing is doing async calls in a loop, effectively serializing their execution. Having asynchronous calls be implicit may obscure that sort of error. Also, if you support implicit coercion from a Task<T> (or your language's equivalent) to T, that can add a bit of complexity/cost to your typechecker and error reporting when it's unclear which of the two the programmer really wanted.
But those are not insurmountable problems. If you wanted to support that behavior you almost certainly could, though there would be trade-offs.
answered 2 hours ago
TelastynTelastyn
93.8k26210323
93.8k26210323
I think an idea could be to wrap everything in async functions, the synchronous tasks would just resolve immediatly and we get all a one kind to handle (Edit: @amon explained why it's a bad idea...)
– Cinn
2 hours ago
add a comment |
I think an idea could be to wrap everything in async functions, the synchronous tasks would just resolve immediatly and we get all a one kind to handle (Edit: @amon explained why it's a bad idea...)
– Cinn
2 hours ago
I think an idea could be to wrap everything in async functions, the synchronous tasks would just resolve immediatly and we get all a one kind to handle (Edit: @amon explained why it's a bad idea...)
– Cinn
2 hours ago
I think an idea could be to wrap everything in async functions, the synchronous tasks would just resolve immediatly and we get all a one kind to handle (Edit: @amon explained why it's a bad idea...)
– Cinn
2 hours ago
add a comment |
There are languages that do this. But, there is actually not much of a need, since it can be easily accomplished with existing language features.
As long as you have some way of expressing asynchrony, you can implement Futures or Promises purely as a library feature, you don't need any special language features. And as long as you have some of expressing Transparent Proxies, you can put the two features together and you have Transparent Futures.
For example, in Smalltalk and its descendants, an object can change its identity, it can literally "become" a different object (and in fact the method that does this is called Object>>become:).
Imagine a long-running computation that returns a Future<Int>. This Future<Int> has all the same methods as Int, except with different implementations. Future<Int>'s + method does not add another number and return the result, it returns a new Future<Int> which wraps the computation. And so on, and so forth. Methods that cannot sensibly be implemented by returning a Future<Int>, will instead automatically await the result, and then call self become: result., which will make the currently executing object (self, i.e. the Future<Int>) literally become the result object, i.e. from now on the object reference that used to be a Future<Int> is now an Int everywhere, completely transparent to the client.
No special asynchrony-related language features needed.
Ok, but that has problems if bothFuture<T>andTshare some common interface and I use functionality from that interface. Should itbecomethe result and then use the functionality, or not? I'm thinking of things like an equality operator or a to-string debugging representation.
– amon
1 hour ago
I understand that it does not add any features, the thing is we have different syntaxes to write immediately resolving computations and long-running computations, and after that we would use the results the same way for other purposes. I was wondering if we could have a syntax that transparently handle the both, making it more readable and so the programmer does not have to handle it. Like doinga + b, both integers, no matters if a and b are available immediately or later, we just writea + b(making possible to doInt + Future<Int>)
– Cinn
1 hour ago
@Cinn: Yes, you can do that with Transparent Futures, and you don't need any special language features to do that. You can implement it using the already existing features in e.g. Smalltalk, Self, Newspeak, Us, Korz, Io, Ioke, Seph, ECMAScript, and apparently, as I just read, Python.
– Jörg W Mittag
1 hour ago
3
@amon: The idea of Transparent Futures is that you don't know it's a future. From your point of view, there is no common interface betweenFuture<T>andTbecause from your point of view, there is noFuture<T>, only aT. Now, there is of course lots of engineering challenges around how to make this efficient, which operations should be blocking vs. non-blocking, etc., but that is really independent of whether you do it as a language or as a library feature. Transparency was a requirement stipulated by the OP in the question, I won't argue that it is hard and might not make sense.
– Jörg W Mittag
1 hour ago
add a comment |
There are languages that do this. But, there is actually not much of a need, since it can be easily accomplished with existing language features.
As long as you have some way of expressing asynchrony, you can implement Futures or Promises purely as a library feature, you don't need any special language features. And as long as you have some of expressing Transparent Proxies, you can put the two features together and you have Transparent Futures.
For example, in Smalltalk and its descendants, an object can change its identity, it can literally "become" a different object (and in fact the method that does this is called Object>>become:).
Imagine a long-running computation that returns a Future<Int>. This Future<Int> has all the same methods as Int, except with different implementations. Future<Int>'s + method does not add another number and return the result, it returns a new Future<Int> which wraps the computation. And so on, and so forth. Methods that cannot sensibly be implemented by returning a Future<Int>, will instead automatically await the result, and then call self become: result., which will make the currently executing object (self, i.e. the Future<Int>) literally become the result object, i.e. from now on the object reference that used to be a Future<Int> is now an Int everywhere, completely transparent to the client.
No special asynchrony-related language features needed.
Ok, but that has problems if bothFuture<T>andTshare some common interface and I use functionality from that interface. Should itbecomethe result and then use the functionality, or not? I'm thinking of things like an equality operator or a to-string debugging representation.
– amon
1 hour ago
I understand that it does not add any features, the thing is we have different syntaxes to write immediately resolving computations and long-running computations, and after that we would use the results the same way for other purposes. I was wondering if we could have a syntax that transparently handle the both, making it more readable and so the programmer does not have to handle it. Like doinga + b, both integers, no matters if a and b are available immediately or later, we just writea + b(making possible to doInt + Future<Int>)
– Cinn
1 hour ago
@Cinn: Yes, you can do that with Transparent Futures, and you don't need any special language features to do that. You can implement it using the already existing features in e.g. Smalltalk, Self, Newspeak, Us, Korz, Io, Ioke, Seph, ECMAScript, and apparently, as I just read, Python.
– Jörg W Mittag
1 hour ago
3
@amon: The idea of Transparent Futures is that you don't know it's a future. From your point of view, there is no common interface betweenFuture<T>andTbecause from your point of view, there is noFuture<T>, only aT. Now, there is of course lots of engineering challenges around how to make this efficient, which operations should be blocking vs. non-blocking, etc., but that is really independent of whether you do it as a language or as a library feature. Transparency was a requirement stipulated by the OP in the question, I won't argue that it is hard and might not make sense.
– Jörg W Mittag
1 hour ago
add a comment |
There are languages that do this. But, there is actually not much of a need, since it can be easily accomplished with existing language features.
As long as you have some way of expressing asynchrony, you can implement Futures or Promises purely as a library feature, you don't need any special language features. And as long as you have some of expressing Transparent Proxies, you can put the two features together and you have Transparent Futures.
For example, in Smalltalk and its descendants, an object can change its identity, it can literally "become" a different object (and in fact the method that does this is called Object>>become:).
Imagine a long-running computation that returns a Future<Int>. This Future<Int> has all the same methods as Int, except with different implementations. Future<Int>'s + method does not add another number and return the result, it returns a new Future<Int> which wraps the computation. And so on, and so forth. Methods that cannot sensibly be implemented by returning a Future<Int>, will instead automatically await the result, and then call self become: result., which will make the currently executing object (self, i.e. the Future<Int>) literally become the result object, i.e. from now on the object reference that used to be a Future<Int> is now an Int everywhere, completely transparent to the client.
No special asynchrony-related language features needed.
There are languages that do this. But, there is actually not much of a need, since it can be easily accomplished with existing language features.
As long as you have some way of expressing asynchrony, you can implement Futures or Promises purely as a library feature, you don't need any special language features. And as long as you have some of expressing Transparent Proxies, you can put the two features together and you have Transparent Futures.
For example, in Smalltalk and its descendants, an object can change its identity, it can literally "become" a different object (and in fact the method that does this is called Object>>become:).
Imagine a long-running computation that returns a Future<Int>. This Future<Int> has all the same methods as Int, except with different implementations. Future<Int>'s + method does not add another number and return the result, it returns a new Future<Int> which wraps the computation. And so on, and so forth. Methods that cannot sensibly be implemented by returning a Future<Int>, will instead automatically await the result, and then call self become: result., which will make the currently executing object (self, i.e. the Future<Int>) literally become the result object, i.e. from now on the object reference that used to be a Future<Int> is now an Int everywhere, completely transparent to the client.
No special asynchrony-related language features needed.
answered 1 hour ago
Jörg W MittagJörg W Mittag
69.3k14143227
69.3k14143227
Ok, but that has problems if bothFuture<T>andTshare some common interface and I use functionality from that interface. Should itbecomethe result and then use the functionality, or not? I'm thinking of things like an equality operator or a to-string debugging representation.
– amon
1 hour ago
I understand that it does not add any features, the thing is we have different syntaxes to write immediately resolving computations and long-running computations, and after that we would use the results the same way for other purposes. I was wondering if we could have a syntax that transparently handle the both, making it more readable and so the programmer does not have to handle it. Like doinga + b, both integers, no matters if a and b are available immediately or later, we just writea + b(making possible to doInt + Future<Int>)
– Cinn
1 hour ago
@Cinn: Yes, you can do that with Transparent Futures, and you don't need any special language features to do that. You can implement it using the already existing features in e.g. Smalltalk, Self, Newspeak, Us, Korz, Io, Ioke, Seph, ECMAScript, and apparently, as I just read, Python.
– Jörg W Mittag
1 hour ago
3
@amon: The idea of Transparent Futures is that you don't know it's a future. From your point of view, there is no common interface betweenFuture<T>andTbecause from your point of view, there is noFuture<T>, only aT. Now, there is of course lots of engineering challenges around how to make this efficient, which operations should be blocking vs. non-blocking, etc., but that is really independent of whether you do it as a language or as a library feature. Transparency was a requirement stipulated by the OP in the question, I won't argue that it is hard and might not make sense.
– Jörg W Mittag
1 hour ago
add a comment |
Ok, but that has problems if bothFuture<T>andTshare some common interface and I use functionality from that interface. Should itbecomethe result and then use the functionality, or not? I'm thinking of things like an equality operator or a to-string debugging representation.
– amon
1 hour ago
I understand that it does not add any features, the thing is we have different syntaxes to write immediately resolving computations and long-running computations, and after that we would use the results the same way for other purposes. I was wondering if we could have a syntax that transparently handle the both, making it more readable and so the programmer does not have to handle it. Like doinga + b, both integers, no matters if a and b are available immediately or later, we just writea + b(making possible to doInt + Future<Int>)
– Cinn
1 hour ago
@Cinn: Yes, you can do that with Transparent Futures, and you don't need any special language features to do that. You can implement it using the already existing features in e.g. Smalltalk, Self, Newspeak, Us, Korz, Io, Ioke, Seph, ECMAScript, and apparently, as I just read, Python.
– Jörg W Mittag
1 hour ago
3
@amon: The idea of Transparent Futures is that you don't know it's a future. From your point of view, there is no common interface betweenFuture<T>andTbecause from your point of view, there is noFuture<T>, only aT. Now, there is of course lots of engineering challenges around how to make this efficient, which operations should be blocking vs. non-blocking, etc., but that is really independent of whether you do it as a language or as a library feature. Transparency was a requirement stipulated by the OP in the question, I won't argue that it is hard and might not make sense.
– Jörg W Mittag
1 hour ago
Ok, but that has problems if both
Future<T> and T share some common interface and I use functionality from that interface. Should it become the result and then use the functionality, or not? I'm thinking of things like an equality operator or a to-string debugging representation.– amon
1 hour ago
Ok, but that has problems if both
Future<T> and T share some common interface and I use functionality from that interface. Should it become the result and then use the functionality, or not? I'm thinking of things like an equality operator or a to-string debugging representation.– amon
1 hour ago
I understand that it does not add any features, the thing is we have different syntaxes to write immediately resolving computations and long-running computations, and after that we would use the results the same way for other purposes. I was wondering if we could have a syntax that transparently handle the both, making it more readable and so the programmer does not have to handle it. Like doing
a + b, both integers, no matters if a and b are available immediately or later, we just write a + b (making possible to do Int + Future<Int>)– Cinn
1 hour ago
I understand that it does not add any features, the thing is we have different syntaxes to write immediately resolving computations and long-running computations, and after that we would use the results the same way for other purposes. I was wondering if we could have a syntax that transparently handle the both, making it more readable and so the programmer does not have to handle it. Like doing
a + b, both integers, no matters if a and b are available immediately or later, we just write a + b (making possible to do Int + Future<Int>)– Cinn
1 hour ago
@Cinn: Yes, you can do that with Transparent Futures, and you don't need any special language features to do that. You can implement it using the already existing features in e.g. Smalltalk, Self, Newspeak, Us, Korz, Io, Ioke, Seph, ECMAScript, and apparently, as I just read, Python.
– Jörg W Mittag
1 hour ago
@Cinn: Yes, you can do that with Transparent Futures, and you don't need any special language features to do that. You can implement it using the already existing features in e.g. Smalltalk, Self, Newspeak, Us, Korz, Io, Ioke, Seph, ECMAScript, and apparently, as I just read, Python.
– Jörg W Mittag
1 hour ago
3
3
@amon: The idea of Transparent Futures is that you don't know it's a future. From your point of view, there is no common interface between
Future<T> and T because from your point of view, there is no Future<T>, only a T. Now, there is of course lots of engineering challenges around how to make this efficient, which operations should be blocking vs. non-blocking, etc., but that is really independent of whether you do it as a language or as a library feature. Transparency was a requirement stipulated by the OP in the question, I won't argue that it is hard and might not make sense.– Jörg W Mittag
1 hour ago
@amon: The idea of Transparent Futures is that you don't know it's a future. From your point of view, there is no common interface between
Future<T> and T because from your point of view, there is no Future<T>, only a T. Now, there is of course lots of engineering challenges around how to make this efficient, which operations should be blocking vs. non-blocking, etc., but that is really independent of whether you do it as a language or as a library feature. Transparency was a requirement stipulated by the OP in the question, I won't argue that it is hard and might not make sense.– Jörg W Mittag
1 hour ago
add a comment |
If i'm reading you right you are asking for a synchronous programming model but a high performance implementation. If that is correct than that is already available to us in the form of green threads or processes of e.g. Erlang or Haskell. So yes, it's an excellent idea, but the retrofitting to existing languages can't always be as smooth as you would like.
add a comment |
If i'm reading you right you are asking for a synchronous programming model but a high performance implementation. If that is correct than that is already available to us in the form of green threads or processes of e.g. Erlang or Haskell. So yes, it's an excellent idea, but the retrofitting to existing languages can't always be as smooth as you would like.
add a comment |
If i'm reading you right you are asking for a synchronous programming model but a high performance implementation. If that is correct than that is already available to us in the form of green threads or processes of e.g. Erlang or Haskell. So yes, it's an excellent idea, but the retrofitting to existing languages can't always be as smooth as you would like.
If i'm reading you right you are asking for a synchronous programming model but a high performance implementation. If that is correct than that is already available to us in the form of green threads or processes of e.g. Erlang or Haskell. So yes, it's an excellent idea, but the retrofitting to existing languages can't always be as smooth as you would like.
answered 2 hours ago
monocellmonocell
1285
1285
add a comment |
add a comment |
What you are missing, is the purpose of async operations: They allow you to make use of your waiting time!
If you turn an async operation, like requesting some resource from a server, into a synchronous operation by implicitly and immediately waiting for the reply, your thread cannot do anything else with the waiting time. If the server takes 10 milliseconds to respond, there go about 30 million CPU cycles to the waste. The latency of the response becomes the execution time for the request.
The only reason why programmers invented async operations, is to hide the latency of inherently long-running tasks behind other useful computations. If you can fill the waiting time with useful work, that's CPU time saved. If you can't, well, nothing's lost by the operation being async.
So, I recommend to embrace the async operations that your languages provide to you. They are there to save you time.
i was thinking of a functional language where operations are not blocking, so even if it has a synchronous syntax, a long-running computation will not block the thread
– Cinn
7 mins ago
add a comment |
What you are missing, is the purpose of async operations: They allow you to make use of your waiting time!
If you turn an async operation, like requesting some resource from a server, into a synchronous operation by implicitly and immediately waiting for the reply, your thread cannot do anything else with the waiting time. If the server takes 10 milliseconds to respond, there go about 30 million CPU cycles to the waste. The latency of the response becomes the execution time for the request.
The only reason why programmers invented async operations, is to hide the latency of inherently long-running tasks behind other useful computations. If you can fill the waiting time with useful work, that's CPU time saved. If you can't, well, nothing's lost by the operation being async.
So, I recommend to embrace the async operations that your languages provide to you. They are there to save you time.
i was thinking of a functional language where operations are not blocking, so even if it has a synchronous syntax, a long-running computation will not block the thread
– Cinn
7 mins ago
add a comment |
What you are missing, is the purpose of async operations: They allow you to make use of your waiting time!
If you turn an async operation, like requesting some resource from a server, into a synchronous operation by implicitly and immediately waiting for the reply, your thread cannot do anything else with the waiting time. If the server takes 10 milliseconds to respond, there go about 30 million CPU cycles to the waste. The latency of the response becomes the execution time for the request.
The only reason why programmers invented async operations, is to hide the latency of inherently long-running tasks behind other useful computations. If you can fill the waiting time with useful work, that's CPU time saved. If you can't, well, nothing's lost by the operation being async.
So, I recommend to embrace the async operations that your languages provide to you. They are there to save you time.
What you are missing, is the purpose of async operations: They allow you to make use of your waiting time!
If you turn an async operation, like requesting some resource from a server, into a synchronous operation by implicitly and immediately waiting for the reply, your thread cannot do anything else with the waiting time. If the server takes 10 milliseconds to respond, there go about 30 million CPU cycles to the waste. The latency of the response becomes the execution time for the request.
The only reason why programmers invented async operations, is to hide the latency of inherently long-running tasks behind other useful computations. If you can fill the waiting time with useful work, that's CPU time saved. If you can't, well, nothing's lost by the operation being async.
So, I recommend to embrace the async operations that your languages provide to you. They are there to save you time.
answered 18 mins ago
cmastercmaster
6,66311322
6,66311322
i was thinking of a functional language where operations are not blocking, so even if it has a synchronous syntax, a long-running computation will not block the thread
– Cinn
7 mins ago
add a comment |
i was thinking of a functional language where operations are not blocking, so even if it has a synchronous syntax, a long-running computation will not block the thread
– Cinn
7 mins ago
i was thinking of a functional language where operations are not blocking, so even if it has a synchronous syntax, a long-running computation will not block the thread
– Cinn
7 mins ago
i was thinking of a functional language where operations are not blocking, so even if it has a synchronous syntax, a long-running computation will not block the thread
– Cinn
7 mins ago
add a comment |
The problem you're describing is two-fold.
- The program you're writing should behave asynchronously as a whole when viewed from the outside.
- It should not be visible at the call site whether a function call potentially gives up control or not.
There are a couple of ways to achieve this, but they basically boil down to
- having multiple threads (at some level of abstraction)
- having multiple kinds of function at the language level, all of which are called like this
foo(4, 7, bar, quux).
For (1), I'm lumping together forking and running multiple processes, spawning multiple kernel threads, and green thread implementations that schedule language-runtime level threads onto kernel threads. From the perspective of the problem, they are the same. In this world, no function ever gives up or loses control from the perspective of its thread. The thread itself sometimes doesn't have control and sometimes isn't running but you don't give up control of your own thread in this world. A system fitting this model may or may not have the ability to spawn new threads or join on existing threads. A system fitting this model may or may not have the ability to duplicate a thread like Unix's fork.
(2) is interesting. In order to do it justice we need to talk about introduction and elimination forms.
I'm going to show why implicit await cannot be added to a language like Javascript in a backwards-compatible way. The basic idea is that by exposing promises to the user and having a distinction between synchronous and asynchronous contexts, Javascript has leaked an implementation detail that prevents handling synchronous and asynchronous functions uniformly. There's also the fact that you can't await a promise outside of an async function body. These design choices are incompatible with "making asynchronousness invisible to the caller".
You can introduce a synchronous function using a lambda and eliminate it with a function call.
Synchronous function introduction:
((x) => return x + x;)
Synchronous function elimination:
f(4)
((x) => return x + x;)(4)
You can contrast this with asynchronous function introduction and elimination.
Asynchronous function introduction
(async (x) => return x + x;)
Asynchonrous function elimination (note: only valid inside an async function)
await (async (x) => return x + x;)(4)
The fundamental problem here is that an asynchronous function is also a synchronous function producing a promise object.
Here's an example of calling an asynchronous function synchronously in the node.js repl.
> (async (x) => return x + x;)(4)
Promise 8
You can hypothetically have a language, even a dynamically typed one, where the difference between asynchronous and synchronous function calls is not visible at the call site and possibly is not visible at the definition site.
Taking a language like that and lowering it to Javascript is possible, you'd just have to effectively make all functions asynchronous.
add a comment |
The problem you're describing is two-fold.
- The program you're writing should behave asynchronously as a whole when viewed from the outside.
- It should not be visible at the call site whether a function call potentially gives up control or not.
There are a couple of ways to achieve this, but they basically boil down to
- having multiple threads (at some level of abstraction)
- having multiple kinds of function at the language level, all of which are called like this
foo(4, 7, bar, quux).
For (1), I'm lumping together forking and running multiple processes, spawning multiple kernel threads, and green thread implementations that schedule language-runtime level threads onto kernel threads. From the perspective of the problem, they are the same. In this world, no function ever gives up or loses control from the perspective of its thread. The thread itself sometimes doesn't have control and sometimes isn't running but you don't give up control of your own thread in this world. A system fitting this model may or may not have the ability to spawn new threads or join on existing threads. A system fitting this model may or may not have the ability to duplicate a thread like Unix's fork.
(2) is interesting. In order to do it justice we need to talk about introduction and elimination forms.
I'm going to show why implicit await cannot be added to a language like Javascript in a backwards-compatible way. The basic idea is that by exposing promises to the user and having a distinction between synchronous and asynchronous contexts, Javascript has leaked an implementation detail that prevents handling synchronous and asynchronous functions uniformly. There's also the fact that you can't await a promise outside of an async function body. These design choices are incompatible with "making asynchronousness invisible to the caller".
You can introduce a synchronous function using a lambda and eliminate it with a function call.
Synchronous function introduction:
((x) => return x + x;)
Synchronous function elimination:
f(4)
((x) => return x + x;)(4)
You can contrast this with asynchronous function introduction and elimination.
Asynchronous function introduction
(async (x) => return x + x;)
Asynchonrous function elimination (note: only valid inside an async function)
await (async (x) => return x + x;)(4)
The fundamental problem here is that an asynchronous function is also a synchronous function producing a promise object.
Here's an example of calling an asynchronous function synchronously in the node.js repl.
> (async (x) => return x + x;)(4)
Promise 8
You can hypothetically have a language, even a dynamically typed one, where the difference between asynchronous and synchronous function calls is not visible at the call site and possibly is not visible at the definition site.
Taking a language like that and lowering it to Javascript is possible, you'd just have to effectively make all functions asynchronous.
add a comment |
The problem you're describing is two-fold.
- The program you're writing should behave asynchronously as a whole when viewed from the outside.
- It should not be visible at the call site whether a function call potentially gives up control or not.
There are a couple of ways to achieve this, but they basically boil down to
- having multiple threads (at some level of abstraction)
- having multiple kinds of function at the language level, all of which are called like this
foo(4, 7, bar, quux).
For (1), I'm lumping together forking and running multiple processes, spawning multiple kernel threads, and green thread implementations that schedule language-runtime level threads onto kernel threads. From the perspective of the problem, they are the same. In this world, no function ever gives up or loses control from the perspective of its thread. The thread itself sometimes doesn't have control and sometimes isn't running but you don't give up control of your own thread in this world. A system fitting this model may or may not have the ability to spawn new threads or join on existing threads. A system fitting this model may or may not have the ability to duplicate a thread like Unix's fork.
(2) is interesting. In order to do it justice we need to talk about introduction and elimination forms.
I'm going to show why implicit await cannot be added to a language like Javascript in a backwards-compatible way. The basic idea is that by exposing promises to the user and having a distinction between synchronous and asynchronous contexts, Javascript has leaked an implementation detail that prevents handling synchronous and asynchronous functions uniformly. There's also the fact that you can't await a promise outside of an async function body. These design choices are incompatible with "making asynchronousness invisible to the caller".
You can introduce a synchronous function using a lambda and eliminate it with a function call.
Synchronous function introduction:
((x) => return x + x;)
Synchronous function elimination:
f(4)
((x) => return x + x;)(4)
You can contrast this with asynchronous function introduction and elimination.
Asynchronous function introduction
(async (x) => return x + x;)
Asynchonrous function elimination (note: only valid inside an async function)
await (async (x) => return x + x;)(4)
The fundamental problem here is that an asynchronous function is also a synchronous function producing a promise object.
Here's an example of calling an asynchronous function synchronously in the node.js repl.
> (async (x) => return x + x;)(4)
Promise 8
You can hypothetically have a language, even a dynamically typed one, where the difference between asynchronous and synchronous function calls is not visible at the call site and possibly is not visible at the definition site.
Taking a language like that and lowering it to Javascript is possible, you'd just have to effectively make all functions asynchronous.
The problem you're describing is two-fold.
- The program you're writing should behave asynchronously as a whole when viewed from the outside.
- It should not be visible at the call site whether a function call potentially gives up control or not.
There are a couple of ways to achieve this, but they basically boil down to
- having multiple threads (at some level of abstraction)
- having multiple kinds of function at the language level, all of which are called like this
foo(4, 7, bar, quux).
For (1), I'm lumping together forking and running multiple processes, spawning multiple kernel threads, and green thread implementations that schedule language-runtime level threads onto kernel threads. From the perspective of the problem, they are the same. In this world, no function ever gives up or loses control from the perspective of its thread. The thread itself sometimes doesn't have control and sometimes isn't running but you don't give up control of your own thread in this world. A system fitting this model may or may not have the ability to spawn new threads or join on existing threads. A system fitting this model may or may not have the ability to duplicate a thread like Unix's fork.
(2) is interesting. In order to do it justice we need to talk about introduction and elimination forms.
I'm going to show why implicit await cannot be added to a language like Javascript in a backwards-compatible way. The basic idea is that by exposing promises to the user and having a distinction between synchronous and asynchronous contexts, Javascript has leaked an implementation detail that prevents handling synchronous and asynchronous functions uniformly. There's also the fact that you can't await a promise outside of an async function body. These design choices are incompatible with "making asynchronousness invisible to the caller".
You can introduce a synchronous function using a lambda and eliminate it with a function call.
Synchronous function introduction:
((x) => return x + x;)
Synchronous function elimination:
f(4)
((x) => return x + x;)(4)
You can contrast this with asynchronous function introduction and elimination.
Asynchronous function introduction
(async (x) => return x + x;)
Asynchonrous function elimination (note: only valid inside an async function)
await (async (x) => return x + x;)(4)
The fundamental problem here is that an asynchronous function is also a synchronous function producing a promise object.
Here's an example of calling an asynchronous function synchronously in the node.js repl.
> (async (x) => return x + x;)(4)
Promise 8
You can hypothetically have a language, even a dynamically typed one, where the difference between asynchronous and synchronous function calls is not visible at the call site and possibly is not visible at the definition site.
Taking a language like that and lowering it to Javascript is possible, you'd just have to effectively make all functions asynchronous.
edited 4 mins ago
answered 10 mins ago
Gregory NisbetGregory Nisbet
1656
1656
add a comment |
add a comment |
This is available in C++ as std::async since C++11.
The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call.
And with C++20 coroutines can be used:
https://www.modernescpp.com/index.php/coroutines- https://lewissbaker.github.io/2017/11/17/understanding-operator-co-await
This doesn't seem to answer the question. According to your link: "What does the Coroutines TS give us? Three new language keywords: co_await, co_yield and co_return"... But the question is why do we need anawait(orco_awaitin this case) keyword in the first place?
– Arturo Torres Sánchez
11 mins ago
add a comment |
This is available in C++ as std::async since C++11.
The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call.
And with C++20 coroutines can be used:
https://www.modernescpp.com/index.php/coroutines- https://lewissbaker.github.io/2017/11/17/understanding-operator-co-await
This doesn't seem to answer the question. According to your link: "What does the Coroutines TS give us? Three new language keywords: co_await, co_yield and co_return"... But the question is why do we need anawait(orco_awaitin this case) keyword in the first place?
– Arturo Torres Sánchez
11 mins ago
add a comment |
This is available in C++ as std::async since C++11.
The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call.
And with C++20 coroutines can be used:
https://www.modernescpp.com/index.php/coroutines- https://lewissbaker.github.io/2017/11/17/understanding-operator-co-await
This is available in C++ as std::async since C++11.
The template function async runs the function f asynchronously (potentially in a separate thread which may be part of a thread pool) and returns a std::future that will eventually hold the result of that function call.
And with C++20 coroutines can be used:
https://www.modernescpp.com/index.php/coroutines- https://lewissbaker.github.io/2017/11/17/understanding-operator-co-await
edited 55 mins ago
answered 1 hour ago
Robert AndrzejukRobert Andrzejuk
519110
519110
This doesn't seem to answer the question. According to your link: "What does the Coroutines TS give us? Three new language keywords: co_await, co_yield and co_return"... But the question is why do we need anawait(orco_awaitin this case) keyword in the first place?
– Arturo Torres Sánchez
11 mins ago
add a comment |
This doesn't seem to answer the question. According to your link: "What does the Coroutines TS give us? Three new language keywords: co_await, co_yield and co_return"... But the question is why do we need anawait(orco_awaitin this case) keyword in the first place?
– Arturo Torres Sánchez
11 mins ago
This doesn't seem to answer the question. According to your link: "What does the Coroutines TS give us? Three new language keywords: co_await, co_yield and co_return"... But the question is why do we need an
await (or co_await in this case) keyword in the first place?– Arturo Torres Sánchez
11 mins ago
This doesn't seem to answer the question. According to your link: "What does the Coroutines TS give us? Three new language keywords: co_await, co_yield and co_return"... But the question is why do we need an
await (or co_await in this case) keyword in the first place?– Arturo Torres Sánchez
11 mins ago
add a comment |
Cinn is a new contributor. Be nice, and check out our Code of Conduct.
Cinn is a new contributor. Be nice, and check out our Code of Conduct.
Cinn is a new contributor. Be nice, and check out our Code of Conduct.
Cinn is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Software Engineering Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsoftwareengineering.stackexchange.com%2fquestions%2f389445%2fwhy-dont-programming-languages-automatically-manage-the-synchronous-asynchronou%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
11
I don't really understand your question. If you "always wait for the asynchronous operation", then it is not an asynchronous operation, it is a synchronous operation. Can you clarify? Maybe give a specification of the type of behavior you are looking for? Also, "what do you think about it" is off-topic on Software Engineering. You need to formulate your question in the context of a concrete problem, that has a single, unambiguous, canonical, objectively correct answer.
– Jörg W Mittag
2 hours ago
1
@JörgWMittag I imagine a hypothetical C# that implicitly
awaits aTask<T>to convert it toT– Caleth
2 hours ago
Are you asking about language support for Transparent Futures? If yes, why do you need language support, why are the currently existing libraries not good enough?
– Jörg W Mittag
2 hours ago
@Caleth I don't know much of C#, in js or swift we have to adopt a particular syntax to manage operations which resolves in the future (i am avoiding the asynchronous term as it seems to create confusions). And this particular syntax is really heavy, so that's why we got promises and later async/await to make it a bit lighter, but still... My question is if it is possible for a programming language to handle the same way the both, as it would make things much more easier for the programmer, code more readable etc.
– Cinn
2 hours ago
Check out coroutines in Kotlin. What you are describing seems similar.
– JimmyJames
2 hours ago