Talk:Callback (computer programming)

message: This topic needs more general discussion of callbacks and their use, with simpler examples that explain the concept of a callback.  I am rewriting most of this article to include much more information. -- Who said this and when? Mattsenate (talk) 01:07, 13 December 2012 (UTC)
thread_title: [Untitled]

message: I think we should give simple example about this topic.coz this article is so COMPLICATED..THANKZ  —Preceding unsigned comment added by 202.60.56.249 (talk) 00:24, 17 February 2009 (UTC)
thread_title:  Suggestion 

message: === Example: return ===
Well, why these functions return int, when counter assumes they return void?
=== Example: count ===
Why 9 is before 10, in hex?
* Fixed: temporay loss of sanity. Dysprosia 12:50, 15 Dec 2003 (UTC)
thread_title:  Example 

message: Why 9 is before 10, in hex?
* Fixed: temporay loss of sanity. Dysprosia 12:50, 15 Dec 2003 (UTC)
thread_title:  Example: count 

message: Ldo, I'm afraid that your changes (on 17 Sep 2004) have really gone farther than needed.  This page is now overly complicated and reads more of a disertation on sorting algorithms rather than a simple encyclopedic article on the callback function.  I think keeping any example to the minimal possible to show the concept of callback is best, and leave the lengthy programming textbook and best practices explanation elsewhere.  Also some of your text is too gramatically casual, especially the paragraphs full of questions. - Dmeranda 06:54, 15 Oct 2004 (UTC)
thread_title:  Need to keep example code very simple 

message: I'm a software engineer (a real one (yeah, I know this is a very inflammatory way to start ;))) and I have difficulties understanding this article.  For example, in the Motivation section it is mentioned that the code of the iterator must be duplicated everywhere the list must be iterated over.  Why?  Are we talking about the machine code (even then, I wouldn't understand why it would need to be inlined) or about the high-level language code?  E.g. in Java, when I have to iterate over a Collection, I don't see myself duplicating any code. --132.210.56.50 15:21, 28 February 2006 (UTC)
replies: text: Me again.  After reading the code examples that come right after, I got it.. we were talking about the high-level language repetition of the "get the iterator/loop until itr.next() returns null" stuff.  Maybe it should be made explicit in the text?  I'm too slow? ;)  --132.210.56.50 15:30, 28 February 2006 (UTC)
thread_title:  This article is difficult to understand 

message: I don't agree with this passage:
:A callback can be used as a simpler alternative to polymorphism and generic programming, in that the exact behavior of a function can be dynamically determined by passing different (yet compatible) function pointers or handles to the lower-level function.
That's at least misleading.  It sounds like it's advocating using function pointers rather than polymorphism because "the exact behavior of a function can be dynamically determined by passing different ...  function pointers".  Polymorphism and generic programming can do the same thing (at least as well, IMHO).  You might be able to argue that function pointers are simpler, buy anyone who has tried to use them in C++ knows that (1) the syntax is horrific and (2) using member function pointers for callbacks is a nightmare.  By the way, it may be worth mentioning boost::function somewhere in the article, which is a superb library that uses generic programming to make function pointer-like objects which can be used very effectively for callbacks.
::I believe the point was that function pointers are more general, which they are. Rp (talk) 20:09, 1 March 2010 (UTC)
thread_title:  Callbacks > Polymorphism?? 

message: The second paragraph of this current article is absolutely horrible.  99.999999% of the world doesn't exist in the original author's stream of consciousness.  Can someone please translate it from spaz into English?  —Preceding unsigned comment added by 75.147.10.25 (talk) 15:43, 31 March 2009 (UTC)
replies: text: I agree. I was able to benefit from the example, but it isn't quite encyclopedic. It's kind of unprofessional. I would have loved it if it were in a blog post, but this needs to be as comprehensible as possible, which means simple and dry. If I think of a good way to rephrase the example, perhaps I'll make an edit. 68.82.50.201 (talk) 17:39, 5 April 2009 (UTC)

text: i guess i disagree.  i checked out this article after reading some gtk+ documentation and i think it makes sense from my perspective.  i loved the quirkiness and am glad to see that people can still have a sense of humour when they write something that is helpful.  —Preceding unsigned comment added by 24.230.180.254 (talk) 03:26, 7 April 2009 (UTC)

text: I rewrote the article to actually talk about callbacks and not handling 2012; also, we cannot have a sense of humor - such things inevitably obscure the content. BioTube (talk) 23:34, 3 June 2009 (UTC)

text: Too many platform specific references, ie Linux, Unix.  Needs to be abstracted away from punks/hackers prosaic tendencies and their favorite languages and towards compsci academics.  —Preceding unsigned comment added by 71.15.154.180 (talk) 04:37, 28 July 2010 (UTC)

text: LOL Stevebroshar (talk) 13:58, 11 April 2024 (UTC)
thread_title:  Augh! 

message: sam  —Preceding unsigned comment added by 196.217.165.28 (talk) 18:50, 9 July 2009 (UTC)
thread_title:  <nowiki></nowiki> 

message: Example code now doesn't show a function with a callback in it - it presumes the readeer already has some other window open somewhere showing them the prototype for signal(), which is, I feel, not a safe assumption.
I feel that a comprehensive example needs at least three functions: main(), the function that takes the callback as a parameter, and the callback function itself.
It should not assume anything system dependant, nor more than the most basic of knowledge of the language, and even that should be guessable from knowledge of other languages (printf, rand).
So, I've put up a suggestion, but I'm sure it can be improved on. 24.28.66.63 (talk) 18:49, 17 December 2010 (UTC)
thread_title:  Example code now TOO simple 

