index

means: context


struct Song { 
  Lyrics   lyr_; 
  Rhythm   rhy_; 
  Image    img_; 
  Notes  notes_; 
  string filename_; 
};
Don't use global variables. Instead add data to an isolated context-- a repository of information a code module might need, allowing few arguments and decoupled code.

In a way, a module is defined by the particular context it requires:
Show me your flowcharts and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowcharts; they'll be obvious.[ The Mythical Man Month]

Collecting data in a context avoids global conflicts, simplifying issues like opening a new document, or having many projects open at once.

Keep contexts modestly-sized. Extend with an appendix.

Factor into sub-contexts. High-level contexts for aggregate modules consist of the sub-contexts required to get the job done.

Bad programmers worry about the code. Good programmers worry about data structures and their relationships.[Linus Torvalds: https://lwn.net/Articles/193245/]

A few specific flavors worth noting:

const


void apply(const Context&);
A read-only context. If your code can use this, it absolutely should. Downstream users and coders can't accidentally change something with bugs or misunderstandings.

pod


"plain old data"-- memcpyable. (C++_Common_Knowledge p.38)
struct DataHeader { // pod 
  uint id; 
  int  numTimes; 
  doub radius; 
}; 

struct Data { 
  DataHeader         header; 
  vector<Trombones*> trombones; 
  void copy(Data*dest) { 
      memcpy(&dest->header, &header, sizeof(DataHeader)); 
      dest->trombones.resize(trombones.size()); 
      for (sz_t i=0; i<trombones.size(); ++i) 
        dest->trombones[i] = trombones[i]; 
  } 
};
"Plain old data" can be handled in fast, useful ways that aren't generally ok. Factoring out the pod sub-context lets you take advantage of that systematically.

apdx


Sometimes there are things you don't usually need:
struct SongAppendix { 
  Metadata     metadata; 
  vector<Song*> similar; 
  vector<Link*>   links; 
}; 

struct Song { 
  Lyrics   lyr_; 
  Rhythm   rhy_; 
  Image    img_; 
  Notes  notes_; 
  string filename_; 
  SongAppendix apdx; 
};
Factoring out optional additions keeps the core idea clear.

nedwaves.com 2017 [171108]