While reading Ill Gotten Gains, a book by Leo Katz about financial legal conundrums (almost as much fun as the one he wrote on criminal law), I was intrigued by his discussion of the Shabbos Goy. He brought it up as part of the more general question of what is legal avoidance and what is illegal evasion, citing the Shabbos Goy as one example of people making this distinction in areas beyond the pall of financial law. His analysis of the whole problem was fascinating and I am not doing it enough justice by this two second summary, but he basically said that there are two schools of thought with regard to avoision (the term used for border-line cases). One group, the consequentialists, think that only the result matters- if it is right to steer the trolley to run over one person instead of hitting five, then it is equally right to kill one person and divide his organs among five others (to use his example). Therefore, avoision is always wrong because it reaches unsanctioned results. The other group, deontologists, believe that the path taken is as important as the end- if it is moral to kill one for five in one case, in another it may well be immoral. Avoision, therefore, simply consists of playing within the rules regarding means, and is perfectly alright, even if the means are against some imagined "spirit of the law".
What his argument does not fully explain is the reluctance that people have to engage in avoision. Many people will not, for example, take advantage of a tax loophole, even if available, because it simply feels wrong. I would say that everyone has a hint of the consequentialist as well as the deontologist, not being willing to abuse the system to reach results that are too massively wrong.
Which brings us to halacha. People often have a hard time with the idea of loopholes in Judaism. The example that Katz used of the Shabbos Goy is only one of many examples of this sort of thing- others include the eiruv, selling chametz, 'partnerships' to allow charging interest, and purposely not re-conquering parts of Israel during the Second Temple to allow work in shemitta. The rationale that the gemara usually uses for these things -"the mouth that permits is the mouth that forbade"- works only for Rabbinic commandments. The other major rationale- that G-d knew ahead of time that this loophole would exist and chose to leave it in- gets into tricky debates about pre-destination, not to mention the fact that it doesn't really address the problem that we are getting around a theoretical spirit of the law.
I think that Katz's argument is the best that I have ever heard to explain loopholes. Halacha, is manifestly deontologist- ends are never said to justify means. But what Katz adds is that means can be used to justify the ends. Halacha is all about the morality of actions, rather than about utilitarian calculus of results. If this works to prohibit actions with lofty intentions, then it equally well permits actions with sneaky consequences.
At the same time, the natural inhibitions that we have about loopholes- the feeling of sneaking around G-d- also has basis in halacha, most specifically in the concept of ha'arama (trickery). There are times that a halachic discussion will simply say "Push comes to shove, what is being done is wrong, no matter how you slice it." The example that comes to mind off-hand, and I may be mis-recalling it, is a case where a boatload of wheat became chametz. The gemara asks whether it is permissible to sell this grain to non-Jews, who may sell it to unwitting Jews. After a complex discussion of lifnei iver, lifnei d'lifnei, safek, etc, one Amora says "What you're actually doing is tricking Jews into eating chametz. Whether that is technically whatever is unimportant."
The section in Katz's book interested me so much for two basic reasons-firstly, that it cast a light on a basic question in morality as well as halacha, and secondly, because much of the reasoning and questioning that it had done had already been considered in halachic sources. I bring this all down as one humble example of the usefulness of incorporating secular wisdom into halacha, and particularly viewing halacha as wrestling with many of the same problems as any other legal code.