3 ms·
I agree that it is a bit overzealous to say that every function should return its data using callbacks, but sometimes it makes sense even for synchronous functi
by shawnz 12y ago
I agree that it is a bit overzealous to say that every function should return its data using callbacks, but sometimes it makes sense even for synchronous functions. By making a function which doesn't accept a callback, you are creating an API that can never be made asynchronous, which could cause you more work in the long run.
For example, consider a function with a synchronous implementation. It gets the data from a place that is quick and easy to access, so making it async is not necessary. But later on, that data gets moved to an external database. Now, in the best case, every place where that function is used must be updated to be made asynchronous. In the worst case, every caller of the function, as well as every caller of those functions, and so on, must be updated. And quite often, converting synchronous code to async is no small feat.
- nickporter 12y agoI knew someone would say that, hah! I am 100% for making sync functions asynchronous if it's implementation might have to be async in the future. In fact, I have done so many times for the exact example you have mentioned.