Live data from Hacker News

Callbacks as our Generation's Goto Statement

tirania.org

231–240 of 287 posts

Re: Callbacks as our Generation's Goto Statement

#231

There is some creative use of C# async/await in this blogpost: http://praeclarum.org/post/45277337108/await-in-the-land-of-... Basically, the author implements a “first time walkthrough” kind of interface a-la iWork very declaratively by using async: async Task ShowTheUserHowToSearch () { await Tutorial.EnterText (searchField, minLength: 3); await Tutorial.Tap (searchButton); await Tutorial.Congratulate ("Now you kno…

What if you have two buttons, search and 'be lucky'? I guess you will have to await for a controller object that wakes up that if either one of the buttons is triggered, and then test what button was pressed. Now what if you have add a search option dialog that can be invoked at any moment? I guess when the 'apply' button of the option dialog got pressed then this is still going to be a callback that sets global vari…

"What if you have two buttons, search and 'be lucky'? I guess you will have to await for a controller object that wakes up that if either one of the buttons is triggered, and then test what button was pressed."

http://msdn.microsoft.com/en-us/library/hh194796.aspx

Re: Callbacks as our Generation's Goto Statement

#233

Earlier quoted context omitted.

They seem to be pretty busy with Roslyn, Anders recently admitted it's taking longer than originally expected. So perhaps we need to give 'em a break. The only thing I heard about C# 6 so far is it's maybe going to have more compact class declarations, a-la F# or TypeScript.

C# 2 added generics (courtesy of the same people that did F#) and closures (albeit with syntax as verbose as JS). C# 3 added LINQ, which is a major breakthrough for end-users, although I'm not fond of the query language. So really, C# 3 just added in some basic features you expect from proper languages. I do understand this required a huge amount of work, esp. with the tooling required. C# 4 added dynamic (F# provide…

>C# seems to have stagnated

TO me that seems to be a good thing. The language has picked up a lot of great features that make it nice to program in, but it is also making the language huge. How do all these new features interact? What are the emergent properties of the language? Personally I could use a few years to A) get legacy code caught up B) Explore what already exists.

Re: Callbacks as our Generation's Goto Statement

#234
This is all simply sugar to hide behind-the-scenes threading behind very narrow interfaces. Which isn't necessarily bad, but it's fun to see it suddenly in favour again and presented as something new.

E.g. Simula67 had Call and Detach for the basic case, and Activate(object representing async behaviour) and Wait(queue) that would both depending on need often be used for the same purpose (as well as a number of other operations). We had to write code using those methods in Simula67 in my introduction to programming class first semester at university...

Re: Callbacks as our Generation's Goto Statement

#235
post #63

Yes a thousand million times. This is the reason why people love golang and why there's a lot of excitement about core.async in the Clojure community, particularly for ClojureScript where we can target the last 11 years of client web browser sans callback hell: http://swannodette.github.io/2013/07/12/communicating-sequen... Having spent some time with ClojureScript core.async I believe the CSP model actually has a le…

Yeah, C# await/async is cool. But isn't Google Go's approach nicer? Keep standard lib calls blocking as is, and use the "go" statement when you want to run something async? It avoids all the extra DoWhateverAsync() API functions. See http://stackoverflow.com/a/7480033/68707 What's the Go equivalent of "await"? I.e., like the "go" statement but asynchronously wait for the function to return and get its value?

[deleted]

Re: Callbacks as our Generation's Goto Statement

#236

Earlier quoted context omitted.

I'm not a beliver, so I may be missing something important... As far as I can see, await makes it possible to do things like: - UI Thread starts Thread X to do something slow; - Thread X is processing, in the meantime the user clicks on something that requires X's result; - Only now the UI thread stops, waiting for X. Your program stay responsive, unless it's completely not able to do so. As I said, I still don't thi…

No, you got it wrong. Await never blocks the UI thread. Instead, the compiler rewrites your sequential code into a state machine. When you await on a task, the compiler turns this into scheduling a continuation. No blocking.

Yep, I got it wrong. Thanks for pointing that.

Now I'm also wondering how I'd use something like that in an imperative language... Well, I have some studying to do.

Re: Callbacks as our Generation's Goto Statement

#237
post #176

Earlier quoted context omitted.

C# operates entirely differently, I understand. The IDE work is massive and necessary. Having said that, a lot of this stuff is "catching up" or implementing stuff from the 70s. To be clear, it's not like type inference or closures were invented with Haskell, F#, or C#. Stuff like that is pretty well-known PL stuff, isn't it? People would be upset if C# didn't have for loops; why aren't they upset the type inference…

> People would be upset if C# didn't have for loops; why aren't they upset the type inference is nearly useless? Because the existing type inference is good enough for the average enterprise programmer. You know, those guys with good enough CS grades, that just do what they are told and don't even know HN exists.

It's also good enough for some of us that do know HN exists.

Re: Callbacks as our Generation's Goto Statement

#238
post #176

Earlier quoted context omitted.

C# operates entirely differently, I understand. The IDE work is massive and necessary. Having said that, a lot of this stuff is "catching up" or implementing stuff from the 70s. To be clear, it's not like type inference or closures were invented with Haskell, F#, or C#. Stuff like that is pretty well-known PL stuff, isn't it? People would be upset if C# didn't have for loops; why aren't they upset the type inference…

> People would be upset if C# didn't have for loops; why aren't they upset the type inference is nearly useless? Because the existing type inference is good enough for the average enterprise programmer. You know, those guys with good enough CS grades, that just do what they are told and don't even know HN exists.

[deleted]

Re: Callbacks as our Generation's Goto Statement

#239
post #117

Evan Czaplicki (author of Elm lang) made the identical argument (sometime?/years ago), with the same reference to Dijkstra's quote, but with another suggested solution, Functional Reactive Programming, on which his language is oriented: http://elm-lang.org/learn/Escape-from-Callback-Hell.elm

HN discussion of that article: https://news.ycombinator.com/item?id=4732924 FRP is an interesting topic (I thought so anyway, I wrote a paper on it for my MS). It doesn't seem to have caught on widely as a paradigm, with a few exceptions I'm aware of (Elm, Meteor).

Rx (for C#), RxJS (for Javascript), Bacon.js.

Definitely not 'widely' but there are a few library implementations out there.

I reckon that the reason for this is that it's most useful when the interactivity is high (i.e. there are a lot of events to react to), but most applications (desktop, web) don't have a high enough number of events to make learning a new paradigm 'worthwhile'.

Re: Callbacks as our Generation's Goto Statement

#240
post #210

await PostPicToServiceAsync(mFile.GetStream (), tagsCtrl.Tags); Seems to be equivalent to a blocking call of old, or am I missing something?

Yes, you are :-)

The compiler rewrites your code to schedule all next lines as a continuation. There is no blocking.

Post reply on HN