Programming thread

  • Want to keep track of this thread?
    Accounts can bookmark posts, watch threads for updates, and jump back to where you stopped reading.
    Create account
i am totally ignorant on coroutines
can someone explain to me why i would want to use coroutines instead of just spawning and managing worker threads myself the regular way and handing them whatever task i want done concurrently in the form of some 'task' or 'executable' object?
What the fuck kind of nigger lang are you using where that kind of monstrosity is considered “the regular way”? Anyways, concurrency is not parallelism. Concurrency is a design strategy wherein related tasks are able to be executed independantly of each other, while parallelism is an execution strategy where tasks are executed at the same time as each other. Concurrency does not necessitate parallelism in that tasks could be executed one at a time, and parallelism does not necessitate concurrency in that the tasks executed need not be related in any way.
Coroutines exist to enable concurrent design of programs, those executable objects you talk about handing over to worker threads could be thought of as coroutines, handed to threads to be executed in parallel. Traditionally what were called coroutines were distinct from other concurrency models in that they didn’t feature any parallelism. This isn’t a necessary feature of the model, tho, and I meant coroutines in a general sense, not precluding parallel execution.
 
In this way, a monad is like a coroutine because when you call into a monad, you pick up whatever state is guarded by the monad from the last time it was called and augment it for the next time the monad is called.
Closures are also coroutines and thus also monads btw.
I think you misunderstands what a monad is. Monad is a way of defining how to combine "wrappers" when you have wrapped/monadic value x and want to apply function that takes x and returns wrapped/monadic y. m x -> (x -> m y) -> m y
There is no per se calling into a monad. Monad is just definition of how to apply function to it, and how monadic context is being combined.

I made a write up about it earlier:
https://kiwifarms.st/threads/programming-thread.41367/post-22478501

i am totally ignorant on coroutines
can someone explain to me why i would want to use coroutines instead of just spawning and managing worker threads myself the regular way and handing them whatever task i want done concurrently in the form of some 'task' or 'executable' object?
Coroutines are more about asynchronous calls than parallelism, or even concurrency. Edit: Wrong! It's about concurrent calls.
It's basically a way to store local state for some code.
 
Last edited:
i am totally ignorant on coroutines
can someone explain to me why i would want to use coroutines instead of just spawning and managing worker threads myself the regular way
You should spawn worker threads when you're going to be doing a bunch of things that can be done at the same time by multiple cores. Coroutines are for situations where there is a vaguely ordered set of synchronous things that will happen. They don't solve any new problem per se, they are just for neater engineering to replace polling and callbacks.

A concrete example will make everything clearer. A player in your game is moving to the edge of an area, and you need to surreptitiously load some more of the game world. You parse your nextarea.json to see what resources you need, spawn some worker threads to read, gunzip and initialize all the data, and then... what? Do you schedule some kind of checkIfTheNiggersAreLoaded function to run every five seconds, to check if everything is done and initialized? Are all of your data structures going to call a (void*)*reportNiggerloading(Nigger*) callback function when they complete, to do bookkeeping on how complete it is, and call something else when it is complete?

Well, the idea of coroutines is that you will have the checkNiggers routines already "running", and the niggersInitialized result function already "running" (= not running), and they just yield their execution until the other coroutines communicate that they've done their part of the sequence. Ideally it will save you the work of engineering how the control flow will visit all these locations in a correct and optimal order, and hopefully make the resulting program easier for others to understand by implementing the synchronicity behind this Wizard of Oz curtain.
 
There is no per se calling into a monad. Monad is just definition of how to apply function to it, and how monadic context is being combined.
Some monads, like state monads can be kinda "called into". (through returning a different function based on what you put in, which in turn can be used to get a modified copy of the monad) [0]

But in general, monads are just containers which obey some laws. https://blog.ploeh.dk/2022/04/11/monad-laws/

[0]: Basically you return a function that also is a closure over the data which returns a new, modified instance of the data when called. https://en.wikibooks.org/wiki/Haskell/Understanding_monads/State#Setting_and_Accessing_the_State

(the curse of being unable to explain monads properly really hits home for me now)
 
I think you misunderstands what a monad is. Monad is a way of defining how to combine "wrappers" when you have wrapped/monadic value x and want to apply function that takes x and returns wrapped/monadic y. m x -> (x -> m y) -> m y
There is no per se calling into a monad. Monad is just definition of how to apply function to it, and how monadic context is being combined.

