§ January 12, 2009 06:52 by beefarino
I want to refactor some code to a strategy pattern to isolate some complex authentication procedures, rather than have hard-coded behavior that prevents unit, load, and performance testing. I just had a very frustrating discussion about it ...
Developers talk about their code as if it were people all the time. I do it, you do too. Most of the time it's harmless, as in this little quip I said this morning:
"So when the service wants to authenticate the client, it will ask whatever authentication strategy is available."
Everyone in the conversation obviously knows that the application isn't capable of wanting or asking, and that these are metaphors to hand-wave over the technicalities of calling on an object. No harm done; but consider the reply:
"But how would the service know that the client was really authenticated unless it does the work itself?"
Both examples show a kind of anthropomorphism ( like when your car won't start because it's upset with you for not changing its oil, or that your laptop doesn't like the couch because it won't connect to your wireless network there ). Wants and asks describes dependencies and actions of the software - in short, the software's behavior. Know attributes a conscious state to the software - that it somehow can understand the difference between doing some work and calling someone else to do the same work, which is nothing short of a direct demotion of a functional requirement ( the service MUST authenticate all clients ) into a software implementation ( this class MUST contain all authentication code ).
There is no homunculus in the software. There is no little dude sitting in a virtual Cartesian Theater watching the bits fly by and getting upset when things don't happen the way he thinks they should.
Software doesn't know anything. Software does whatever it is told to do. If the service contains the authentication code, or if it delegates to a strategy that performs the same action, the behavior is the same. Given that, if the former is prohibitive to testing, I say do the latter and test my heart out!!