this post was submitted on 28 Jan 2024
25 points (96.3% liked)

Programmer Humor

32175 readers
289 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
top 43 comments
sorted by: hot top controversial new old
[–] snowe@programming.dev 7 points 8 months ago (2 children)

This is my favorite version of this so far.

[–] Phoenix3875@lemmy.world 3 points 8 months ago

I'm gett the ing UDP same vib joke

[–] Exosus@lemdro.id 0 points 8 months ago (1 children)

It's funny but the random capitalization is distracting

[–] stebo02@lemmy.dbzer0.com 0 points 8 months ago (1 children)

it's not that random, it's the original text

[–] Exosus@lemdro.id 0 points 8 months ago (2 children)

Ok so you had to know the original post, ok

[–] stebo02@lemmy.dbzer0.com 1 points 8 months ago

There are tons of parodies like this of it

[–] Maven@lemmy.world 0 points 8 months ago (1 children)

I wouldn't say you HAVE to know the original but it's pretty common in memes for text to be replaced and the person doing the replacing to not know the original font.

[–] Pyroglyph@lemmy.world 1 points 8 months ago

You at least have to know that it's a meme format. Otherwise it just looks like someone complaining about async with a bad crop.

[–] mlg@lemmy.world 4 points 8 months ago* (last edited 8 months ago)

I'm actually laughing out loud at the amount of whitespace because ~~thread~~ routine is still executing lmao

[–] neo@lemmy.comfysnug.space 2 points 8 months ago

We're here asyncronously waiting for the rest of the meme.

[–] fxdave@lemmy.ml 1 points 8 months ago (1 children)

Honestly, I don't get it.

Is it about the syntax sugar? Would you like to use callbacks instead?

Async programming is when you achive concurrency even with one thread. It's needed. There's no alternative to this.

[–] activ8r@sh.itjust.works 4 points 8 months ago (1 children)
[–] fxdave@lemmy.ml 1 points 8 months ago

I see, thanks

[–] tias@discuss.tchncs.de 0 points 8 months ago (1 children)
[–] Maven@lemmy.world 4 points 8 months ago (2 children)

I PROMISE the rest will come eventually

[–] ibasaw@lemmy.world 3 points 8 months ago

that is going to take some RESOLVE

[–] xmunk@sh.itjust.works 0 points 8 months ago (1 children)
[–] RustyNova@lemmy.world 1 points 8 months ago

Async are lazy loaded by design in rust, so... Yeah

[–] agressivelyPassive@feddit.de 0 points 8 months ago (6 children)

I honestly don't know, why async got so popular. It seems like the entire reason for doing it was that some blokes were hellbent on using JS on a server and couldn't fathom that a second thread might be a good idea.

[–] hubobes@sh.itjust.works 2 points 8 months ago

If you are waiting for IO, why would you block your current thread and not let it do something else? Async does not only exist in JS.

[–] masterspace@lemmy.ca 2 points 8 months ago

Because the alternative is a series of ridiculously nested call backs that make code hard to read and manage?

I honestly can't fathom how anyone would dislike async programming.

[–] mindbleach@sh.itjust.works 1 points 8 months ago* (last edited 8 months ago)

Async got popular when the choices for clientside code in the browser were "Javascript" or "go fuck yourself." It's an utterly miserable way to avoid idiotic naive while() stalling. But it was the only way.

[–] Lmaydev@programming.dev 0 points 8 months ago* (last edited 8 months ago) (2 children)

A huge amount of time in apps is spent waiting for IO, database or web requests to complete.

Async prevents locking a thread during this wait.

If you're handling a large amount of requests in a web server, for example, it allows other requests to progress while waiting for these operations.

Threads are also expensive to start and manage.

Also handling threads manually is a pain in the ass.

[–] Bene7rddso@feddit.de 0 points 8 months ago (1 children)

If you need to get multiple pieces of data for one request Async is great, but why would you work on different requests in the same thread? Why slow down one request because the other needs a bunch of computation?

[–] Lmaydev@programming.dev 1 points 8 months ago

You aren't slowing down anything. If you didn't use async that thread would be blocked.

You'd need a thread per request even though they are sat doing nothing while waiting for responses.

Instead when you hit an await that thread is freed for other work and when the wait is over the rest of the code is scheduled to run.

[–] ShortFuse@lemmy.world -1 points 8 months ago (1 children)

Async prevents locking a thread during this wait.

That's a very common misconception. async is just a scheduling tool that runs at the end of event loop (microtask queue). It still runs on the main thread and you can still lock up your UI. You'd need Web Workers for actual multi-threading.

[–] locuester@lemmy.zip 1 points 8 months ago (1 children)

It can lock up a UI doing cpu bound work. Making a web request, no. Preventing the ui thread from waiting on native IO is what async was created for.

[–] ShortFuse@lemmy.world 1 points 8 months ago* (last edited 8 months ago) (1 children)

Preventing the ui thread from waiting on native IO is what async was created for.

Citation needed. async just a wrapper for Promises. IO isn't related, just commonly used with it.

https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-async-functions-abstract-operations-async-function-start