I made a write up about it earlier:
https://kiwifarms.st/threads/programming-thread.41367/post-22478501
Ok then, tell me where I’ve got this wrong. Monads are about providing access rules surrounding a value along with a context for that value that persists between function calls/modifications. Coroutines are about combining a routine with a context around that routine that persists between yields/calls. I state that these are equivalent constructs because they both provide a persistant context with some rules for interacting with that context. Where did I go wrong? Did I conflate too much between monads and the functions that use them?
 
Ok then, tell me where I’ve got this wrong. Monads are about providing access rules surrounding a value along with a context for that value that persists between function calls/modifications. Coroutines are about combining a routine with a context around that routine that persists between yields/calls. I state that these are equivalent constructs because they both provide a persistant context with some rules for interacting with that context. Where did I go wrong? Did I conflate too much between monads and the functions that use them?
Monads are much more abstract than coroutines. Monads is set of laws that given object/type has to fulfill.
Coroutine is just a way to define code which can yield.
I think you can use coroutine to implement some Monads. But I don't think it's as simple as monad is a coroutine.

But maybe someone could prove it.
 
i am totally ignorant on coroutines
can someone explain to me why i would want to use coroutines instead of just spawning and managing worker threads myself the regular way and handing them whatever task i want done concurrently in the form of some 'task' or 'executable' object?
In recent times the async/await paradigm has been gaining ground over the traditional threading paradigm. In my opinion this is generally a good thing as you don't have to deal with thread safety problems like having to use atomic operations or mutual exclusion.

The async/await paradigm provides stackless coroutines. They are less powerful than stackful coroutines, but with the added benefit of performance and a kind of type checking (probably not the right terminology) via colored functions. I'm personally not a fan of type checking or colored functions, so I like my stackful coroutines.

Choosing to use multi-threading should be for optimizing performance, similar to how you'd use vector operations or hand write assembly.
 
In recent times the async/await paradigm has been gaining ground over the traditional threading paradigm. In my opinion this is generally a good thing as you don't have to deal with thread safety problems
But let's be real. The reason coroutines got popular "over the traditional threading paradigm" is that there are a bunch of baby languages where you can't actually do multiple threads properly, because the interpreter was designed as single-threaded, and the hacky tacked-on worker thread solutions can't share a single memory map. I put "over parallelization" in scare quotes there because coroutines do not replace parallelization. Coroutines and threaded parallelization are not solving the same problem and could even be mixed, if these languages were able to do threads correctly.
 
No, this is cope. Not the "it's great" part, that's true of course, but the "it's only bad if" part. Just like with other great and society-transforming inventions like automobiles and personal mobility vehicles, the "if" part always happens. Except this time it isn't just going to turn everybody fat and gross, but cause a severe cognitive decline that already can be measured in the late Z generation.

Obviously, feel free to go ahead and keep pumping out and consuming AI slop, this genie isn't ever going back in the bottle. But let's not kid ourselves about the writing on the wall here.
Personally, I use it rarely, (like 1-3 times a month ? at most), if I need something, I will search to find answers on internet (or books if I truly need it). But beyond that, it's just a tool you can use like everything else.

And yes, you are true about the cognitive decline, I mean lazy parenting and shit schools, A.I. was just the hammer to break their brains.
 
I've found Claude Code to be useful once in a while, but I try to contain the blast radius. There's probably been about as many instances where it's done a fine job at writing boilerplate code I didn't feel like writing, as there have been instances where it cost me time by making wild incorrect guesses about, e.g., a well-documented API and I have to step through code I didn't write (or talk with a real human in a code review), and therefore lack any "muscle memory" for, to figure out where and how exactly it goes wrong. I don't care enough to compare and contrast it with Cursor or Copilot or Grok or the rest.

It's not "glorified autocomplete," and it sure as shit isn't a compiler (anyone saying this should rope). It's an okay tool for when you're too lazy to pick up a project or a toy program idea. I'm noticing that none of my friends who are all "ChatGPT makes me as good at your job as you are!" have actually landed a $150K/year tech job yet.

Gonna pick up SICP again tonight. I found an implementation of Fibonacci in Scheme on my work laptop. Don't remember writing it, but I must've. I'm starting to develop the skill of reflexively imagining the AST a given bit of code generates.
 
It's not "glorified autocomplete," and it sure as shit isn't a compiler (anyone saying this should rope). It's an okay tool for when you're too lazy to pick up a project or a toy program idea. I'm noticing that none of my friends who are all "ChatGPT makes me as good at your job as you are!" have actually landed a $150K/year tech job yet.
I hate AI autocomplete so much. Good ol' intellisense is much better for autocomplete. I am starting to use it for boilerplate code though. Specifically well defined functions that query a database for me. Where I let it autogenerate the simplest of CRUD operations.
 
