D community's view on syntactic sugar
Dmitry Olshansky
dmitry.olsh at gmail.com
Tue Jun 19 07:14:11 UTC 2018
On Monday, 18 June 2018 at 20:54:22 UTC, aberba wrote:
> On Saturday, 16 June 2018 at 08:39:07 UTC, Dmitry Olshansky
> wrote:
>> On Friday, 15 June 2018 at 23:04:40 UTC, Sjoerd Nijboer wrote:
>>> For someone coming from a C# background there is some
>>> seemingly simple syntactic sugar missing from D.
>>>
>
>>> T* he `async` & `await` keyword from C# make proactor pattern
>>> async code extremely easy to reason about.
>>
>> God please no. Look at Go’s popularity because of dead simple
>> go routines and “async i/o is transparent and looks blocking
>> but ain’t so”. We have at least vibe.d for that and possibly
>> more. Also see Java doing fibers recently, and Kotlin did them
>> just a year or so back. People love fibers and mostly dislike
>> Futers/explicit async, and plain callbacks are obvious last
>> resort that nobody likes.
>
> async/await make asynchronous code in C# and JavaScript look
> clean and easy to wrap ones head around it. Solution to aka.
> callback hell. If popularity is what you're looking at, it
> JavaScript not Go. And async/await is all over the place...it
> more that a syntactic sugar, it a pattern.
I look at popularity but I prefer crutical thinking.
Nothing beats simple non-async code in understamdability save for
declarative stuff or no code. Really no code is best but
obviously not always an option.
So why async in JS?
That is because it’s their last choice to make things at least
_look_ better.
To give you a picture of how JS got to async you have to
understand that they started (and still in many ways are) as
Practically all of today’s JS execution environments are single
threaded process with integrated eventloop for events such as
timers and clicks.
They introduced APIs back in 199x that used callbacks
exclusively. Then people constructed Futures (Deferred etc.) on
top.
But it’s a JavaScript (popular, just like you said) so it has to
make it more builtin and simple. Because *some* (many) would
think that say jQuery Deffered is slow, you’d better use plain
callbacks. All of that stupidity sqaured is a day in day out talk
in JS world, because well popularity.
So being wise they decided to not destroy the excecution model
(but extend with workers, which are isolated process btw) but
cheaply extend it with syntax shugar.
And they succeeded because now you come and say that’s basically
the best thing to do.
It is not though, and I believe I’ve seen enough to act against
it. I use Scala everyday, and there Futures and Monads all the
way down in I/O, and no it’s not simpler nor faster model. It’s
okayish but that’s about it.
Compared to proper scheduler with integrated eventloop:
async is not fast - same as futures, could use a bit less RAM per
connection etc., but same or worse speed (and if you need say..
stacktrace;))
async is not convenient because it splits functions into “red”
and “green”, and you can mix them anymore
async is best effort attempt to make imperatice programmers write
future-based, monadic code (essentially). It was great success in
that, but no, please let’s pick the better model (in general,
ofc, special needs are special).
>>
>
>> ‘async’ is viral keywords that poorly scales, I worked on Dart
>> core team and even they admitted this problem is not solved
>> well.
>>
> Doesn't scales for what?
>
> Try C# or JavaScript and experience the true power of
> async/await.
Oh kid. I tried all of that and more. Like 4 years ago. Pardon
for my temper but no I know what I’m talking about and it’s not
“I tried it for a week and now I see async is nice”.
To hell with that!
I have actually seen and worked (not directly) on code **cking
does make async stack traces tolerable (google for causal stack
traces, Dart).
Again sorry to hurt your feelings but unless I see deep technical
good reason to go for async, I’ll die fighting against it. Let’s
bot cargocult for once, especially considering the interplay with
just about any bloody language feature to get “shugar”.
P.S. Damn, it really pusses me off. No offence was meant.
—
Dmitry Olshansky
More information about the Digitalmars-d
mailing list