Portál AbcLinuxu, 30. dubna 2025 12:59
"I've gone back and forth multiple times between functional practices and OO practices, and I definitely empathize with the confusion going in both directions. You trade one problem for another, and in the end there really is no free lunch." I think there is a strange kind of duality between OOP and FP. I think OOP passes structures of objects hidden behind interfaces, while the FP passes composed functions in other direction. So you can convert your OOP code to FP code almost mindlessly by total "inversion of control" - wherever you pass an object somewhere (making a call), in FP you pass the operation from the callee to the caller instead. And I think it's this duality that you observe in practice. However, I believe there is a practical difference between the two, which makes FP superior despite being harder to understand initially. It's much easier to spot that you're doing "no-ops" in FP than in OOP. In OOP, often you pass the objects unchanged across layers, while in FP, this manifests as identity functions being used. And it's easier for both human and compiler to remove these redundant identity functions (through function specialization and things like fusion etc.). Also, I believe functional approach allows you to better realize that there are some algebraic laws governing your problem domain. It's really kind of like in mathematics, when you come from point-wise understanding of functions to functional understanding of functions, more insight is gained.Docela by se mi libilo, kdyby se nekdo z tech zajemcu o OOP systemy zamyslel nad touhle dualitou (a vubec jestli existuje) a pak nejak formuloval lambda kalkul, ktery odpovida jejich oblibenemu OO modelu. Bylo by to myslim zajimave srovnani. (Je pomerne dobre zname, ze existuje korespondence mezi ruznymi kalkuly a vypocetnimi modely.)
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.