Unconfigured Ad Widget



No announcement yet.

Disappointment (Again)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Disappointment (Again)

    This the second manual I've purchased from MC Press that frustrates my purpose; i.e. I have a need to expand my technical knowledge so I can either be more valuable to my current employer or my next one.

    As an example, on page 124, this excerpt (with regard to create_function()):

    "Technically, the created PHP function has a name, but because the name starts with a null character, it's unlikely you'll ever declare a function with the same name. You can pass these lambda-style functions as variables and also use them as callback functions."

    "Examine the following code carefully, it can be easy to get lost in it."

    function calFunction($callback) { echo $callback(2, 3); }
    $func = create_function('$a, $b', 'return $a * $b;');
    "Here is the resulting output:"

    Where do I begin?

    The authors didn't feel the need to explain ANYTHING about this convoluted piece of code. Isn't that their function, to explain this stuff to the novice? The parameters passed to create_function() are 2 single-quoted strings. Are 2 strings the maximum? Does the 2nd (or last) one always start with 'return'? Why the use of the variable name $callback in the function callFunction? Is that significant or required or just descriptive? (And where was the null character they mentioned?) OK - $callback contains $func which contains a function, but still... They provide no context. When and where and why would I use this type of construct? The authors just throw this stuff on the page and warn me about getting lost in it? Are they just being lazy?

    Mike Faust's "SQL Built-In Functions and Stored Procedures" was EXACTLY the same kind of waste of my time and money. If I only want the syntax, I can look it up on the web. I buy these books because I want to UNDERSTAND. I want an author who realizes he's 'speaking' to an audience (me!) that DOESN'T already know this stuff and one who has the teaching talent to explain it well.

    I may just be exposing my slow-wittedness here but I'm very disappointed (again).

  • #2

    Thanks for taking the time to provide some feedback. To address your concerns, we felt that it best in this case to provide a simple code sample. Then the user is left to test it out, modify it. Thereby gaining a much better understanding of how the code works than if we attempted to provide a lengthy detailed description of the "create_function" function. Also, in the process of writing a book the decision has to be made on what to include and what to exclude. The "create_function" functionality, while important, is a more advanced technique and not something you will probably be using right out of the gate.

    To answer your question.

    The first four lines of the sample code are just a normal function that happens to be called "callFunction". $callback is the parameter being passed to the "callFunction" function (in this case the $callback variable will contain a created function name (e.g. the lambda-style name starting with a null character). All that the "callFunction" function is going to do is call the lambda-style function and "echo" the returned results; in the case of the example code: "6".

    function callFunction( $callback )
    echo $callback(2, 3);

    The following line defines the lambda style function and its parameters. The last line calls the "callFunction" function and passes the $func variable which contains the name of the function created on the previous line (again with the lambda style name starting with the null character).

    $func = create_function('$a, $b', 'return $a * $b;');

    So the created lambda style function has two parameters ($a and $b). All the function does is multiply the two parms (e.g. $a * $b) and return the result to the caller.


    Jeff Olen


    • #3
      On a separate but related note, PHP functions and classes (OO) are notoriously the most difficult parts of PHP for RPG developers to grasp. Don't dispair. There are plenty of us out there who have made the transition and are happy to help a fellow RPG developer. :-)



      • #4
        Cooler Head

        As I replied privately to Jeff, a big part of my frustration comes from having to choose from the mountain of languages, tools, envirmonments, etc. out there, in order to stay 'relevant' (which is to say 'employed'). Couple that with my natural laziness and stupidity and you can see how I'd get frustrated as I struggle to learn and grow.

        Again, thanks, Jeff, for your quick response. I return to your book with new hope and energy.

        Long live RPG-ILE on the i! (Sorry, just had to say, and pray, it.)