in reply to Balancing Complexities of Data Structures, Code and Readability

Heh. Having just finished the chapter in Code Complete on Abstract Data Types over lunch, I've got a few comments for you.
  1. Use ADT's. They will make your life so much easier. And, your code will be more readable and maintainable. (Read on for how!)
  2. Use accessor methods into your ADT. Rip out every single direct access into your data structure(s) and replace them with well-defined, loosely-coupled accessor routines. Things like GetEmailAccounts(), Remove EmailAccount(), and AddEmailAccount(). Your code using this ADT will be very easy to read. It might even become self-documenting!
  3. Put your ADT into a module. Maybe, even an object! Then (and here's the kicker) ...
    NEVER EVER DIRECTLY ACCESS THE INTERNALS!!!
  4. Let me repeat it.
    NEVER EVER DIRECTLY ACCESS THE INTERNALS!!!
  5. If you do, you will be worse off that you are now, cause you'll change the implementation and something will break and you don't know why and you don't know where and you thought you should've had it cause you had these fancy accessors but someone violated the contract! *deep breath*
The point here is data-hiding/encapsulation/all that stuff. Add on well-named and well-defined accessor methods and the only place your data structure is ugly is in the module(s) that define/access it. Sorta like CGI, DBI, or IO::File, if you think about it. Make your own CGI and the people who follow will bless your name one thousand times.

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

Replies are listed 'Best First'.
Re: Re: Balancing Complexities of Data Structures, Code and Readability ... USE ADTs!
by ralphie (Friar) on Aug 11, 2001 at 04:53 UTC
    i like your point ... the combination of style and maintainability that permeates "code complete" had influenced my perception of good programming since i first read it. abstracted a level, it's a work that has pertinence in contexts far removed from programming.