samedi 19 octobre 2019

Is this application of Abstract data types in C equivalent to functional programming?

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:

  1. Is this indeed the same as functional programming?
    1. 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.
    2. If no, what is the differentiating factor here?

Code referred from Adam Tornhill's articles on Patterns in C

Aucun commentaire:

Enregistrer un commentaire