NodeJS's IO and fetch are just promises. (And NodeJS used to use callback(err, response) before adding promises.).

[–] locuester@lemmy.zip 1 points 8 months ago (1 children)

Yes I’m simplifying a LOT, but in the context of background web calls, that was what callbacks became so important for. XMLHttpRequest in IE 5 sparked the Ajax movement and adventures in nested callbacks.

Prior to that, the browser had window.setTimeout and its callback for delays and animation and such - but that’s it.

The main purpose of all this async callback stuff was originally, and arguably still is (in the browser), for allowing the ui event loop to run while network requests are made.

NodeJS didn’t come into the picture for almost 10 years or so.

[–] ShortFuse@lemmy.world 1 points 8 months ago* (last edited 8 months ago) (1 children)

Yeah, that's a big simplification and I get it. But the async syntax itself syntax "sugar" for Promises. It's not like C# or Java/Android where it will spawn a thread. If you take a JSON of 1000 rows and attach a promise/await to each of them, you won't hit the next event loop until they all run to completion.

It's a common misconception that asynchronous means "run in background". It doesn't. It means run at end of current call stack.

Prior to that, the browser had window.setTimeout and its callback for delays and animation and such - but that’s it.

And you STILL have to call setTimeout in your async executions or else you will stall your UI.

Again async is NOT background. It's run later. async wraps Promise which wraps queueMicrotask.

Here is a stack overflow that explains it more in detail.

[–] locuester@lemmy.zip 1 points 8 months ago

I’m well aware how async works in the single threaded js environment. All code blocks the main thread! Calling await on an async operation yields back.

You’re right, async is commonly mixed up with multi-threaded. And in fact in many languages the two things work hand in hand. I’m very aware of how it works in JavaScript.

We are agreeing. Don’t need more info.

[–] PlexSheep@feddit.de 0 points 8 months ago* (last edited 8 months ago) (1 children)

Async rust with the Tokio Framework is pretty cool. Need none of that JS bloat for async.

[–] cooljacob204@kbin.social 0 points 8 months ago (1 children)

Async Rust sucks. I hate how many libraries use it, forcing it apon you.

[–] deur@feddit.nl 0 points 8 months ago* (last edited 8 months ago) (1 children)

You suck, I hate how your comment was forced "apon" me. Anyone who claims things that they can easily avoid if theyre so opinionated against them are "forced upon" them are always pathetic people.

[–] cooljacob204@kbin.social 1 points 8 months ago

Have you programmed with rust a day in your life? Once you introduce one library that requires Tokio async you have to start wrapping all your calls that involve it in async shit.

So many better concurrency patterns out there.

And these libraries are not easily avoidable. Ex: most AWS libraries require it.

And forgive me for a stupid typo, I have had little sleep the last week but you are an asshole that thinks belittling people somehow makes you right so it doesn't really matter.

[–] Nyfure@kbin.social 0 points 8 months ago (1 children)

Async is good because threads are expensive, might aswell do something else when you need to wait for something anyways.
But only having async and no other thread when you need some computation is obviously awful.. (or when starting anothe rthread is not easily manageable)

Thats why i like go, you just tell it you want to run something in parallel and he will manage the rest.. computational work, shift current work to new thread.. just waiting for IO, async.

[–] MantisWaffle@lemmy.world 0 points 8 months ago* (last edited 8 months ago) (1 children)

The "do something while waiting for something else" is not a reason to use async. That's why blocking system calls and threads exist.

Threads don't need to be expensive. Max stack usage can be determined statically before choosing the size when spawning a thread.

Any other reasons?

[–] masterspace@lemmy.ca 0 points 8 months ago (1 children)

Threads don't need to be expensive.

Well too bad cause they are.

Go ahead and spin up a web worker and transfer a bunch of data to it and tell us how long you had to wait.

[–] MantisWaffle@lemmy.world 0 points 8 months ago* (last edited 8 months ago) (1 children)

The only way I have heard threads are expensive, in the context of handling many io requests, is stack usage. You can tell the os to give less memory (statically determined stack size) to the thread when it's spawned, so this is not a fundamental issue to threads.

Go ahead and spin up a web worker and transfer a bunch of data to it and tell us how long you had to wait.

Time to transfer data to one thread is related to io speed. Why would this have anything to do with concurrency model?

[–] masterspace@lemmy.ca 1 points 8 months ago (1 children)

Well I just told you another one, one actually relevant to the conversation at hand, since it's the only one you can use with JavaScript in the context of a web browser.

[–] MantisWaffle@lemmy.world 0 points 8 months ago* (last edited 8 months ago) (1 children)

You cant say async is the fundamentally better model because threading is purposely crippled in the browser.

The conversation at hand is not "how do io in browser". Its "async is not inherently better than threads"

[–] masterspace@lemmy.ca 0 points 8 months ago* (last edited 8 months ago) (1 children)

No, because async is fundamentally a paradigm for how to express asynchronous programming, i.e. situations where you need to wait for something else to happen, threading is not an alternative to that, callbacks are.

[–] MantisWaffle@lemmy.world -1 points 8 months ago

Threads are callbacks.