Welcome Guest, Not a member yet? Register   Sign In
Functional PHP Extension
#10

[eluser]sophistry[/eluser]
@Jamongkad - thanks for the new sample code. however, i am having a hard time understanding the benefits of adopting this coding paradigm.

the revised example you offer above shows the lambda function defining a new function that is essentially a (less functional, less clear) display output function like this:
Code:
function label_new_if_today($date, $date_format="Y-m-d", $label="(New Project)")
{
    return ($date === date($date_format)) ? $label : null;
}

being the developer of the FP library for PHP, i'm sure you are familiar with many of these arguments... but i'll lay out a few anyhow.

first of all, this function has a name - it should be clear to everyone who reads it. the string in the lam() function has to be studied to understand what it does.
second, it has parameters with defaults that are spelled out - what if i wanted to abstract that lam() function so that it could do a string compare on a different date format?
third, this function will be recorded in function_exists().

other issues...
there are many problems when you embed PHP code in a string - the most important immediate effect is that you lose the syntax.
you also lose the ability to reuse your function in another scope. the function is also hidden inside code.

in this case, defining a real function is better overall - i don't think you could convince anyone to adopt lambda functions to allow inline function creation based on string output function.

it seems to me that there must be a more compelling example for adopting FP than string output and concatenation...
maybe something that dramatically shifts the coding architecture?
some better way of working in teams, splitting up large problems?
making unit testing easier?
maybe there is a particular problem domain where FP is better suited? maybe an event-driven system?

sorry to be a pest, but you seem like a smart coder and i'd like to know what you are thinking.


Messages In This Thread
Functional PHP Extension - by El Forum - 07-06-2008, 08:30 PM
Functional PHP Extension - by El Forum - 07-06-2008, 11:59 PM
Functional PHP Extension - by El Forum - 07-07-2008, 12:15 AM
Functional PHP Extension - by El Forum - 07-07-2008, 12:48 AM
Functional PHP Extension - by El Forum - 07-07-2008, 12:58 AM
Functional PHP Extension - by El Forum - 07-07-2008, 01:20 AM
Functional PHP Extension - by El Forum - 07-07-2008, 01:44 AM
Functional PHP Extension - by El Forum - 07-07-2008, 07:51 AM
Functional PHP Extension - by El Forum - 07-07-2008, 07:55 AM
Functional PHP Extension - by El Forum - 07-07-2008, 08:32 AM
Functional PHP Extension - by El Forum - 07-07-2008, 09:53 AM
Functional PHP Extension - by El Forum - 07-07-2008, 10:15 AM
Functional PHP Extension - by El Forum - 07-07-2008, 02:42 PM
Functional PHP Extension - by El Forum - 07-07-2008, 07:27 PM
Functional PHP Extension - by El Forum - 07-07-2008, 10:19 PM
Functional PHP Extension - by El Forum - 07-07-2008, 10:53 PM
Functional PHP Extension - by El Forum - 07-08-2008, 09:10 AM
Functional PHP Extension - by El Forum - 07-08-2008, 11:21 AM
Functional PHP Extension - by El Forum - 07-08-2008, 06:33 PM
Functional PHP Extension - by El Forum - 07-08-2008, 07:02 PM
Functional PHP Extension - by El Forum - 07-10-2008, 11:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB