View Poll Results: Which style to provide?

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

    0 0%
  • Callback

    1 100.00%

Thread: Pump Versus Callback: A Gentleman's Dilemma

  1. #1
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108

    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
    5,108
    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, 02:42 PM
  2. message pump code for COM STA
    By George2 in forum Windows Programming
    Replies: 0
    Last Post: 04-10-2008, 08:19 PM
  3. COM message pump
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 03-29-2008, 02: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, 04:28 PM