|go ahead... be a heretic|
Avoiding compound data in software and system designby metaperl (Curate)
|on Apr 20, 2010 at 21:36 UTC||Need Help??|
That's like asking for the chocolate back after you've made chocolate milk!
This post concerns a tragedy in API design. While it is often convenient to have your API receive compound data, it is a bad idea.
What is compound data?A compound datum is an apparently atomic data item that it really not atomic. Here are two examples of API tragedy:
The first argument to connect is compound data. It is a single string argument, but it contains important subelements:
so what?well, take a look at register_db API, it expects you to supply things like "mysql" and "host" in separate parameters:
So, what happens if you've been using DBI and you have all your connect data in configuration files with DSN strings and then you decide you want to start using Rose::DB::Object? You have to find some way of getting the chocolate back from chocolate milk --- you have to break down the compound data in the dsn in order to get out the sub-elements.
DBIx::DBHDBIx::DBH was written long ago to address this issue. You supply the sub-elements of the dsn and it forms the compound data for you.
HTML::ZoomHTML::Zoom is a promising push-style templating system developed by Matt Trout. Let's take a look at how you select an HTML tag with id equal to "hithere":
So "hithere" is compound data. The octothorpe is shorthand for id and "hithere" is the value of an id... that's two things packed into a single scalar.
suggested non-compound top-level API call
and similar to class lookdowns, etc.
The HTML::Element look_down() method had an excellent non-compound approach.
That being said, the current API meshes well with the jQuery API and it also intuitive for web designers, so there are definitely some reasons for why it is OK.
Relational Database DesignI dont have the time to get into all the terrifying ways that people overload single columns with compound data
Directory TreesIf you see a directory structure like:
you have compound data, which you need to "normalize" via bugs/old, bugs/new, bugs/closed
conclusionI hope this post helped someone. Typically people either know this and dont need to be told or they dont know it and dont care :)
The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.
-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"