From: Martin DeMello Date: 2005-04-26T20:14:30+09:00 Subject: Re: Managing complexity and untangling my thoughts Hal Fulton wrote: > > As one of the slides indicates, part of my confusion is different > ways of thinking about what a "note" is. > > Sometimes I perceive it as: > - an object of a certain class > - the actual text of the note > - the text plus its metadata > - the YAML'd version of the text+metadata > - the key used to look up the record in the db > - the text field in which the text is displayed > - the parent widget to which that text field belongs > - or something else. > > I like the idea of composing an object of smaller objects -- > for example, store all the GUI stuff in note.widget or > note.gui or something. > > But then (among other complications) the note has a title > (note.title) which is also stored in the GUI (note.widget.title) -- > these must be kept in sync. :/ And so on. > > What are your mental (or other) tools for dealing with this sort > of complexity? My most valuable mental tools are 1. Once and Only Once: Every bit of data should have a unique place in which it is stored. This should be the definitive source if you need to replicate it elsewhere. 2. Bottom Up Programming: Most clearly championed in Paul Graham's On Lisp, I think, but essentially you grow your language up to meet your problem 3. Don't Repeat Yourself: Not always easy to follow in practice, but Ruby helps a lot. In this specific instance, I'd start with the bare data - the text of the note and any intrinsic (i.e. not related to the database as a whole) metadata. Have a small class to store those. Then add methods to output the data in a variety of formats, and parse a variety of formats to get that data (essentially accessors). Then start thinking of extrinsic properties (containers, parents etc) and actual GUI frontends. As an example, your note title is part of the intrinsic metadata, and would be stored in your note class. The GUI would need to query the note for its title, using an accesor like #title Note that storing extrinsic data like a parent inside a note can be problematic - I'd recommend having a TreeNode class containing a note, and storing the parent in that. martin