I found the source of a very old open source video game. It's riddled withv
* Memory leaks
* Old libraries
* Shitcode

I was thinking of restoring it/remastering it. Could I pass it onto an ai model to fix it reliably?
 
Last edited:
I found the source of a very old open source video game. It's riddled withv
* Memory leaks
* Old libraries
* Shitcode

I was thinking of restoring it/remastering it. Could I pass it onto an ai model to fix it reliably?
You might as well give it a shot. The worst that happens is that you waste some time and burn some FAGMAN money (assuming you're using a free AI model for this).
 
Any recommendations for this kind of job?

Also any common mistakes I should look out for?
People have been giving Claude Code rave reviews, might as well try that (I haven't tried it personally though). Otherwise you could just cycle between ChatGPT, Gemini and Claude and see what gives you the best results. Though I'd think that you'd have more trouble compiling it and getting it to work in the first place. Once you get that done you can use that as a ground-truth version to steer AI back towards to stop it from going too off-the-rails.
 
I found the source of a very old open source video game. It's riddled withv
* Memory leaks
* Old libraries
* Shitcode

I was thinking of restoring it/remastering it. Could I pass it onto an ai model to fix it reliably?
What’s the game? If you don’t mind me asking. I remember being absolutely heartbroken when AsciiPortal refused to compile on my modern Linux. That game was so cool and it’s a travesty that games like it aren’t able to run on modern systems without major work.
 
More fun dealing with my jeet coworkers today.

We're developing a web app for a client. I'm handling backend, my coworker is handling frontend.

From the beginning of this project, I insisted that any of the external resources our code relies on have a local docker version. Sure, our client will deploy it to AWS and use AWS' postgres service, and S3 and SQS/SNS (their event pipeline thing), but I want local versions too, to make development comfy.

I always push for there to be an up-to-date docker compose file that supports whatever shitty open source clones exist of these services, so that anyone who joins the project can just clone master and run docker compose up --build and have the whole thing working solely on their computer without needing to connect to a cloud service for basic local development.

At some point, there might be some element of the project that absolutely, 100% relies on a cloud service. But I'll cross that river when we come to it.

So recently, we're adding a new feature that depends on an AWS service. My coworker is saying "uhh, ok, well, now we should talk about getting rid of the local version, because the local version doesn't support XYZ."

I argued with this person for like 5 hours over the past week about this. (We have multiple clients, so I'm getting pulled into dumb meetings at random times.)

I asked "ok show me the part of the code you absolutely can't mock out". Then I get pulled into a meeting and I never get the answer. Happened several times.

Today I'm reviewing a frontend PR for them and motherfucker, my coworker had this feature mocked out for like two weeks. The mock works just fine. It's exactly what I'm asking for.

I have no clue why they were quarreling with me about this for the past few days.

"oh yeah, that mock does work, just set the environment variable and it'll switch to the local version in docker"

Are you fucking kidding me? What language did you grow up speaking? Hindi? Punjabi? Would you have communicated this to me more effectively if I asked you in your jeet language instead? Fucking bullshit.

Developer experience is important. I hate anything that reduces my fun programming job to clerical work.

Anyway, they don't let me clock overtime, so I'm off the clock three minutes ago.

Working on my personal projects! Getting back into Scheme again for a project. Also playing around with ZeroMQ. Very interesting library.
 
I was thinking of restoring it/remastering it. Could I pass it onto an ai model to fix it reliably?
First of all you need to have an understanding of C/C++ to begin with, so you know what changes/fixes you actually need to make. After you get it compiling, you'll need to run it with a profiler so you can identify problem areas, such as Visual Studio's Memory Profiler or Valgrind.
If you are going to use an AI assistant, treat it like a junior developer who can only handle small tasks. It's going to have many limitations and need a lot of handholding to be useful.
Use Git as version control, so you can easily rollback changes in case you or Claude make a big mistake.
Finally, you should consider rewriting it in Rust, its much safer and more modern than C and C++, and everyone ITT loves it and will give you lots of encouragement for using it.
 
Does anybody else see and hate these people with github profiles absolutely stuffed with "personal projects" that are just static github pages sites? They can't even bother to follow a tutorial for a bullshit CRUD app. Commit calendar fully greened out with unsolicited style tweaks or AI slop pull requests. It really just puts a sour taste in my mouth to see hordes of people that appear to have zero passion or interest in software, cynically filling a portfolio with copied homework. These motherfuckers always have their profile picture as their headshot with every social media link on earth too. Are you getting hired? Who's hiring you to deploy template sites???
 
Back
Top Bottom