I disagree. protothreads is garbage. Making code look like something it isn't. Maintainability goes down the drain.
This is why most embedded code that claude writes is rubbish. It's because embedded code "in the public" is full of "overdone" personal, hobby horse coding styles.
MACRO_LANGUAGES
for example.
Usually there is nothing wrong with particular "concept", it's just the over application of it, or the application outside of context.
Consider an example from my line of work.
"Thou shalt make all method parameters final/const!"
The proponents are not lying and they are not wrong in many or most cases, however, they fail to see the downsides.
Consider a common flow like this:
aFunction( const anObject ) {
const detainted = detaint( anObject )
const normalised = normalise( detainted )
const validated = validate( normalised )
const domainModel = domain_map( validated )
// etc.
return finished_object
}
Five copies. 5 allocations. All in scope. Not even garbage collector will help you. All done for EVERY call, EVERY time. All decallocated each and every time, except the final return. Large cyclic garbage collection = slow = high memory footprint.
Consider instead:
aFunction( anObject ) {
anObject = detaint( anObject )
anObject = normalise( anObject )
anObject = validate( anObject )
anObject = domain_map( anObject )
// etc.
return anObject
}
Now runtime optimisations can actually take effect, the memory footprint drops, recycle/reuse can be utiltised.
Note... this is not the same thing as "side effects". The original "anObject" passed to the function is untouched. Only the 'reference' has been reused internally.
This might seem trival until "anObject" is a 2 Petabyte distributed dataset. Creating 5 copies of it is not what will happen at the metal... even if the code tries to tell you it does. Nor is it const.
Obviously if you are in C/C++ you need to be very careful how you manage your memory, but you should see that the "const" approach has issues if those functions allocate memory. It's the same thing. Except in "enterprise" languages where memory management is "runtime" people get lazy and don't see the wood for the trees. I do. You either use the garbage collector wisely or it bottlenecks your performance.
"Thou shalt make all method parameters final/const!""It depends"