DEV Community

Discussion on: Data-Oriented programming: Liberate yourself from objects

Collapse
 
polymathsomnath profile image
Somnath Singh

The main difference between DOP and FP is about how we treat data.

In most FP languages (e.g. OCaml, Haskell), data is statically typed. As a consequence, data access is not flexible. Whereas in DOP, data can be manipulated via generic functions.

For instance, in DOP one could write a function renameKeys that rename some fields in a record. This function would work with any record e.g. a Book or a User.

In traditional FP, one would have to write two separate functions renameKeysInBook and renameKeysInUser and to create two records Book2 and User2 with the new keys.

In traditional FP, field names compile away where in DOP fields are first-class citizens.