message: So you know. --fs 07:16, 19 December 2010 (UTC)
replies: text: Compiles just fine now (for me, at least).  I take it this talk thread could be deleted now.  --rs2 (talk) 21:47, 13 July 2011 (UTC)
thread_title:  Example doesn't compile. 

message: Especially for (very) beginner programmers, I feel that the use of rand() calls in the example functions isn't particularly necessary to illustrate how callbacks work, and might serve to unnecessarily confuse, say, a primary-school CS student comparing their program output to the example output listed. I think rand() calls should be deleted from the functions defined in the example, though it could be left in the first line of main() to illustrate that callbacks can be used with already-present functions as well. In the defined functions, simple integer returns should do. Zbbentley (talk) 21:53, 2 August 2011 (UTC)
replies: text: I think anyone interested in callbacks will know what rand() does. --Byteality (talk) 16:33, 6 January 2012 (UTC)
replies: text: I completely agree with Zbbentley. The less parasitic problems there is to read a given article, the better. Ptyxs (talk) 17:10, 3 August 2012 (UTC)

text: Yeah. The C example is way too complicated. I'm going to simplify it. ... The original comment is from 2011 and no one has simplified it in the past 13 years! Stevebroshar (talk) 13:56, 11 April 2024 (UTC)
thread_title:  Remove rand calls in Example Code? 

message: Needs a link to function pointers  — Preceding unsigned comment added by 203.41.222.1 (talk) 09:26, 30 May 2012 (UTC)
replies: text: Sounds good. Add it. Stevebroshar (talk) 13:53, 11 April 2024 (UTC)
thread_title:  function pointers page 

message: A brief discussion of the new std::function<> class, enabled by the recent C++11 addenda to C++ should be in order, don't you think so ?  
See for instance :  
Ptyxs (talk) 17:07, 3 August 2012 (UTC)
replies: text: To note: std::function objects make it possible to call : 1) a non member function 2) a static member function 3) a functional object 4) a lambda function 5) a non static member function (via std::bind). That is they can refer to any callable entity with compatible signature and are particularly useful to callback.Ptyxs (talk) 08:07, 4 August 2012 (UTC)

text: I don't think the page should (or feasibly could) cover every syntax that supports callback. But, if you must, add an example for C++. Stevebroshar (talk) 13:53, 11 April 2024 (UTC)
thread_title:  C++11 

message: This article goes into deferred callbacks, but it should go further and mention the article on that very concept, futures and promises. — Hippietrail (talk) 16:32, 8 August 2012 (UTC)
replies: text: Well, it's not going to add itself :) IOW A good way to get something done is to do it yourself. Stevebroshar (talk) 13:50, 11 April 2024 (UTC)
thread_title:  Should mention / link to the [[futures and promises]] article 

message: Hey all, not an expert, but learning a lot and wanted to improve this article as I did so. I provided a basic JavaScript example that dovetails into the more complicated (but awesome!) C examples below it. I also re-ordered so that the explanation of differences between synchronous and asynchronous callbacks is made explicit early on. Next comes the implementation list, and finally some concrete examples under "Use". Happy to see improvements on this, leave a note if there are other low-barrier-to-entry examples we should tack on? -- Mattsenate (talk) 01:07, 13 December 2012 (UTC)
replies: text: I just modified/simplified the JS example. It was good, but still more complicated than I think it could/should be. ... FWIW, I find the C example (which may or may not be what it was in 2012) to be poor (far from awesome). I'm planning to work on it, but don't know where to start. Stevebroshar (talk) 13:49, 11 April 2024 (UTC)
thread_title:  Added JavaScript Example, Re-ordered

message: Please avoid using irrelevant concepts in the examples. For example, the python example on this page was,
>>> def my_square(val):
...     """ the callback """
...     return val ** 2
...
>>> def caller(val, func):
...     return func(val)
...
>>> for i in range(5):
...     j = caller(i, my_square)
...     print("{0} ** 2 = {1}".format(i, j))
...
0 ** 2 = 0
1 ** 2 = 1
2 ** 2 = 4
3 ** 2 = 9
4 ** 2 = 16
Why should we assume that the reader knows
* for loops
* the method range
* string formatting (especially in a style quite unique to python)
I have since changed the above to:
>>> def get_square(val):
...     """ the callback """
...     return val ** 2
...
>>> def caller(func, val):
...     return func(val)
...
>>> caller(get_square, 5)
25
Caveat: The example is complex because it demonstrates how callbacks can be implemented to achieve some complex behaviour; however, the program written to demonstrate this still should not include unnecessary concepts and be as simplistic as possible.
The Lua example seems to suffer from this. It seems like it was copy-pasted from some project's source code. Besides concerns about the license of the project, I believe that the program should be stripped down to something as simple as possible, while still demonstrating the behaviour it aims to demonstrate. Can someone proficient in Lua take a look?
NingOTI (talk) 15:29, 9 January 2018 (UTC)
replies: text: Amen (to the desire for simplicity). Thanks for KISSing it.  Stevebroshar (talk) 13:44, 11 April 2024 (UTC)
thread_title:  Do not over-complicate examples  

message: Dear all, 
I don't understand why in the C# section for Callback (computer programming) there is not a mention to delegates, that are a usual way of creating callbacks in C#.
All the best,
--Hgfernan (talk) 11:59, 2 December 2019 (UTC)
replies: text: I agree, it is part of the expected and well-typed way of defining callbacks in C#. Rp (talk) 13:39, 2 December 2019 (UTC)

text: You are not directly asking a question or proposing something. I suggest a more direct approach; otherwise your comment will not result in action. IMO, the best way to get action on WP (any wiki) is to roll up your sleaves and edit. Stevebroshar (talk) 13:43, 11 April 2024 (UTC)
thread_title:  Why not mention delegates in C# ?