Difference: ProgrammingNotes (10 vs. 11)

Revision 1128 Mar 2003 - TobyCabot

Line: 1 to 1
 
META TOPICPARENT name="TechTips"
(back to TechTips)
Line: 31 to 31
 Merge means that you note the version of the row that you read and fail on the write if that version has changed in the mean time. This is something like CVS's approach - it works well when there are few collisions but requires some conflict-resolution logic to really work well.
Changed:
<
<

Normalization Isn't Just For Databases

>
>

Normalization - It Isn't Just For Databases Anymore

In database terms, normalization is the process of removing duplicate information from schemas so that they are more internally consistent. After all, if the same piece of information appears twice in a database there's some chance that the two values will become inconsistent with one another, whereas if there's only one it's always consistent with itself. Normalization applies to other areas of programming as well. One project I worked on had a data structure that contained a person's birthday, age, and a code that represented the person's age category (adult, child, infant). Each of these items had a member field and getter and setter methods. No one was really sure how these grew up, because they had evidently been added by different people at different times, but the result was a lot of unneccessary confusion over which item was set, which wasn't, and who was using which. Only very rarely were all three values in sync; usually one or two had been set and the others were empty. This was a nightmare for programmers because you never knew which ones had been set and which hadn't, which caused a lot of wasted time.

The solution seems obvious in retrospect, but wasn't at the time: store one field and have the getters and setters "normalize" to that field. For example, the category field didn't ever need to be set since it could be inferred from the age, and the age could be inferred from the birthday. This might have made the class itself more complex but it would have made the use of it much, much simpler.

Here's another example from an XML document:

<people>
 <num_of_people>2</num_of_people>
 <person>Bob</person>
 <person>Mary</person>
</people>

What would happen if the same fragment had a num_of_people whose value was 3? On the other hand, the num_of_people doesn't add any more information than is already contained in the document, because it's implicit from the number of person elements. The document would be far clearer and more robust if the num_of_people element were eliminated.

In general, look for opportunities to eliminate duplicate data. It will pay off over time in clearer code that's easier to use.

 
View topic | History: r25 < r24 < r23 < r22 | More topic actions...
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding The Caboteria? Send feedback