With the following code
typedef struct Customer* CustomerPtr;
typedef struct Order* OrderPtr;
CustomerPtr createCustomer(const char* name, const Address* address);
void destroyCustomer(CustomerPtr customer);
void placeOrder(const CustomerPtr customer, const OrderPtr order);
the placeOrder
function is only dependent on the input parameters, and if Customer
and Order
do not have side-effects, then it appears to be a pure function.
I have the following 2 questions based on the observation:
- Is this indeed the same as functional programming?
-
- If yes, then are there any patterns from functional programming that might be available for implementation in this straightforward fashion?
I would like to avoid function composition using function pointers as it makes the code feel quite unreadable. - If no, what is the differentiating factor here?
- If yes, then are there any patterns from functional programming that might be available for implementation in this straightforward fashion?
Code referred from Adam Tornhill's articles on Patterns in C
Aucun commentaire:
Enregistrer un commentaire