in reply to Object functionality?

Write your tests first. If you do that, it will become obvious how your API should work, and you'll adjust your tests until they look and feel right.

Seriously, it sounds strange, but it really works well. Try it.

Replies are listed 'Best First'.
Re: Re: Object functionality?
by demerphq (Chancellor) on May 10, 2002 at 15:21 UTC
    Seriously, it sounds strange, but it really works well. Try it.

    matts++

    Better advice rarely given. I did this too and it paid off big time.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

      Anyone have any links to good tutorials on how one goes about using this approach? I mean it sounds like a fine idea, but (not being a CS type myself) I wouldn't know where to begin....

      ..Jon

      Update: OK, so I guess the answer (thanks to demerphq++) is to look up the Test::More module. THanks!

        Well I dont have links but I can make some suggestions.

        If you're writing a module you must have some idea of what you want it to do and how you are going to call its functions/methods/procedures. From that point its just a matter of painting a picture as it were. So for instance I knew for Data::BFDump that I was going to implement the Data::Dumper interface, but with different output. So I sat down and wrote a bunch of tests. Something like this:

        use Test::More qw(noplan); use Data::BFDump; is(Data::BFDump->Dump([1..10]),"( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )","Ba +sic list"); is(Data::BFDump->Dump([\1]),"\do{ my $t=1 }","Scalar Ref");
        And so on. Thus you put down what and how you'd like to call a routine and what youd like it to return. If you dont actually have the functionality then you wrap it in a TODO like so:
        TODO:{ local $TODO="Not implemented yet"; is(Data::BFDump->Dump([1..10]),"( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 )"," +Basic list"); is(Data::BFDump->Dump([\1]),"\do{ my $t=1 }","Scalar Ref"); }
        As you build up more an more tests you also build up more and more functionality.

        Oh, a little note: Some changes you make will break every test that you came up with. Thats ok. Just go through and make sure the results are what you want and change the expected results. But keep the tests. The more the better.

        Yves / DeMerphq
        ---
        Writing a good benchmark isnt as easy as it might look.

        A not so bad idea is to simply do a Google search for unit tests, and browse around there for a while. Also, check up on any stuff by Martin Fowler (especially Refactoring) and Kent Beck. Furthermore, http://www.junit.org/ is a veritable gold mine for unit testing, although most things there are exemplified in Java, it shouldn't be hard to follow. It probably would if it was the other way around though. :)
        You have moved into a dark place.
        It is pitch black. You are likely to be eaten by a grue.
        Mike Schwern of P5P testing fame has a Wiki site which contains quite a good intro to the testing modules.
Re: (Buzzcutbuddha - Explain Why) Object functionality?
by buzzcutbuddha (Chaplain) on May 10, 2002 at 18:28 UTC
    Writing the tests first is an excellent way to get a handle on how your objects should work, but I think newbie monks especially, and those unfamiliar will benefit from more information about Extreme Programming, as that is the origin of the whole idea of writing your tests first, and Unit Testing.

    See Demerphq's post below, as well as the 'official' site for more information.
      I don't think XP was the point of origin for either writing tests first or unit testing, as I have worked with teams where both practices were followed long before XP ever came on the scene. XP more or less just subsumed and/or modified many practices that its originators felt were the good ones under the umbrella namespace of Extreme Programming. Not that that detracts from XP or following the link you provided for more info.
      I don't know where you get your information, buzzcutbuddha, but I was writing tests before functions and unit testing my pieces long, long before I'd heard of "Extreme" anything. XP may advocate these practices, but it is not their origin.
        I stand corrected.

        I had not heard of Unit Testing prior to reading about Extreme Programming, and so many XP advocates tout that as one of their strengths that I made an assumption, which as we all now, is a Bad Thing. I should have known better.
      Extreme Programming ... they should call you buzzwordbudha ;)