View Poll Results: Which style to provide?

Voters
1. You may not vote on this poll
  • Iterative

    0 0%
  • Callback

    1 100.00%

Pump Versus Callback: A Gentleman's Dilemma

This is a discussion on Pump Versus Callback: A Gentleman's Dilemma within the C++ Programming forums, part of the General Programming Boards category; ^_^ Admit it! The title totally had you curious. In any event, I'm looking for opinions on something for my ...

  1. #1
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,406

    Pump Versus Callback: A Gentleman's Dilemma

    ^_^

    Admit it! The title totally had you curious.

    In any event, I'm looking for opinions on something for my library code. Again.

    This time it is the iterative processing approach versus a callback based approach.

    As usual, I could do either; this is simply about harvesting opinions so that the default approach feels comfortable to the widest audience.

    I'll show the iterative processing approach first.

    Code:
    // ...
    struct SomeData;
    // ...
    
    // ...
    SomeData lSomeData;
    // ...
    
    // ...
        while(lResult = DoSomething(lSomeData))
        {
            if(lResult == MOREMEMORY)
            {
                // ...
                // Expand memory allocation associated with `lSomeData'
                // for use by `DoSomething'.
                // ...
            }
        }
    // ...
    Now I'll show a callback based approach.

    Code:
    // ...
    struct SomeData;
    // ...
    
    // ...
    bool MyProcessSomeData
    (
        SomeData & fSomeData
      , NIdentifier fReason
    )
    {
        if(fReason == MOREMEMORY)
        {
            // ...
            // Expand memory allocation associated with `fSomeData'
            // for use by `DoSomething'.
            // ...
        }
    }
    // ...
    
    // ...
    SomeData lSomeData;
    // ...
    
    // ...
    DoSomething(lSomeData, MyProcessSomeData);
    // ...
    Soma

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,406
    I got a message which noted that a client defined transform from iterative to callback would be significantly easier than the opposite transform.

    That's a strong argument for the iterative approach.

    I honestly hadn't considered that; once again I'm too close to see something so obvious.

    Thanks for that.

    I'm open to other arguments if any would offer one.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. solar pump switch
    By kian in forum C Programming
    Replies: 4
    Last Post: 07-23-2011, 03:42 PM
  2. message pump code for COM STA
    By George2 in forum Windows Programming
    Replies: 0
    Last Post: 04-10-2008, 09:19 PM
  3. COM message pump
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 03-29-2008, 03:52 AM
  4. Don't Pump Gas on May 15th
    By Queatrix in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 05-04-2007, 05:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21