Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: Programming is combat

by BrowserUk (Patriarch)
on Jul 08, 2004 at 17:50 UTC ( [id://372881]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Programming is combat
in thread Programming is combat

I'm still to be, and don't expect to be, convinced of the value of \t directory and Test:* modules.

Don't misread that. I'm strong on tests and testing. It is the only tool short of suck-it-and-see that we yet have for trying to establish the quality of the code we produce.

The problem with those modules and the \t directory is that they rely on tests external to the code. Out of site, out of mind. Tests should be integral with the code where they may be maintained along with the code. You can have all the tests in the world but if they are testing the wrong things they are little more than overhead.

In an ideal world, the tests would be generated automatically by the compiler thereby removing the possibility of the tests and the code becoming out of sync, but that is still a ways off.

Design by contract shows great potential (IMO). I had hoped that something similar would be integral to P6, but I haven't seen any signs of it. I'm hoping that the (proper) macro facility will allow this to be added in fairly short shrift after the fact. Time will tell.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^4: Programming is combat
by TimToady (Parson) on Jul 08, 2004 at 20:28 UTC
    DBC is integral to Perl 6. If you google for "design by contract apocalypse perl", you'll discover that it's even been mentioned in discussions here on PM.

      Indeed. Sorry for having disseminated FUD. My only defense is that it had been a while since I read Apo4 and I had forgotten about PRE and POST blocks.

      One question that I couldn't answer from my (quick) reappraisal of Apo4. Is there any intent that PRE & POST blocks will be "turn-offable" (with apologies to the BG ads) via command line switch or other similar mechanism?


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
      "Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon
        Certainly, that's one of the reasons we later separated them out from FIRST and LAST blocks. In any event it'd be pretty easy to redefine the grammar to make them no-ops.
      DBC is integral to Perl 6

      Since the subject's come up ;-)

      PRE and POST will obviously handle pre-/post-conditions for methods. However - I've not spotted an easy way of expressing class invariants. Is there something that I've missed?

      Also, there do not appear be a built ins for dealing with naming conflicts as there are in languages like Eiffel. How would I rename method foo() to bar() in a sub-class and keep the pre- and post-conditions?

      Disclaimer: I've still not read A12 properly, so apologies if the answer is in there and I missed it when I skimmed it :-)

        It should be possible to do class invariants one way or another. Perhaps we could just say that any PRE and POST properties on the class itself automagically get attached to any methods defined in the class.

        As for naming conflicts, A12 does talk about that some in the context of Roles, but similar reasoning applies to inherited methods. In general, renaming violates Liskov substitutability, so we discourage (but do not prevent) that approach in favor of distinguishing via multiple dispatch where possible, and use of a switch method where not. But in cases where renaming is used, it'll be important to make sure the correct PRE and POST are called at each level. If renaming is done simply by a wrapper method in the derived class, this will happen automatically, I suspect.

        Nonetheless, if you're changing the contract of a class, you probably ought to consider delegation instead of inheritance. And the delegation mechanism certainly has plenty of hooks for renaming.

Re^4: Programming is combat
by adrianh (Chancellor) on Jul 09, 2004 at 16:42 UTC
    The problem with those modules and the \t directory is that they rely on tests external to the code. Out of site, out of mind. Tests should be integral with the code where they may be maintained along with the code

    Test::Inline?

    You also might find the idea of Zero Button Testing appealing.

    Personally, I find having the code and the tests in the same document gets in the way of reading the code and interferes with refactoring, but YMMV.

    You can have all the tests in the world but if they are testing the wrong things they are little more than overhead.

    Doctor, it hurts when I do that :-)

    In an ideal world, the tests would be generated automatically by the compiler thereby removing the possibility of the tests and the code becoming out of sync, but that is still a ways off.

    I see people asking for this sort of functionality a lot and it confuses me. I must be misunderstanding what you mean since, on the face of it, what you're requesting seems to be impossible. How would the magic test producer know what the code should do.

    Design by contract shows great potential (IMO)

    Interestingly enough DBC used to be my preferred design methodology, before I discovered TDD (Eiffel is still one of my favourite languages). Because you're dealing with concrete data rather than an abstract contract I find it much easier to incrementally develop code with tests.

      Don’t forget specification-based testing à la tmoertel’s Test::LectroTest (which he talked about in RFC: Tutorial on Testing). I’ve tinkered with it some; when it fits the kind of unit being tested, it’s spectacular.

      Makeshifts last the longest.

        Don't forget specification-based testing à la tmoertel's Test::LectroTest (which he talked about in RFC: Tutorial on Testing). I've tinkered with it some; when it fits the kind of unit being tested, it's spectacular.

        I agree that it's is useful stuff where it fits, but to be honest I don't find it fitting that often :-)

        The trouble I have applying specification based testing is that, like design by contract, it's tricky to apply incrementally. Personally I find TDD and specification based tests a bad fit since I now code in small increments, and specification based tests are very much all-or-nothing.

        Specification based tests are certainly a useful tool, but I don't find myself reaching for it very often.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://372881]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-03-28 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found