top | item 13651371

(no title)

zump | 9 years ago

As a C programmer working with a large codebase, I have come to HATE callbacks.

Seriously, the worst feeling ever is tracing through a huge function tree, only to run into function pointer dereference. Then you have to go on a wild goose chase to find out when, where and what it will be assigned to.

STATIC TYPES PEOPLE.

discuss

order

pwdisswordfish|9 years ago

What does it have to do with static typing? Function pointers are perfectly valid types. Also, can't you just use a debugger?

zump|9 years ago

Not really in a custom ASIC in an embedded environment.

dllthomas|9 years ago

> STATIC TYPES PEOPLE.

What you are asking for is much more closely related to static dispatch than static typing.

dahart|9 years ago

C/C++ callbacks are fairly different in practice than what the article is talking about. You might like callbacks in JavaScript. You might really like promises -- no wild goose chase to track down the chain, because promises chain things explicitly and make async code look more synchronous.

What's most interesting about your point is that what the article suggests -- naming and de-nesting callbacks -- is in a way what you're warning against. By naming it and physically moving it, execution that was contained within a single block of code is now jumping around, and can move to other places where you have to go looking.

Even though it's considered an anti-pattern for good reasons, there are some advantages to nested callbacks.

MrBuddyCasino|9 years ago

As a C beginner I don't like them either. But are there techniques to avoid them? Take for instance nghttp2 which needs callbacks to handle I/O.