hi guys,

design by contract or aspect-oriented programming.
anyone has used one of the above technique?
in a nutshell, which one is better? in terms of simplicity and usability, which one is a hassle?

I use 'design by contract' all the time. From my perspective it is another way to spell 'test first'. It is a technique for converting requirements into code in a way that makes you think about the actual requirements ("How can I test that the requirement, or 'contract' is met?") before you think about how to write the code. It is a technique of software engineering.

There is another variation in meaning for 'design by contract' which is (more or less) easily available in some languages: You can, or in some cases must, write precondition and postcondition assertions for each block or each function. These assertions are checked when the code runs, and they are the 'contract' that each function must meet: The precondition is what I assure the function it can expect, the postcondition is what the function assures me it has done. From my perspective, this is actually quite similar to 'test first' in the sense that these assertions are in fact tests for that particular block of code, just written inline rather than in a distinct module. Because they are inline and (at least in principle) run with each invocation of the program, they may provide better 'test coverage' than is easy with separate test modules. On the other hand, they don't do much to assure that every logic branch is tested, so you still have to write test code that forces the program through its less traveled paths.

On the other hand, aspect oriented programming is a technique that is (more or less) easily available in some languages. It allows you to consider one or another aspect of the whole program apart from thinking how to actually encode that aspect in each block of code. Using this technique, you can add (or I suppose remove) some feature such as memory checking, logging or some other global concern without actually working through every function and module to insert the code (the aspect oriented coding tool does it for you). It allows you to spend more time thinking about your program at a higher level. I've never liked it, personally, because it seems to me that it causes behavior that I don't understand, and makes thinking about the code (thus: Debugging) more difficult. Perhaps if I used it more, I would be able to use it better.

When will people (especially kids) get it into their brains that there is no overall "best" in any such comparison, only different ways of doing thing each of which might be more or less suitable to specific situations?

It's a sickening phenomenon that seems to be growing ever worse.

commented: Good point +4

thats a nice explanation griswolf. many thanks.
i'm just looking at aspect oriented programming now, and hope to come back for more questions.