in reply to OT: Data Structure First or Code First?

Which comes first data structure or code?

Neither. Write a unit test first. I'm serious.

Starting with a real client, even if it's just a test, forces you to focus on the interface. Once you've got the client interface thought through, work from interface into data structures.

If you start from the data structures, you risk influencing the API from the data structures, rather than from a client perspective. Many unusable messes are made this way.

  • Comment on Re: OT: Data Structure First or Code First?

Replies are listed 'Best First'.
Re: Re: OT: Data Structure First or Code First?
by jerrygarciuh (Curate) on Mar 29, 2002 at 21:19 UTC
    I'm looking around for what a unit test is...help me out? Are you suggesting that I develop the interface which will insert the data first?
    TIA
    jg
    _____________________________________________________
    Think a race on a horse on a ball with a fish! TG
      A unit test exercises an API and verifies that it returns correct values for correct inputs, and handles incorrect inputs correctly. In your case, I'm guessing that your API will produce an HTML table given (at least) a date.

      A simple unit test might feed that API several dates, comparing the resulting HTML to known-good reference copies.

      To make this work will probably require that you get your data access abstraction right, so that you can pass a stubbed database in for testing purposes. Or, you can structure the calendar object such that it's populated by a separate agent. Use a dummy agent for populating with test data, and a real agent (which you write separate unit tests for) for accessing the database.