The Artima Developer Community
Sponsored Link

Prescriptions, Proscriptions, and Prognostications
Contract Enforcement for humanity ... ?
by Matthew Wilson
April 30, 2005
Summary
Should individual human beings, and humanity's institutions, adopt the principles of contract programming, and use contract enforcement in their own functioning? Would that lead to a better world?

Advertisement

If for no other reason than I've been digesting too much right-wing media and too much left-wing literature of late, and at the same time working on a treatise on The Principle of Irrecoverability as part of a new, gargantuan, instalment of my and Bjorn Karlsson's Smart Pointers column entitled "The Nuclear Reactor and the Deep Space Probe", I had cause to wonder this morning whether humanity's accelerating decline could have been avoided, and might yet be arrested, if we used contract programming principles and practices.

Now I'm clearly not talking about people experiencing unrecoverable exceptions leading to process termination if they make a faux pas at a dinner party:

  "Who's that hideous creature over there?"

  "That's my husband/wife/mother/etc.!"

(Incidentally, though that's an urban myth, I have a friend who actually did this, to much consternation and posthumous merriment.)

But it seems we humans have parallels in our individual and collective behaviour to the neophyte programmer. When writing code, new programmers write what they think will work, expecting it to work. Contrast this with the seasoned programmer who writes out the interface, and then codes the implementation expecting it to fail, and who therefore codes in constraints and verifications (discussed at length in Chapter 1 of Imperfect C++ :-) ) to trap the failures.

Like the neophyte, human beings and, especially, human organisations, are almost entirely reactive when it comes to error. Consider the corrupt public sector worker who gets big bribes for being helpful to big business, the insider-trader, the quietly genocidal doctor, the truck driver pressed into amphetamine use to meet otherwise impossible deadlines who ends up causing carnage on the roads, airport baggage handling systems at airports that facilitate the unwitting use of innocent passengers as drug mules, the software engineer who checks things in without a care (or a unit-test, or even a successful compilation), peodophiles allowed in positions of power and influence over children, etc. etc. etc.

Each of these systems should have failure built-in and expected. But they don't. They're reactive.

So here's a radical idea. Let's accept that underlying all differences in human institutions - political, religious, economic, social, commercial, etc - is the fundamental attribute of human nature: Optimistic Nonchalence. To be sure, this is both our strength, as it allows us to march forward in the face of adversity, complexity, futility and, er, death, and also our weakness, as it means we have, as we say in Australia, the "She'll be right" attitude that assumes everything's going to be ok and if it's not someone else will come along and fix it for us.

Let's accept that that's how we're evolved/designed, and do what the seasoned programmer does: expect failure. Indeed, we have a latent capacity for anticipating negative consequences; As any parent will tell you, every possible permutation of damage to one's children flits through the mind in every circumstance. Let's harness that, celebrate it, institutionalise it. This is not a negative/pessimistic thing - remember, the seasoned programmer expects to create successful components, but has the wisdom and experience to realise that this success is hard won. Code that contains enforcement of contracted behaviour is far more robust than that coded on a wing and prayer. Let's start putting the asserts into real life. Discuss....

Afterrant

Of course, I might just be completely nuts. It is very early in the morning. :-) )

Talk Back!

Have an opinion? Readers have already posted 5 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Matthew Wilson adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Matthew Wilson is a software development consultant and creator of the FastFormat, Pantheios and STLSoft libraries. He is author of the books Imperfect C++ (Addison-Wesley, October 2004) and Extended STL, volume 1 (Addison-Wesley, 2007), and is currently working on his third, Breaking Up The Monolith: Advanced C++ Design Without Compromise. He has published over 60 articles on C++ and other topics, and has served as columnist and contributing editor for C/C++ Users Journal. Matthew believes that code should be discoverable and largely self-documenting, and lives up to that by being a hopeless documentor. He can be contacted via http://www.imperfectcplusplus.com/ or stlsoft@gmail.com.

This weblog entry is Copyright © 2005 Matthew Wilson. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use