4 ms·
> I understand the value of referential transparency and how it makes "certain" things easy, but saying that it automatically makes testing functional code easy
by sedachv 10y ago
> I understand the value of referential transparency and how it makes "certain" things easy, but saying that it automatically makes testing functional code easy is a myth. Sometimes it does, sometimes it doesn't.
> And because of that, functional code is often very tedious to test.
Your argument rests on a fundamentally wrong assumption. Expressions in functional programs do not have to be (and indeed are almost never) referentially transparent. Just consider global or module-level immutable variables. Those function names? Also not referentially transparent. This goes all the way back to free variables in the lambda calculus: https://en.wikipedia.org/wiki/Lambda_calculus#Free_variables https://en.wikipedia.org/wiki/Lambda_calculus#Free_variables
Further, dependency injection is a completely idiotic and broken pattern and IMO the worst thing to come out of object oriented programming. Once you have dynamic scoping (surprise! also not referentially transparent) everything that DI does (and much more) becomes trivial.
- Jweb_Guru 10y agoMy own opinions on the matter aside, I don't fully understand why anyone who likes dynamic scoping would dislike dependency injection.
- sedachv 10y agoBecause of things like: https://github.com/google/guice https://github.com/google/guice 4k LOC of "lightweight" garbage for... variable lookups?
- nickpsecurity 10y agoTo put that into perspective, the Squeak interpreter for the gold standard of OOP languages, Smalltalk, was about 3951loc of Smalltalk for logic to handle language and 1681loc of C for OS interface. A lightweight scheme for dependency injection took them more loc to express than a whole Smalltalk interpreter. And to hack around bad OOP or tooling in the first place. This might not mean anything. It just jumped out in my brain for some reason.
- Jweb_Guru 10y agoSo your issue is with the implementation? I can understand that, I guess. Personally I don't like either dynamic scoping or DI; it had just never occurred to me that someone might prefer one to the other.