Premature Serialization

Coder: My program has a big tree in memory, and it must send this tree to a module that is unaware of my data objects, and might be in a separate memory arena. What shall I do?

Alleged Guru: Read the XML propaganda, my child. It discusses the miracle of interoperable data formats. You may write your writer in the one program, and write a reader in the other program, and your data will be flexible. And we may someday put this XML into a file, or cast it out upon the 'net.

See PrematureComplexity. Contrast InspectEvalFileFormat.

(In this situation, the correct fix is to pass the friggin' tree.)

The DesignSmell "too many strings", "too much string parsing" and "why do these strings have private members?" leads to the PS diagnosis.


"In this situation, the correct fix is to pass the friggin' tree."

Does that mean the correct thing to do is not use non-XML serialization? Or is all this stuff happening within one memory space, making serialization unnecessary? (I can't tell if this is anti-XML advice or anti-complicated-interfaces advice.)

It is advice against doing this (in an arbitrary C++ like language):

  struct
    int x
    int y
    double z

string << q.x << ':' << q.y ':' << q.z; passToAnotherModule(string);

Ultimately, the other module could perform "switch on type code". A case for mature generalization.

EditText of this page (last edited May 8, 2003) or FindPage with title or text search