I will talk about my own experience, and it only engage myself. I am not sure we can generalize my experience here with callbacks: But for me callback resulted in a big mess. :-)
I've worked in two investment banks, working on their "order passing servers" legacy code. It's c++ code for unix platform. And of course select() driven implementation leads to extensive use of callbacks. The kind of code structure was the same every where I worked: I receive something on a socket, I decode it, what is the event type? Huh ok, I call then the corresponding callback... Huh I need to load the associated context too. And usually the spaghetti appears just right here. When writing the callback for a processing deep into the "sequence diagram" people tend to be overflowed by information. They don't have a clear view of the invariants in their mind. Which leads to over-complicated code in order to deal with the myriad of possible states of your context. And it leads to a lot of bugs.
The context being global, a callback function is forced to behave with side effects. I guess (and only guess since I've never had the occasion to work in FRP style yet) that writing a callback in a synchronous style would would favor a more Functional-programming style, avoiding a lot of buggy side effects, while I guess also it would not be possible to avoid them all... :-/ It must be verified in a real world project that FRP does lead to a cleaner code. Does someone have examples please?
It would be great to have a c++ framework implementing FRP. Or implementing the async/await keywords as in c#. (just tell me if I am not clear enough cause I am not a natural English speaker... :-) )
I've worked in two investment banks, working on their "order passing servers" legacy code. It's c++ code for unix platform. And of course select() driven implementation leads to extensive use of callbacks. The kind of code structure was the same every where I worked: I receive something on a socket, I decode it, what is the event type? Huh ok, I call then the corresponding callback... Huh I need to load the associated context too. And usually the spaghetti appears just right here. When writing the callback for a processing deep into the "sequence diagram" people tend to be overflowed by information. They don't have a clear view of the invariants in their mind. Which leads to over-complicated code in order to deal with the myriad of possible states of your context. And it leads to a lot of bugs.
The context being global, a callback function is forced to behave with side effects. I guess (and only guess since I've never had the occasion to work in FRP style yet) that writing a callback in a synchronous style would would favor a more Functional-programming style, avoiding a lot of buggy side effects, while I guess also it would not be possible to avoid them all... :-/ It must be verified in a real world project that FRP does lead to a cleaner code. Does someone have examples please?
It would be great to have a c++ framework implementing FRP. Or implementing the async/await keywords as in c#. (just tell me if I am not clear enough cause I am not a natural English speaker... :-) )